using FHT.Agency.CommonTypes;
using FHT.Agency.Web.Filters;
using FHT.ApiCommon;
using FHT.Core.UI.ViewModels;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;
using FHT.Management.Interfaces.InputModels;
using FHT.Management.Interfaces.DependentInterfaces.Services;
using FHT.DDD;
using System.Web.Http.Cors;
namespace FHT.Agency.Web.ApiControllers
{
///
/// 帖子类型广告
///
[Authorize]
[RoutePrefix("api/topictypeads")]
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class TopicTypeAdApiController : ApiController
{
private readonly IManagementTopicTypePromotionService _managementTopicTypePromotionService;
public TopicTypeAdApiController(IManagementTopicTypePromotionService managementTopicTypePromotionService)
{
_managementTopicTypePromotionService = managementTopicTypePromotionService;
}
[HttpGet]
[Route("{id:int:min(1)}")]
[ResponseType(typeof(TopicTypePromotionInputModel))]
[ApiClaimsAuthorize(FhtUserClaimType.TopicTypePromotionList)]
public async Task GetAsync(int id)
{
TopicTypePromotionInputModel model = await _managementTopicTypePromotionService.GetAsync(id);
return Ok(model);
}
[HttpGet]
[Route("_search")]
[ResponseType(typeof(QueryResult))]
[ApiClaimsAuthorize(FhtUserClaimType.TopicTypePromotionList)]
public async Task SearchAsync(string q = "", int currPage = 1,int limit=6)
{
QueryResult results = await _managementTopicTypePromotionService.SearchAsync(q, currPage, limit);
return Ok(results);
}
[HttpPost]
[Route("_create", Name = nameof(CreateTopicTypeAdAsync))]
[ResponseType(typeof(CreatedViewModel))]
[ValidateModel]
[ApiClaimsAuthorize(FhtUserClaimType.TopicTypePromotionList)]
public async Task CreateTopicTypeAdAsync(TopicTypePromotionInputModel model)
{
int TopicTypeAdId = await _managementTopicTypePromotionService.CreateAsync(model);
string url = Url.Link(nameof(CreateTopicTypeAdAsync), new { TopicTypeAdId });
return Created(url, new CreatedViewModel { Id = TopicTypeAdId, Location = url });
}
[HttpPost]
[Route("_update")]
[ResponseType(typeof(void))]
[ValidateModel]
[ApiClaimsAuthorize(FhtUserClaimType.TopicTypePromotionList)]
public async Task UpdateAsync(TopicTypePromotionInputModel model)
{
await _managementTopicTypePromotionService.UpdateAsync(model);
return Ok();
}
[HttpPost]
[Route("_delete")]
[ResponseType(typeof(void))]
[ApiClaimsAuthorize(FhtUserClaimType.TopicTypePromotionList)]
public async Task DeleteByIdsAsync(int[] ids)
{
await _managementTopicTypePromotionService.DeleteByIdsAsync(ids);
return Ok();
}
[HttpPost]
[Route("_enabled")]
[ResponseType(typeof(void))]
[ApiClaimsAuthorize(FhtUserClaimType.TopicTypePromotionList)]
public async Task EnabledAsync(int[] ids)
{
await _managementTopicTypePromotionService.ChangeActiveStatusAsync(true, ids);
return Ok();
}
[HttpPost]
[Route("_disabled")]
[ResponseType(typeof(void))]
[ApiClaimsAuthorize(FhtUserClaimType.TopicTypePromotionList)]
public async Task DisabledAsync(int[] ids)
{
await _managementTopicTypePromotionService.ChangeActiveStatusAsync(false, ids);
return Ok();
}
}
}