using FHT.Agency.Queries.ImplementedInterfaces; using FHT.Agency.Services.ImplementedInterfaces; using FHT.Agency.UI.InputModels.Search; using System.Web.Mvc; using FHT.Agency.CommonTypes; using FHT.Agency.UI.InputModels.Order; using Microsoft.AspNet.Identity; using FHT.Agency.Web.Filters; using System; using System.Collections.Generic; using FHT.Core.UI.ViewModels; using FHT.DDD; using System.Threading.Tasks; using FHT.MvcCommon; namespace FHT.Agency.Web.Controllers { public class AdvReviseController : Controller { private readonly IAdvReviseService _advReviseService; private readonly IAdvReviseQuery _advReviseQuery; private readonly IOrderQuery _orderQuery; private readonly IUserQuery _userQuery; private readonly Core.Queries.ImplementedInterfaces.IProductQuery _productQuery; public AdvReviseController(IAdvReviseService advReviseService, IAdvReviseQuery advReviseQuery , IOrderQuery orderQuery, IUserQuery userQuery, Core.Queries.ImplementedInterfaces.IProductQuery productQuery) { _advReviseService = advReviseService; _advReviseQuery = advReviseQuery; _orderQuery = orderQuery; _userQuery = userQuery; _productQuery = productQuery; } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.AdvRevise)] public async Task List(SearchAdvReviseInputModel filter) { ViewBag.AdvRevises = await _advReviseQuery.SearchAsync(filter.OrderId,filter.ClientName,filter.Offset(),filter.Limit); return View(filter); } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.AdvRevise)] public ActionResult Detail(long? orderId) { var model = new AdvReviseInputModel(); if (orderId.HasValue) { model = _advReviseService.GetAdvRevise(orderId.Value, true); } return View(model); } [HttpPost] [ClaimsAuthorize(FhtUserClaimType.AdvRevise)] [ValidateAjaxModel] public JsonResult CreateOrUpdate(AdvReviseInputModel model, int? isSubmit) { try { int authenticatedUserId = User.Identity.GetUserId(); model.Status = isSubmit == 1 ? Status.Temporary : Status.Pending; _advReviseService.CreateOrUpdateAdvRevise(authenticatedUserId, model); return Json(new { Success = true, Error = "" }); } #pragma warning disable FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT catch (InvalidOperationException ioe) #pragma warning restore FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT { return Json(new { Success = false, Error = ioe.Message }); } #pragma warning disable FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT catch (Exception ex) #pragma warning restore FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT { return Json(new { Success = false, Error = "广告信息保存失败!" }); } } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.AdvReviseAudit)] public ActionResult AuditList(SearchAdvReviseInputModel filter) { ViewBag.AdvRevises = _advReviseQuery.SearchAsync(filter.OrderId,filter.ClientName,filter.Offset(),filter.Limit); return View(filter); } [HttpGet] [ClaimsAuthorize(FhtUserClaimType.AdvReviseAudit)] public async Task< ActionResult> Audit(int id) { AdvReviseInputModel model = _advReviseService.GetAdvRevise(id, false, Status.Pending); if (model == null || model.Status != Status.Pending) { throw new InvalidOperationException("请勿非法操作!"); } ViewBag.Order =await _orderQuery.GetOrderAsync(model.OrderId); return View(model); } [HttpPost] [ValidateAntiForgeryToken] [ClaimsAuthorize(FhtUserClaimType.AdvReviseAudit)] public ActionResult Audit(long id, int status) { try { int authenticatedUserId = User.Identity.GetUserId(); _advReviseService.Audit(authenticatedUserId, id, (Status)status); return Json(new { Success = true, Error = "" }); } #pragma warning disable FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT catch (InvalidOperationException ioe) #pragma warning restore FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT { return Json(new { Success = false, Error = ioe.Message }); } #pragma warning disable FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT catch (Exception ex) #pragma warning restore FHTRoslynChecker_ExceptionCheck // Do not catch Exceptions which are not defined by FHT { return Json(new { Success = false, Error = "审核失败!" }); } } [HttpGet] [IsAjaxJsonResult] public async Task GetAdvReviseByOrderId(long orderId) { List advRevisew =await _advReviseQuery.GetTemporaryAdvRevisewByOrderIdAsync(orderId); return Json(advRevisew, JsonRequestBehavior.AllowGet); } /// /// 根据订单编号获取客户产品--autocomplate /// /// /// 产品编号 /// 订单编号 /// [HttpGet] [IsAjaxJsonResult] public async Task GetProductByOrderId(string q, int? productId, long orderId) { UI.ViewModels.Order.OrderViewModel order =await _orderQuery.GetOrderAsync(orderId); var products = new List(); if (order != null) { if (productId.HasValue) { products = _productQuery.GetAutoCompleteProductsByIds(new List { productId.Value }, null); return Json(products, JsonRequestBehavior.AllowGet); } else { products = _productQuery.SearchSelectListItem(q, order.CompanyId); return Json(products, JsonRequestBehavior.AllowGet); } } return Json(null); } } }