/// <summary> /// Prepare paged return request list model /// </summary> /// <param name="searchModel">Return request search model</param> /// <returns>Return request list model</returns> public virtual async Task <ReturnRequestListModel> PrepareReturnRequestListModelAsync(ReturnRequestSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter emails var startDateValue = !searchModel.StartDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); var returnRequestStatus = searchModel.ReturnRequestStatusId == -1 ? null : (ReturnRequestStatus?)searchModel.ReturnRequestStatusId; //get return requests var returnRequests = await _returnRequestService.SearchReturnRequestsAsync(customNumber : searchModel.CustomNumber, rs : returnRequestStatus, createdFromUtc : startDateValue, createdToUtc : endDateValue, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare list model var model = await new ReturnRequestListModel().PrepareToGridAsync(searchModel, returnRequests, () => { return(returnRequests.SelectAwait(async returnRequest => { //fill in model values from the entity var returnRequestModel = returnRequest.ToModel <ReturnRequestModel>(); var customer = await _customerService.GetCustomerByIdAsync(returnRequest.CustomerId); //convert dates to the user time returnRequestModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(returnRequest.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) returnRequestModel.CustomerInfo = (await _customerService.IsRegisteredAsync(customer)) ? customer.Email : await _localizationService.GetResourceAsync("Admin.Customers.Guest"); returnRequestModel.ReturnRequestStatusStr = await _localizationService.GetLocalizedEnumAsync(returnRequest.ReturnRequestStatus); var orderItem = await _orderService.GetOrderItemByIdAsync(returnRequest.OrderItemId); if (orderItem == null) { return returnRequestModel; } var order = await _orderService.GetOrderByIdAsync(orderItem.OrderId); var product = await _productService.GetProductByIdAsync(orderItem.ProductId); returnRequestModel.ProductId = orderItem.ProductId; returnRequestModel.ProductName = product.Name; returnRequestModel.OrderId = order.Id; returnRequestModel.AttributeInfo = orderItem.AttributeDescription; returnRequestModel.CustomOrderNumber = order.CustomOrderNumber; return returnRequestModel; })); }); return(model); }
/// <summary> /// Prepare paged return request list model /// </summary> /// <param name="searchModel">Return request search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the return request list model /// </returns> public virtual async Task <ReturnRequestListModel> PrepareReturnRequestListModelAsync(ReturnRequestSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter emails var startDateValue = !searchModel.StartDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); var returnRequestStatus = searchModel.ReturnRequestStatusId == -1 ? null : (ReturnRequestStatus?)searchModel.ReturnRequestStatusId; //get return requests var returnRequests = await _returnRequestService.SearchReturnRequestsAsync(customNumber : searchModel.CustomNumber, rs : returnRequestStatus, createdFromUtc : startDateValue, createdToUtc : endDateValue, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare list model var model = await new ReturnRequestListModel().PrepareToGridAsync(searchModel, returnRequests, () => { return(returnRequests.SelectAwait(async returnRequest => await PrepareReturnRequestModelAsync(null, returnRequest))); }); return(model); }
/// <summary> /// Prepare paged news comment list model /// </summary> /// <param name="searchModel">News comment search model</param> /// <param name="newsItemId">News item Id; pass null to prepare comment models for all news items</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the news comment list model /// </returns> public virtual async Task <NewsCommentListModel> PrepareNewsCommentListModelAsync(NewsCommentSearchModel searchModel, int?newsItemId) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter comments var createdOnFromValue = searchModel.CreatedOnFrom == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var createdOnToValue = searchModel.CreatedOnTo == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); var isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false; //get comments var comments = (await _newsService.GetAllCommentsAsync(newsItemId: newsItemId, approved: isApprovedOnly, fromUtc: createdOnFromValue, toUtc: createdOnToValue, commentText: searchModel.SearchText)).ToPagedList(searchModel); //prepare store names (to avoid loading for each comment) var storeNames = (await _storeService.GetAllStoresAsync()) .ToDictionary(store => store.Id, store => store.Name); //prepare list model var model = await new NewsCommentListModel().PrepareToGridAsync(searchModel, comments, () => { return(comments.SelectAwait(async newsComment => { //fill in model values from the entity var commentModel = newsComment.ToModel <NewsCommentModel>(); //convert dates to the user time commentModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(newsComment.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) commentModel.NewsItemTitle = (await _newsService.GetNewsByIdAsync(newsComment.NewsItemId))?.Title; if ((await _customerService.GetCustomerByIdAsync(newsComment.CustomerId)) is Customer customer) { commentModel.CustomerInfo = (await _customerService.IsRegisteredAsync(customer)) ? customer.Email : await _localizationService.GetResourceAsync("Admin.Customers.Guest"); } commentModel.CommentText = HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false, false, false); commentModel.StoreName = storeNames.ContainsKey(newsComment.StoreId) ? storeNames[newsComment.StoreId] : "Deleted"; return commentModel; })); });
public async Task <IActionResult> LogList(TaxTransactionLogSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTaxSettings)) { return(await AccessDeniedDataTablesJson()); } //prepare filter parameters var createdFromValue = searchModel.CreatedFrom.HasValue ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedFrom.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()) : null; var createdToValue = searchModel.CreatedTo.HasValue ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedTo.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1) : null; //get tax transaction log var taxtransactionLog = await _taxTransactionLogService.GetTaxTransactionLogAsync(createdFromUtc : createdFromValue, createdToUtc : createdToValue, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare grid model var model = await new TaxTransactionLogListModel().PrepareToGridAsync(searchModel, taxtransactionLog, () => { return(taxtransactionLog.SelectAwait(async logItem => new TaxTransactionLogModel { Id = logItem.Id, StatusCode = logItem.StatusCode, Url = logItem.Url, CustomerId = logItem.CustomerId, CreatedDate = await _dateTimeHelper.ConvertToUserTimeAsync(logItem.CreatedDateUtc, DateTimeKind.Utc) })); }); return(Json(model)); }
/// <summary> /// Prepare paged activity log list model /// </summary> /// <param name="searchModel">Activity log search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the activity log list model /// </returns> public virtual async Task <ActivityLogListModel> PrepareActivityLogListModelAsync(ActivityLogSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter log var startDateValue = searchModel.CreatedOnFrom == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = searchModel.CreatedOnTo == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); //get log var activityLog = await _customerActivityService.GetAllActivitiesAsync(createdOnFrom : startDateValue, createdOnTo : endDateValue, activityLogTypeId : searchModel.ActivityLogTypeId, ipAddress : searchModel.IpAddress, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); if (activityLog is null) { return(new ActivityLogListModel()); } //prepare list model var customerIds = activityLog.GroupBy(logItem => logItem.CustomerId).Select(logItem => logItem.Key); var activityLogCustomers = await _customerService.GetCustomersByIdsAsync(customerIds.ToArray()); var model = await new ActivityLogListModel().PrepareToGridAsync(searchModel, activityLog, () => { return(activityLog.SelectAwait(async logItem => { //fill in model values from the entity var logItemModel = logItem.ToModel <ActivityLogModel>(); logItemModel.ActivityLogTypeName = (await _customerActivityService.GetActivityTypeByIdAsync(logItem.ActivityLogTypeId))?.Name; logItemModel.CustomerEmail = activityLogCustomers?.FirstOrDefault(x => x.Id == logItem.CustomerId)?.Email; //convert dates to the user time logItemModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(logItem.CreatedOnUtc, DateTimeKind.Utc); return logItemModel; })); }); return(model); }
/// <summary> /// Prepare paged product review list model /// </summary> /// <param name="searchModel">Product review search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the product review list model /// </returns> public virtual async Task <ProductReviewListModel> PrepareProductReviewListModelAsync(ProductReviewSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter reviews var createdOnFromValue = !searchModel.CreatedOnFrom.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var createdToFromValue = !searchModel.CreatedOnTo.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); var isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false; var vendor = await _workContext.GetCurrentVendorAsync(); var vendorId = vendor?.Id ?? 0; //get product reviews var productReviews = await _productService.GetAllProductReviewsAsync(showHidden : true, customerId : 0, approved : isApprovedOnly, fromUtc : createdOnFromValue, toUtc : createdToFromValue, message : searchModel.SearchText, storeId : searchModel.SearchStoreId, productId : searchModel.SearchProductId, vendorId : vendorId, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare list model var model = await new ProductReviewListModel().PrepareToGridAsync(searchModel, productReviews, () => { return(productReviews.SelectAwait(async productReview => { //fill in model values from the entity var productReviewModel = productReview.ToModel <ProductReviewModel>(); //convert dates to the user time productReviewModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(productReview.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) productReviewModel.StoreName = (await _storeService.GetStoreByIdAsync(productReview.StoreId))?.Name; productReviewModel.ProductName = (await _productService.GetProductByIdAsync(productReview.ProductId))?.Name; productReviewModel.CustomerInfo = (await _customerService.GetCustomerByIdAsync(productReview.CustomerId)) is Customer customer && (await _customerService.IsRegisteredAsync(customer)) ? customer.Email : await _localizationService.GetResourceAsync("Admin.Customers.Guest"); productReviewModel.ReviewText = _htmlFormatter.FormatText(productReview.ReviewText, false, true, false, false, false, false); productReviewModel.ReplyText = _htmlFormatter.FormatText(productReview.ReplyText, false, true, false, false, false, false); return productReviewModel; })); });
/// <summary> /// Prepare paged newsletter subscription list model /// </summary> /// <param name="searchModel">Newsletter subscription search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the newsletter subscription list model /// </returns> public virtual async Task <NewsletterSubscriptionListModel> PrepareNewsletterSubscriptionListModelAsync(NewsletterSubscriptionSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter newsletter subscriptions var isActivatedOnly = searchModel.ActiveId == 0 ? null : searchModel.ActiveId == 1 ? true : (bool?)false; var startDateValue = !searchModel.StartDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); //get newsletter subscriptions var newsletterSubscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptionsAsync(email : searchModel.SearchEmail, customerRoleId : searchModel.CustomerRoleId, storeId : searchModel.StoreId, isActive : isActivatedOnly, createdFromUtc : startDateValue, createdToUtc : endDateValue, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare list model var model = await new NewsletterSubscriptionListModel().PrepareToGridAsync(searchModel, newsletterSubscriptions, () => { return(newsletterSubscriptions.SelectAwait(async subscription => { //fill in model values from the entity var subscriptionModel = subscription.ToModel <NewsletterSubscriptionModel>(); //convert dates to the user time subscriptionModel.CreatedOn = (await _dateTimeHelper.ConvertToUserTimeAsync(subscription.CreatedOnUtc, DateTimeKind.Utc)).ToString(); //fill in additional values (not existing in the entity) subscriptionModel.StoreName = (await _storeService.GetStoreByIdAsync(subscription.StoreId))?.Name ?? "Deleted"; return subscriptionModel; })); }); return(model); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> MaintenanceDeleteGuests(MaintenanceModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageMaintenance)) { return(AccessDeniedView()); } var startDateValue = model.DeleteGuests.StartDate == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DeleteGuests.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = model.DeleteGuests.EndDate == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DeleteGuests.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); model.DeleteGuests.NumberOfDeletedCustomers = await _customerService.DeleteGuestCustomersAsync(startDateValue, endDateValue, model.DeleteGuests.OnlyWithoutShoppingCart); return(View(model)); }
protected virtual async Task <IPagedList <SalesSummaryReportLine> > GetSalesSummaryReportAsync(SalesSummarySearchModel searchModel) { //get parameters to filter orders var orderStatus = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null; var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null; var startDateValue = !searchModel.StartDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); //get sales summary var salesSummary = await _orderReportService.SalesSummaryReportAsync( createdFromUtc : startDateValue, createdToUtc : endDateValue, os : orderStatus, ps : paymentStatus, billingCountryId : searchModel.BillingCountryId, groupBy : (GroupByOptions)searchModel.SearchGroupId, categoryId : searchModel.CategoryId, productId : searchModel.ProductId, manufacturerId : searchModel.ManufacturerId, storeId : searchModel.StoreId, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); return(salesSummary); }
/// <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 async Task <AffiliatedOrderListModel> PrepareAffiliatedOrderListModelAsync(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, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.EndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).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 = await _orderService.SearchOrdersAsync(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 = await new AffiliatedOrderListModel().PrepareToGridAsync(searchModel, orders, () => { //fill in model values from the entity return(orders.SelectAwait(async order => { var affiliatedOrderModel = order.ToModel <AffiliatedOrderModel>(); //fill in additional values (not existing in the entity) affiliatedOrderModel.OrderStatus = await _localizationService.GetLocalizedEnumAsync(order.OrderStatus); affiliatedOrderModel.PaymentStatus = await _localizationService.GetLocalizedEnumAsync(order.PaymentStatus); affiliatedOrderModel.ShippingStatus = await _localizationService.GetLocalizedEnumAsync(order.ShippingStatus); affiliatedOrderModel.OrderTotal = await _priceFormatter.FormatPriceAsync(order.OrderTotal, true, false); affiliatedOrderModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(order.CreatedOnUtc, DateTimeKind.Utc); return affiliatedOrderModel; })); }); return(model); }
/// <summary> /// Prepare paged queued email list model /// </summary> /// <param name="searchModel">Queued email search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the queued email list model /// </returns> public virtual async Task <QueuedEmailListModel> PrepareQueuedEmailListModelAsync(QueuedEmailSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter emails var startDateValue = !searchModel.SearchStartDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.SearchStartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = !searchModel.SearchEndDate.HasValue ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.SearchEndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); //get queued emails var queuedEmails = await _queuedEmailService.SearchEmailsAsync(fromEmail : searchModel.SearchFromEmail, toEmail : searchModel.SearchToEmail, createdFromUtc : startDateValue, createdToUtc : endDateValue, loadNotSentItemsOnly : searchModel.SearchLoadNotSent, loadOnlyItemsToBeSent : false, maxSendTries : searchModel.SearchMaxSentTries, loadNewest : true, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare list model var model = await new QueuedEmailListModel().PrepareToGridAsync(searchModel, queuedEmails, () => { return(queuedEmails.SelectAwait(async queuedEmail => { //fill in model values from the entity var queuedEmailModel = queuedEmail.ToModel <QueuedEmailModel>(); //little performance optimization: ensure that "Body" is not returned queuedEmailModel.Body = string.Empty; //convert dates to the user time queuedEmailModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(queuedEmail.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) var emailAccount = await _emailAccountService.GetEmailAccountByIdAsync(queuedEmail.EmailAccountId); queuedEmailModel.EmailAccountName = GetEmailAccountName(emailAccount); queuedEmailModel.PriorityName = await _localizationService.GetLocalizedEnumAsync(queuedEmail.Priority); if (queuedEmail.DontSendBeforeDateUtc.HasValue) { queuedEmailModel.DontSendBeforeDate = await _dateTimeHelper .ConvertToUserTimeAsync(queuedEmail.DontSendBeforeDateUtc.Value, DateTimeKind.Utc); } if (queuedEmail.SentOnUtc.HasValue) { queuedEmailModel.SentOn = await _dateTimeHelper.ConvertToUserTimeAsync(queuedEmail.SentOnUtc.Value, DateTimeKind.Utc); } return queuedEmailModel; })); }); return(model); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> ExportCsv(NewsletterSubscriptionSearchModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageNewsletterSubscribers)) { return(AccessDeniedView()); } bool?isActive = null; if (model.ActiveId == 1) { isActive = true; } else if (model.ActiveId == 2) { isActive = false; } var startDateValue = model.StartDate == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()); var endDateValue = model.EndDate == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1); var subscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptionsAsync(model.SearchEmail, startDateValue, endDateValue, model.StoreId, isActive, model.CustomerRoleId); var result = await _exportManager.ExportNewsletterSubscribersToTxtAsync(subscriptions); var fileName = $"newsletter_emails_{DateTime.Now:yyyy-MM-dd-HH-mm-ss}_{CommonHelper.GenerateRandomDigitCode(4)}.csv"; return(File(Encoding.UTF8.GetBytes(result), MimeTypes.TextCsv, fileName)); }
/// <summary> /// Prepare paged discount list model /// </summary> /// <param name="searchModel">Discount search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the discount list model /// </returns> public virtual async Task <DiscountListModel> PrepareDiscountListModelAsync(DiscountSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter discounts var discountType = searchModel.SearchDiscountTypeId > 0 ? (DiscountType?)searchModel.SearchDiscountTypeId : null; var startDateUtc = searchModel.SearchStartDate.HasValue ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.SearchStartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()) : null; var endDateUtc = searchModel.SearchEndDate.HasValue ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.SearchEndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1) : null; //get discounts var discounts = (await _discountService.GetAllDiscountsAsync(showHidden: true, discountType: discountType, couponCode: searchModel.SearchDiscountCouponCode, discountName: searchModel.SearchDiscountName, startDateUtc: startDateUtc, endDateUtc: endDateUtc)).ToPagedList(searchModel); //prepare list model var model = await new DiscountListModel().PrepareToGridAsync(searchModel, discounts, () => { return(discounts.SelectAwait(async discount => { //fill in model values from the entity var discountModel = discount.ToModel <DiscountModel>(); //fill in additional values (not existing in the entity) discountModel.DiscountTypeName = await _localizationService.GetLocalizedEnumAsync(discount.DiscountType); discountModel.PrimaryStoreCurrencyCode = (await _currencyService .GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId))?.CurrencyCode; discountModel.TimesUsed = (await _discountService.GetAllDiscountUsageHistoryAsync(discount.Id, pageSize: 1)).TotalCount; return discountModel; })); }); return(model); }
/// <summary> /// Prepare paged log list model /// </summary> /// <param name="searchModel">Log search model</param> /// <returns>Log list model</returns> public virtual async Task <LogListModel> PrepareLogListModelAsync(LogSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter log var createdOnFromValue = searchModel.CreatedOnFrom.HasValue ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()) : null; var createdToFromValue = searchModel.CreatedOnTo.HasValue ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1) : null; var logLevel = searchModel.LogLevelId > 0 ? (LogLevel?)searchModel.LogLevelId : null; //get log var logItems = await _logger.GetAllLogsAsync(message : searchModel.Message, fromUtc : createdOnFromValue, toUtc : createdToFromValue, logLevel : logLevel, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare list model var model = await new LogListModel().PrepareToGridAsync(searchModel, logItems, () => { //fill in model values from the entity return(logItems.SelectAwait(async logItem => { //fill in model values from the entity var logModel = logItem.ToModel <LogModel>(); //convert dates to the user time logModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(logItem.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) logModel.LogLevel = await _localizationService.GetLocalizedEnumAsync(logItem.LogLevel); logModel.ShortMessage = HtmlHelper.FormatText(logItem.ShortMessage, false, true, false, false, false, false); logModel.FullMessage = string.Empty; logModel.CustomerEmail = (await _customerService.GetCustomerByIdAsync(logItem.CustomerId ?? 0))?.Email ?? string.Empty; return logModel; })); }); return(model); }