/// <summary>
        /// Prepare paged queued email list model
        /// </summary>
        /// <param name="searchModel">Queued email search model</param>
        /// <returns>Queued email list model</returns>
        public virtual QueuedEmailListModel PrepareQueuedEmailListModel(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, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.SearchEndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.SearchEndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //get queued emails
            var queuedEmails = _queuedEmailService.SearchEmails(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 = new QueuedEmailListModel
            {
                Data = queuedEmails.Select(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 = _dateTimeHelper.ConvertToUserTime(queuedEmail.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    //chai
                    //queuedEmailModel.PriorityName = queuedEmail.Priority.GetLocalizedEnum(_localizationService, _workContext);
                    queuedEmailModel.PriorityName = CommonHelper.ConvertEnum(queuedEmail.Priority.ToString());
                    if (queuedEmail.DontSendBeforeDateUtc.HasValue)
                    {
                        queuedEmailModel.DontSendBeforeDate = _dateTimeHelper
                                                              .ConvertToUserTime(queuedEmail.DontSendBeforeDateUtc.Value, DateTimeKind.Utc);
                    }

                    if (queuedEmail.SentOnUtc.HasValue)
                    {
                        queuedEmailModel.SentOn = _dateTimeHelper.ConvertToUserTime(queuedEmail.SentOnUtc.Value, DateTimeKind.Utc);
                    }

                    return(queuedEmailModel);
                }),
                Total = queuedEmails.TotalCount
            };

            return(model);
        }
예제 #2
0
        public virtual ActionResult List(DataSourceRequest command, IdeaListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageIdea))
            {
                return(AccessDeniedKendoGridJson());
            }

            DateTime?createOnFromValue = (model.CreatedOnFrom == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);
            DateTime?createOnToValue = (model.CreatedOnTo == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone);

            var ideas = _ideaService.GetAllIdeas(null, createOnFromValue, createOnToValue, command.Page - 1,
                                                 command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data = ideas.Select(idea => new IdeaModel
                {
                    Id            = idea.Id,
                    Guid          = idea.Guid,
                    Private       = idea.Private,
                    Deleted       = idea.Deleted,
                    Body          = idea.Body,
                    CustomerEmail = idea.Customer != null ? idea.Customer.Email : null,
                    CreatedOn     = _dateTimeHelper.ConvertToUserTime(idea.CreatedOnUtc, DateTimeKind.Utc),
                    UpdatedOn     = idea.UpdatedOnUtc.HasValue
                        ? (DateTime?)_dateTimeHelper.ConvertToUserTime(idea.UpdatedOnUtc.Value, DateTimeKind.Utc)
                        : null
                }),
                Total = ideas.TotalCount
            };

            return(Json(gridModel));
        }
예제 #3
0
        /// <summary>
        /// Prepare paged queued email list model
        /// </summary>
        /// <param name="searchModel">Queued email search model</param>
        /// <returns>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);
        }
예제 #4
0
        public ActionResult List(DataSourceRequest command, ProductReviewListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductReviews))
            {
                return(AccessDeniedView());
            }

            DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var productReviews = _productService.GetAllProductReviews(0, null,
                                                                      createdOnFromValue, createdToFromValue, model.SearchText, model.SearchStoreId, model.SearchProductId, command.Page - 1, command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data = productReviews.Select(x =>
                {
                    var m = new ProductReviewModel();
                    PrepareProductReviewModel(m, x, false, true);
                    return(m);
                }),
                Total = productReviews.TotalCount
            };

            return(Json(gridModel));
        }
        public virtual (IEnumerable <ContactFormModel> contactFormModel, int totalCount) PrepareContactFormListModel(ContactFormListModel model, int pageIndex, int pageSize)
        {
            DateTime?startDateValue = (model.SearchStartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.SearchStartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.SearchEndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.SearchEndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            string vendorId = "";

            if (_workContext.CurrentVendor != null)
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            var contactform = _contactUsService.GetAllContactUs(
                fromUtc: startDateValue,
                toUtc: endDateValue,
                email: model.SearchEmail,
                storeId: model.StoreId,
                vendorId: vendorId,
                pageIndex: pageIndex - 1,
                pageSize: pageSize);

            return(contactform.Select(x => {
                var store = _storeService.GetStoreById(x.StoreId);
                var m = x.ToModel();
                m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                m.Enquiry = "";
                m.Email = m.FullName + " - " + m.Email;
                m.Store = store != null ? store.Name : "-empty-";
                return m;
            }), contactform.TotalCount);
        }
예제 #6
0
        public virtual IActionResult List(DiscountListModel model, DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedKendoGridJson());
            }

            var discountType = model.SearchDiscountTypeId > 0 ? (DiscountType?)model.SearchDiscountTypeId : null;
            var startDateUtc = model.SearchStartDate.HasValue ?
                               (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.SearchStartDate.Value, _dateTimeHelper.CurrentTimeZone) : null;
            var endDateUtc = model.SearchEndDate.HasValue ?
                             (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.SearchEndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1) : null;

            var discounts = _discountService.GetAllDiscounts(discountType, model.SearchDiscountCouponCode,
                                                             model.SearchDiscountName, true, startDateUtc, endDateUtc);

            var gridModel = new DataSourceResult
            {
                Data = discounts.PagedForCommand(command).Select(discount =>
                {
                    var discountModel = discount.ToModel();

                    discountModel.DiscountTypeName         = discount.DiscountType.GetLocalizedEnum(_localizationService, _workContext);
                    discountModel.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)?.CurrencyCode;
                    discountModel.TimesUsed = _discountService.GetAllDiscountUsageHistory(discount.Id, pageSize: 1).TotalCount;

                    return(discountModel);
                }),
                Total = discounts.Count
            };

            return(Json(gridModel));
        }
예제 #7
0
        public virtual async Task <(IEnumerable <BestCustomerReportLineModel> bestCustomerReportLineModels, int totalCount)> PrepareBestCustomerReportLineModel(BestCustomersReportModel model, int orderBy, int pageIndex, int pageSize)
        {
            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            OrderStatus?   orderStatus    = model.OrderStatusId > 0 ? (OrderStatus?)(model.OrderStatusId) : null;
            PaymentStatus? paymentStatus  = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;
            ShippingStatus?shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)(model.ShippingStatusId) : null;

            var items = _customerReportService.GetBestCustomersReport(model.StoreId, startDateValue, endDateValue,
                                                                      orderStatus, paymentStatus, shippingStatus, 2, pageIndex - 1, pageSize);

            var report = new List <BestCustomerReportLineModel>();

            foreach (var x in items)
            {
                var m = new BestCustomerReportLineModel {
                    CustomerId = x.CustomerId,
                    OrderTotal = _priceFormatter.FormatPrice(x.OrderTotal, true, false),
                    OrderCount = x.OrderCount,
                };
                var customer = await _customerService.GetCustomerById(x.CustomerId);

                if (customer != null)
                {
                    m.CustomerName = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
                }
                report.Add(m);
            }
            return(report, items.TotalCount);
        }
예제 #8
0
        public ActionResult Create(AdsBannerModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets))
            {
                return(AccessDeniedView());
            }
            if (ModelState.IsValid)
            {
                var adsbanner = model.ToEntity();
                if (model.FromDate != null)
                {
                    adsbanner.FromDateUtc = _dateTimeHelper.ConvertToUtcTime(model.FromDate.Value);
                }
                if (model.ToDate != null)
                {
                    adsbanner.ToDateUtc = _dateTimeHelper.ConvertToUtcTime(model.ToDate.Value);
                }

                _adsBannerService.InsertAdsBanner(adsbanner);

                UpdatePictureSeoNames(model);

                SuccessNotification(_localizationService.GetResource("Plugins.Widgets.AdsBanner.Added"));
                return(continueEditing
                    ? RedirectToAction("Edit", new { id = adsbanner.Id })
                    : RedirectToAction("ConfigureWidget", "Widget",
                                       new { area = "Admin", systemName = "Widgets.AdsBanner" }));
            }


            PrepareAdsBannerModel(model);
            return(View("~/Plugins/Widgets.AdsBanner/Views/WidgetsAdsBanner/Create.cshtml", model));
        }
        public virtual async Task <(IEnumerable <ActivityLogModel> activityLogs, int totalCount)> PrepareActivityLogModel(ActivityLogSearchModel model, int pageIndex, int pageSize)
        {
            DateTime?startDateValue = (model.CreatedOnFrom == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var activityLog = await _customerActivityService.GetAllActivities(startDateValue, endDateValue, null, model.ActivityLogTypeId, model.IpAddress, pageIndex - 1, pageSize);

            var activityLogModel = new List <ActivityLogModel>();

            foreach (var item in activityLog)
            {
                var customer = await _customerService.GetCustomerById(item.CustomerId);

                var cas = await _customerActivityService.GetActivityTypeById(item.ActivityLogTypeId);

                var m = item.ToModel();
                m.CreatedOn           = _dateTimeHelper.ConvertToUserTime(item.CreatedOnUtc, DateTimeKind.Utc);
                m.ActivityLogTypeName = cas?.Name;
                m.CustomerEmail       = customer != null ? customer.Email : "NULL";
                activityLogModel.Add(m);
            }
            return(activityLogModel, activityLog.TotalCount);
        }
        public virtual ActionResult List(DataSourceRequest command, ReturnRequestListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageReturnRequests))
            {
                return(AccessDeniedKendoGridJson());
            }

            var rrs = model.ReturnRequestStatusId == -1 ? null : (ReturnRequestStatus?)model.ReturnRequestStatusId;

            var startDateValue = model.StartDate == null ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            var endDateValue = model.EndDate == null ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var returnRequests      = _returnRequestService.SearchReturnRequests(0, 0, 0, model.CustomNumber, rrs, startDateValue, endDateValue, command.Page - 1, command.PageSize);
            var returnRequestModels = new List <ReturnRequestModel>();

            foreach (var rr in returnRequests)
            {
                var m = new ReturnRequestModel();
                PrepareReturnRequestModel(m, rr, false);
                returnRequestModels.Add(m);
            }
            var gridModel = new DataSourceResult
            {
                Data  = returnRequestModels,
                Total = returnRequests.TotalCount,
            };

            return(Json(gridModel));
        }
예제 #11
0
        public JsonResult ListLogs(DataTablesParam dataTableParam, ActivityLogSearchModel model)
        {
            DateTime?startDateValue = (model.CreatedOnFrom == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var activityLog = _userActivityService.GetAllActivities(startDateValue, endDateValue, null, model.ActivityLogTypeId, dataTableParam.iDisplayStart / dataTableParam.iDisplayLength, dataTableParam.iDisplayLength);
            var result      = new DataTablesData
            {
                iTotalRecords        = activityLog.TotalCount,
                sEcho                = dataTableParam.sEcho,
                iTotalDisplayRecords = activityLog.TotalCount,
                aaData               = activityLog.Select(x =>
                {
                    var m       = x.ToModel();
                    m.UserEmail = (x.User != null) ? x.User.UserName : "";
                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }).Cast <object>().ToArray(),
            };

            return(new JsonResult
            {
                Data = result
            });
        }
예제 #12
0
        public virtual async Task <IActionResult> Create(CampaignModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity <Campaign>();

                campaign.CreatedOnUtc          = DateTime.UtcNow;
                campaign.DontSendBeforeDateUtc = model.DontSendBeforeDate.HasValue ?
                                                 (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value) : null;

                await _campaignService.InsertCampaignAsync(campaign);

                //activity log
                await _customerActivityService.InsertActivityAsync("AddNewCampaign",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.AddNewCampaign"), campaign.Id), campaign);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Promotions.Campaigns.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = await _campaignModelFactory.PrepareCampaignModelAsync(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(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));
        }
예제 #14
0
        public virtual async Task <(IEnumerable <Shipment> shipments, int totalCount)> PrepareShipments(ShipmentListModel model, int pageIndex, int pageSize)
        {
            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //a vendor should have access only to his products
            string vendorId = "";

            if (_workContext.CurrentVendor != null)
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            //load shipments
            var shipments = await _shipmentService.GetAllShipments(vendorId: vendorId,
                                                                   warehouseId: model.WarehouseId,
                                                                   shippingCountryId : model.CountryId,
                                                                   shippingStateId : model.StateProvinceId,
                                                                   shippingCity : model.City,
                                                                   trackingNumber : model.TrackingNumber,
                                                                   loadNotShipped : model.LoadNotShipped,
                                                                   createdFromUtc : startDateValue,
                                                                   createdToUtc : endDateValue,
                                                                   pageIndex : pageIndex - 1,
                                                                   pageSize : pageSize);

            return(shipments.ToList(), shipments.TotalCount);
        }
예제 #15
0
        public virtual IActionResult LogList(TaxTransactionLogSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings))
            {
                return(AccessDeniedKendoGridJson());
            }

            //prepare filter parameters
            var createdFromValue = searchModel.CreatedFrom.HasValue
                ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedFrom.Value, _dateTimeHelper.CurrentTimeZone) : null;
            var createdToValue = searchModel.CreatedTo.HasValue
                ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1) : null;

            //get tax transaction log
            var taxtransactionLog = _taxTransactionLogService.GetTaxTransactionLog(createdFromUtc: createdFromValue,
                                                                                   createdToUtc: createdToValue, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new TaxTransactionLogListModel
            {
                //fill in model values from the entity
                Data = taxtransactionLog.Select(logItem => new TaxTransactionLogModel
                {
                    Id          = logItem.Id,
                    StatusCode  = logItem.StatusCode,
                    Url         = logItem.Url,
                    CustomerId  = logItem.CustomerId,
                    CreatedDate = _dateTimeHelper.ConvertToUserTime(logItem.CreatedDateUtc, DateTimeKind.Utc)
                }),
                Total = taxtransactionLog.TotalCount
            };

            return(Json(model));
        }
예제 #16
0
        public virtual 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));
        }
예제 #17
0
        public virtual async Task <(IEnumerable <LogModel> logModels, int totalCount)> PrepareLogModel(LogListModel model, int pageIndex, int pageSize)
        {
            DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            LogLevel?logLevel = model.LogLevelId > 0 ? (LogLevel?)(model.LogLevelId) : null;


            var logItems = await _logger.GetAllLogs(createdOnFromValue, createdToFromValue, model.Message,
                                                    logLevel, pageIndex - 1, pageSize);

            return(logItems.Select(x => new LogModel
            {
                Id = x.Id,
                LogLevel = x.LogLevel.GetLocalizedEnum(_localizationService, _workContext),
                ShortMessage = x.ShortMessage,
                //little hack here:
                //ensure that FullMessage is not returned
                //otherwise, we can get the following error if log records have too long FullMessage:
                //"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. "
                //also it improves performance
                //FullMessage = x.FullMessage,
                FullMessage = "",
                IpAddress = x.IpAddress,
                CustomerId = x.CustomerId,
                PageUrl = x.PageUrl,
                ReferrerUrl = x.ReferrerUrl,
                CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc)
            }), logItems.TotalCount);
        }
예제 #18
0
        public ActionResult AffiliatedOrderList(DataSourceRequest command, AffiliatedOrderListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates))
            {
                return(AccessDeniedView());
            }

            var affiliate = _affiliateService.GetAffiliateById(model.AffliateId);

            if (affiliate == null)
            {
                throw new ArgumentException("No affiliate found with the specified id");
            }

            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var orderStatusIds = model.OrderStatusId > 0 ? new List <int>()
            {
                model.OrderStatusId
            } : null;
            var paymentStatusIds = model.PaymentStatusId > 0 ? new List <int>()
            {
                model.PaymentStatusId
            } : null;
            var shippingStatusIds = model.ShippingStatusId > 0 ? new List <int>()
            {
                model.ShippingStatusId
            } : null;

            var orders = _orderService.SearchOrders(
                createdFromUtc: startDateValue,
                createdToUtc: endDateValue,
                osIds: orderStatusIds,
                psIds: paymentStatusIds,
                ssIds: shippingStatusIds,
                affiliateId: affiliate.Id,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data = orders.Select(order =>
                {
                    var orderModel            = new AffiliateModel.AffiliatedOrderModel();
                    orderModel.Id             = order.Id;
                    orderModel.OrderStatus    = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.PaymentStatus  = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.OrderTotal     = _priceFormatter.FormatPrice(order.OrderTotal, true, false);
                    orderModel.CreatedOn      = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc);
                    return(orderModel);
                }),
                Total = orders.TotalCount
            };

            return(Json(gridModel));
        }
예제 #19
0
        public virtual (IEnumerable <AffiliateModel.AffiliatedOrderModel> affiliateOrderModels, int totalCount) PrepareAffiliatedOrderList(Affiliate affiliate, AffiliatedOrderListModel model, int pageIndex, int pageSize)
        {
            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            OrderStatus?   orderStatus    = model.OrderStatusId > 0 ? (OrderStatus?)(model.OrderStatusId) : null;
            PaymentStatus? paymentStatus  = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;
            ShippingStatus?shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)(model.ShippingStatusId) : null;

            var orders = _orderService.SearchOrders(
                createdFromUtc: startDateValue,
                createdToUtc: endDateValue,
                os: orderStatus,
                ps: paymentStatus,
                ss: shippingStatus,
                affiliateId: affiliate.Id,
                pageIndex: pageIndex - 1,
                pageSize: pageSize);

            return(orders.Select(order =>
            {
                var orderModel = new AffiliateModel.AffiliatedOrderModel();
                orderModel.Id = order.Id;
                orderModel.OrderNumber = order.OrderNumber;
                orderModel.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext);
                orderModel.PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext);
                orderModel.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext);
                orderModel.OrderTotal = _priceFormatter.FormatPrice(order.OrderTotal, true, false);
                orderModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc);
                return orderModel;
            }), orders.TotalCount);
        }
예제 #20
0
        public virtual IActionResult Edit(QueuedEmailModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageQueue))
            {
                return(AccessDeniedView());
            }

            //try to get a queued email with the specified id
            var email = _queuedEmailService.GetQueuedEmailById(model.Id);

            if (email == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                email = model.ToEntity(email);
                email.DontSendBeforeDateUtc = model.SendImmediately || !model.DontSendBeforeDate.HasValue ?
                                              null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value);
                _queuedEmailService.UpdateQueuedEmail(email);

                SuccessNotification(_localizationService.GetResource("Admin.System.QueuedEmails.Updated"));

                return(continueEditing ? RedirectToAction("Edit", new { id = email.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = _queuedEmailModelFactory.PrepareQueuedEmailModel(model, email, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #21
0
        public ActionResult List(GridCommand command, ProductReviewListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var productReviews = _customerContentService.GetAllCustomerContent <ProductReview>(0, null,
                                                                                               createdOnFromValue, createdToFromValue);
            var gridModel = new GridModel <ProductReviewModel>
            {
                Data = productReviews.PagedForCommand(command).Select(x =>
                {
                    var m = new ProductReviewModel();
                    PrepareProductReviewModel(m, x, false, true);
                    return(m);
                }),
                Total = productReviews.Count,
            };

            return(new JsonResult
            {
                Data = gridModel
            });
        }
        public virtual ActionResult ListLogs(DataSourceRequest command, ActivityLogSearchModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedKendoGridJson());
            }

            DateTime?startDateValue = (model.CreatedOnFrom == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var activityLog = _customerActivityService.GetAllActivities(startDateValue, endDateValue, null, model.ActivityLogTypeId, command.Page - 1, command.PageSize, model.IpAddress);
            var gridModel   = new DataSourceResult
            {
                Data = activityLog.Select(x =>
                {
                    var m       = x.ToModel();
                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }),
                Total = activityLog.TotalCount
            };

            return(Json(gridModel));
        }
예제 #23
0
        public ActionResult List(GridCommand command, ProductReviewListModel model)
        {
            DateTime?createdFrom = (model.CreatedOnFrom == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdTo = (model.CreatedOnTo == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var productReviews = _customerContentService.GetAllCustomerContent <ProductReview>(
                0,
                null,
                createdFrom,
                createdTo,
                command.Page - 1,
                command.PageSize);

            var gridModel = new GridModel <ProductReviewModel>
            {
                Total = productReviews.TotalCount
            };

            gridModel.Data = productReviews.Select(x =>
            {
                var m = new ProductReviewModel();
                PrepareProductReviewModel(m, x, false, true);
                return(m);
            });

            return(new JsonResult
            {
                Data = gridModel
            });
        }
예제 #24
0
        public virtual ActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity();
                campaign.CreatedOnUtc          = DateTime.UtcNow;
                campaign.DontSendBeforeDateUtc = model.DontSendBeforeDate.HasValue ?
                                                 (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value) : null;
                _campaignService.InsertCampaign(campaign);

                //activity log
                _customerActivityService.InsertActivity("AddNewCampaign", _localizationService.GetResource("ActivityLog.AddNewCampaign"), campaign.Id);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            model.AllowedTokens = string.Join(", ", _messageTokenProvider.GetListOfCampaignAllowedTokens());
            //stores
            PrepareStoresModel(model);
            //customer roles
            PrepareCustomerRolesModel(model);
            //email accounts
            PrepareEmailAccountsModel(model);

            return(View(model));
        }
예제 #25
0
        /// <summary>
        /// Prepare paged return request list model
        /// </summary>
        /// <param name="searchModel">Return request search model</param>
        /// <returns>Return request list model</returns>
        public virtual ReturnRequestListModel PrepareReturnRequestListModel(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, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);
            var returnRequestStatus = searchModel.ReturnRequestStatusId == -1 ? null : (ReturnRequestStatus?)searchModel.ReturnRequestStatusId;

            //get return requests
            var returnRequests = _returnRequestService.SearchReturnRequests(customNumber: searchModel.CustomNumber,
                                                                            rs: returnRequestStatus,
                                                                            createdFromUtc: startDateValue,
                                                                            createdToUtc: endDateValue,
                                                                            pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new ReturnRequestListModel().PrepareToGrid(searchModel, returnRequests, () =>
            {
                return(returnRequests.Select(returnRequest =>
                {
                    //fill in model values from the entity
                    var returnRequestModel = returnRequest.ToModel <ReturnRequestModel>();

                    var customer = _customerService.GetCustomerById(returnRequest.CustomerId);

                    //convert dates to the user time
                    returnRequestModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(returnRequest.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    returnRequestModel.CustomerInfo = _customerService.IsRegistered(customer)
                        ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
                    returnRequestModel.ReturnRequestStatusStr = _localizationService.GetLocalizedEnum(returnRequest.ReturnRequestStatus);
                    var orderItem = _orderService.GetOrderItemById(returnRequest.OrderItemId);
                    if (orderItem == null)
                    {
                        return returnRequestModel;
                    }

                    var order = _orderService.GetOrderById(orderItem.OrderId);
                    var product = _productService.GetProductById(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);
        }
예제 #26
0
        public async Task <ActivityLogListModel> PrepareActivityLogListModel(ActivityLogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            var startDateValue = searchModel.CreatedOnFrom == null
                ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value,
                                                              _dateTimeHelper.CurrentTimeZone);
            var endDateValue = searchModel.CreatedOnTo == null
                ? null
                : (DateTime?)_dateTimeHelper
                               .ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var activityLog = _userActivityService.GetAllActivities(
                createdOnFrom: startDateValue,
                createdOnTo: endDateValue,
                activityLogTypeId: searchModel.ActivityLogTypeId,
                ipAddress: searchModel.IpAddress,
                pageIndex: searchModel.Page - 1,
                pageSize: searchModel.PageSize);

            var model = new ActivityLogListModel
            {
                Data = activityLog.Select(logItem =>
                {
                    var logItemModel = logItem.ToModel <ActivityLogModel>();
                    logItemModel.ActivityLogTypeName = logItem.ActivityLogType.Name;
                    logItemModel.UserEmail           = logItem.User.Email;
                    logItemModel.CreatedOn           = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc);

                    return(logItemModel);
                }),
                Total = activityLog.TotalCount
            };

            // sort
            if (searchModel.Sort != null && searchModel.Sort.Any())
            {
                foreach (var s in searchModel.Sort)
                {
                    model.Data = await model.Data.Sort(s.Field, s.Dir);
                }
            }

            // filter
            if (searchModel.Filter?.Filters != null && searchModel.Filter.Filters.Any())
            {
                var filter = searchModel.Filter;
                model.Data = await model.Data.Filter(filter);

                model.Total = model.Data.Count();
            }

            return(model);
        }
        /// <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);
        }
예제 #28
0
        public ActionResult LogList(GridCommand command, LogListModel model)
        {
            var gridModel = new GridModel <LogModel>();

            if (_permissionService.Authorize(StandardPermissionProvider.ManageSystemLog))
            {
                DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                                        : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

                DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                                        : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

                LogLevel?logLevel = model.LogLevelId > 0 ? (LogLevel?)(model.LogLevelId) : null;

                var logItems = Logger.GetAllLogs(createdOnFromValue, createdToFromValue, model.Message,
                                                 logLevel, command.Page - 1, command.PageSize, model.MinFrequency);

                gridModel.Data = logItems.Select(x =>
                {
                    var logModel = new LogModel
                    {
                        Id            = x.Id,
                        LogLevelHint  = s_logLevelHintMap[x.LogLevel],
                        LogLevel      = x.LogLevel.GetLocalizedEnum(_localizationService, _workContext),
                        ShortMessage  = x.ShortMessage,
                        FullMessage   = x.FullMessage,
                        IpAddress     = x.IpAddress,
                        CustomerId    = x.CustomerId,
                        CustomerEmail = x.Customer != null ? x.Customer.Email : null,
                        PageUrl       = x.PageUrl,
                        ReferrerUrl   = x.ReferrerUrl,
                        CreatedOn     = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc),
                        Frequency     = x.Frequency,
                        ContentHash   = x.ContentHash
                    };

                    if (x.UpdatedOnUtc.HasValue)
                    {
                        logModel.UpdatedOn = _dateTimeHelper.ConvertToUserTime(x.UpdatedOnUtc.Value, DateTimeKind.Utc);
                    }

                    return(logModel);
                });

                gridModel.Total = logItems.TotalCount;
            }
            else
            {
                gridModel.Data = Enumerable.Empty <LogModel>();

                NotifyAccessDenied();
            }

            return(new JsonResult
            {
                Data = gridModel
            });
        }
예제 #29
0
        public ActionResult LogList(DataTablesParam dataTableParam, LogListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSystemLog))
            {
                return(AccessDeniedView());
            }

            DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            LogLevel?logLevel = model.LogLevelId > 0 ? (LogLevel?)(model.LogLevelId) : null;


            var logItems = Logger.GetAllLogs(createdOnFromValue, createdToFromValue, model.Message,
                                             logLevel, dataTableParam.iDisplayStart / dataTableParam.iDisplayLength, dataTableParam.iDisplayLength, model.MinFrequency);

            var result = new DataTablesData
            {
                iTotalRecords        = logItems.TotalCount,
                iTotalDisplayRecords = logItems.TotalCount,
                sEcho  = dataTableParam.sEcho,
                aaData = logItems.Select(x =>
                {
                    var logModel = new LogModel()
                    {
                        Id           = x.Id,
                        LogLevelHint = s_logLevelHintMap[x.LogLevel],
                        LogLevel     = x.LogLevel.GetLocalizedEnum(_localizationService, _workContext),
                        ShortMessage = x.ShortMessage,
                        FullMessage  = x.FullMessage,
                        IpAddress    = x.IpAddress,
                        UserId       = x.UserId,
                        UserEmail    = x.User != null ? x.User.Email : null,
                        PageUrl      = x.PageUrl,
                        ReferrerUrl  = x.ReferrerUrl,
                        CreatedOn    = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc),
                        Frequency    = x.Frequency,
                        ContentHash  = x.ContentHash
                    };

                    if (x.UpdatedOnUtc.HasValue)
                    {
                        logModel.UpdatedOn = _dateTimeHelper.ConvertToUserTime(x.UpdatedOnUtc.Value, DateTimeKind.Utc);
                    }

                    return(logModel);
                }).Cast <object>().ToArray(),
            };

            return(new JsonResult
            {
                Data = result
            });
        }
예제 #30
0
        /// <summary>
        /// Prepare paged news comment list model
        /// </summary>
        /// <param name="searchModel">News comment search model</param>
        /// <param name="newsItem">News item; pass null to prepare comment models for all news items</param>
        /// <returns>News comment list model</returns>
        public virtual NewsCommentListModel PrepareNewsCommentListModel(NewsCommentSearchModel searchModel, NewsItem newsItem)
        {
            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, _dateTimeHelper.CurrentTimeZone);
            var createdOnToValue = searchModel.CreatedOnTo == null ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);
            var isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false;

            //get comments
            var comments = _newsService.GetAllComments(newsItemId: newsItem?.Id,
                                                       approved: isApprovedOnly,
                                                       fromUtc: createdOnFromValue,
                                                       toUtc: createdOnToValue,
                                                       commentText: searchModel.SearchText);

            //prepare store names (to avoid loading for each comment)
            var storeNames = _storeService.GetAllStores().ToDictionary(store => store.Id, store => store.Name);

            //prepare list model
            var model = new NewsCommentListModel
            {
                Data = comments.PaginationByRequestModel(searchModel).Select(newsComment =>
                {
                    //fill in model values from the entity
                    var commentModel = new NewsCommentModel
                    {
                        Id            = newsComment.Id,
                        NewsItemId    = newsComment.NewsItemId,
                        NewsItemTitle = newsComment.NewsItem.Title,
                        CustomerId    = newsComment.CustomerId,
                        IsApproved    = newsComment.IsApproved,
                        StoreId       = newsComment.StoreId,
                        CommentTitle  = newsComment.CommentTitle
                    };

                    //convert dates to the user time
                    commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsComment.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    commentModel.CustomerInfo = newsComment.Customer.IsRegistered()
                        ? newsComment.Customer.Email : _localizationService.GetResource("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);
                }),
                Total = comments.Count
            };

            return(model);
        }