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