/// <summary> /// Prepare paged affiliated order list model /// </summary> /// <param name="searchModel">Affiliated order search model</param> /// <param name="affiliate">Affiliate</param> /// <returns>Affiliated order list model</returns> public virtual AffiliatedOrderListModel PrepareAffiliatedOrderListModel(AffiliatedOrderSearchModel searchModel, Affiliate affiliate) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (affiliate == null) { throw new ArgumentNullException(nameof(affiliate)); } //get parameters to filter orders var startDateValue = !searchModel.StartDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, _dateTimeHelper.CurrentTimeZone); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1); var orderStatusIds = searchModel.OrderStatusId > 0 ? new List <int> { searchModel.OrderStatusId } : null; var paymentStatusIds = searchModel.PaymentStatusId > 0 ? new List <int> { searchModel.PaymentStatusId } : null; var shippingStatusIds = searchModel.ShippingStatusId > 0 ? new List <int> { searchModel.ShippingStatusId } : null; //get orders var orders = _orderService.SearchOrders(createdFromUtc: startDateValue, createdToUtc: endDateValue, osIds: orderStatusIds, psIds: paymentStatusIds, ssIds: shippingStatusIds, affiliateId: affiliate.Id, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare list model var model = new AffiliatedOrderListModel { //fill in model values from the entity Data = orders.Select(order => { var affiliatedOrderModel = order.ToModel <AffiliatedOrderModel>(); //fill in additional values (not existing in the entity) affiliatedOrderModel.OrderStatus = _localizationService.GetLocalizedEnum(order.OrderStatus); affiliatedOrderModel.PaymentStatus = _localizationService.GetLocalizedEnum(order.PaymentStatus); affiliatedOrderModel.ShippingStatus = _localizationService.GetLocalizedEnum(order.ShippingStatus); affiliatedOrderModel.OrderTotal = _priceFormatter.FormatPrice(order.OrderTotal, true, false); affiliatedOrderModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); return(affiliatedOrderModel); }), Total = orders.TotalCount }; return(model); }
public virtual IActionResult AffiliatedOrderListGrid(AffiliatedOrderSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedKendoGridJson()); } //try to get an affiliate with the specified id var affiliate = _affiliateService.GetAffiliateById(searchModel.AffliateId) ?? throw new ArgumentException("No affiliate found with the specified id"); //prepare model var model = _affiliateModelFactory.PrepareAffiliatedOrderListModel(searchModel, affiliate); return(Json(model)); }
public virtual async Task <IActionResult> AffiliatedOrderListGrid(AffiliatedOrderSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAffiliates)) { return(await AccessDeniedDataTablesJson()); } //try to get an affiliate with the specified id var affiliate = await _affiliateService.GetAffiliateByIdAsync(searchModel.AffliateId) ?? throw new ArgumentException("No affiliate found with the specified id"); //prepare model var model = await _affiliateModelFactory.PrepareAffiliatedOrderListModelAsync(searchModel, affiliate); return(Json(model)); }
/// <summary> /// Prepare affiliated order search model /// </summary> /// <param name="searchModel">Affiliated order search model</param> /// <param name="affiliate">Affiliate</param> /// <returns>Affiliated order search model</returns> protected virtual AffiliatedOrderSearchModel PrepareAffiliatedOrderSearchModel(AffiliatedOrderSearchModel searchModel, Affiliate affiliate) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (affiliate == null) { throw new ArgumentNullException(nameof(affiliate)); } searchModel.AffliateId = affiliate.Id; //prepare available order, payment and shipping statuses _baseAdminModelFactory.PrepareOrderStatuses(searchModel.AvailableOrderStatuses); _baseAdminModelFactory.PreparePaymentStatuses(searchModel.AvailablePaymentStatuses); _baseAdminModelFactory.PrepareShippingStatuses(searchModel.AvailableShippingStatuses); //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }