using FHT.Agency.CommonTypes; using FHT.Agency.UI.InputModels; using FHT.Agency.Web.Filters; using FHT.Core.Agency.Interfaces; using FHT.Core.Queries.ImplementedInterfaces; using FHT.Core.UI.ViewModels; using FHT.Utilities; using System.Net; using System.Threading.Tasks; using System.Web.Mvc; namespace FHT.Agency.Web.Controllers { public class TopicTypeController : Controller { private readonly ITopicTypeQuery _topicTypeQuery; private readonly ITopicTypeService _topicTypeService; public TopicTypeController(ITopicTypeQuery topicTypeQuery, ITopicTypeService topicTypeService) { _topicTypeQuery = topicTypeQuery; _topicTypeService = topicTypeService; } [ClaimsAuthorize(FhtUserClaimType.TopicTypeManagement)] [HttpGet] public async Task Index() { System.Collections.Generic.List topicTypes =await _topicTypeQuery.GetAllTopicTypesAsync(); return View(topicTypes); } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.TopicTypeManagement)] public ActionResult CreateTopicType() { return View(new CreateTopicTypeInputModel()); } [HttpPost] [ClaimsAuthorize(FhtUserClaimType.TopicTypeManagement)] public async Task CreateTopicType(CreateTopicTypeInputModel model) { await _topicTypeService.CreateOrUpdateAsync(null, model.Title, model.EnglishTitle, model.Pinyin, model.Description, ImageConverter.ToRelativeUrl(model.PublishIconUrl), ImageConverter.ToRelativeUrl(model.WebIconUrl), ImageConverter.ToRelativeUrl(model.BusinessOpportunityIconUrl), model.Order, true); return RedirectToAction(nameof(Index)); } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.TopicTypeManagement)] public async Task< ActionResult> UpdateTopicType(int topicTypeId) { Core.UI.ViewModels.TopicPost.TopicTypeViewModel topicPost =await _topicTypeQuery.GetTopicTypeFromDbAsync(topicTypeId); return View(new CreateTopicTypeInputModel() { TopicTypeId = topicTypeId, Description = topicPost.Description, EnglishTitle = topicPost.EnglishTitle, Order = topicPost.Order, Pinyin = topicPost.PinYin, PublishIconUrl =new ImageViewModel( topicPost.PublishIcon).AbsoluteUrl, BusinessOpportunityIconUrl = new ImageViewModel(topicPost.BusinessOpportunityIcon).AbsoluteUrl, WebIconUrl = new ImageViewModel(topicPost.WebIcon).AbsoluteUrl, Title = topicPost.Name }); } [HttpPost] [ClaimsAuthorize(FhtUserClaimType.TopicTypeManagement)] public async Task UpdateTopicType(CreateTopicTypeInputModel model) { await _topicTypeService.CreateOrUpdateAsync(model.TopicTypeId, model.Title, model.EnglishTitle, model.Pinyin, model.Description, ImageConverter.ToRelativeUrl(model.PublishIconUrl), ImageConverter.ToRelativeUrl(model.WebIconUrl), ImageConverter.ToRelativeUrl(model.BusinessOpportunityIconUrl), model.Order,true); return RedirectToAction(nameof(Index)); } public async Task UpdateStatus(bool isActive,int topicTypeId) { if (isActive) { await _topicTypeService.ChangeActiveStatusAsync(topicTypeId,true); } else { await _topicTypeService.ChangeActiveStatusAsync(topicTypeId,false); } return new HttpStatusCodeResult(HttpStatusCode.NoContent); } } }