public virtual IActionResult ListLogs(ActivityLogSearchModel searchModel)
        {
            //prepare model
            ActivityLogListModel model = _activityLogModelFactory.PrepareActivityLogListModel(searchModel);

            return(Json(model));
        }
        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
            });
        }
        public virtual IActionResult ListLogs()
        {
            //prepare model
            ActivityLogSearchModel model = _activityLogModelFactory.PrepareActivityLogSearchModel(new ActivityLogSearchModel());

            return(View(model));
        }
        public ActionResult ListLogs()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }

            var activityLogSearchModel = new ActivityLogSearchModel();

            activityLogSearchModel.ActivityLogType.Add(new SelectListItem()
            {
                Value = "0",
                Text  = "All"
            });


            foreach (var at in _customerActivityService.GetAllActivityTypes()
                     .OrderBy(x => x.Name)
                     .Select(x =>
            {
                return(new SelectListItem()
                {
                    Value = x.Id.ToString(),
                    Text = x.Name
                });
            }))
            {
                activityLogSearchModel.ActivityLogType.Add(at);
            }
            return(View(activityLogSearchModel));
        }
        public virtual IActionResult ListLogs(DataSourceRequest command, ActivityLogSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedKendoGridJson());
            }

            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 = _customerActivityService.GetAllActivities(createdOnFrom: startDateValue,
                                                                        createdOnTo: endDateValue,
                                                                        activityLogTypeId: searchModel.ActivityLogTypeId,
                                                                        ipAddress: searchModel.IpAddress,
                                                                        pageIndex: command.Page - 1, pageSize: command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data = activityLog.Select(logItem =>
                {
                    var model       = logItem.ToModel();
                    model.CreatedOn = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc);

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

            return(Json(gridModel));
        }
        public IActionResult ListLogs(DataSourceRequest command, ActivityLogSearchModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }

            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, model.IpAddress, command.Page - 1, command.PageSize);
            var gridModel   = new DataSourceResult
            {
                Data = activityLog.Select(x =>
                {
                    var customer          = _customerService.GetCustomerById(x.CustomerId);
                    var m                 = x.ToModel();
                    m.CreatedOn           = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.ActivityLogTypeName = _customerActivityService.GetActivityTypeById(m.ActivityLogTypeId)?.Name;
                    m.CustomerEmail       = customer != null ? customer.Email : "NULL";
                    return(m);
                }),
                Total = activityLog.TotalCount
            };

            return(Json(gridModel));
        }
        public ActionResult ListLogs(GridCommand command, ActivityLogSearchModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }

            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);
            var gridModel   = new GridModel <ActivityLogModel>
            {
                Data = activityLog.Select(x =>
                {
                    var m       = x.ToModel();
                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }),
                Total = activityLog.TotalCount
            };

            return(new JsonResult {
                Data = gridModel
            });
        }
        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);
        }
        public virtual IActionResult ListLogs(ActivityLogSearchModel searchModel)
        {
            //if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            //    return AccessDeniedKendoGridJson();

            //prepare model
            var model = _activityLogModelFactory.PrepareActivityLogListModel(searchModel);

            return(Json(model));
        }
Beispiel #10
0
        public IActionResult ListLogs(DataSourceRequest command, ActivityLogSearchModel model)
        {
            var activitymodel = _activityLogViewModelService.PrepareActivityLogModel(model, command.Page, command.PageSize);
            var gridModel     = new DataSourceResult
            {
                Data  = activitymodel.activityLogs,
                Total = activitymodel.totalCount
            };

            return(Json(gridModel));
        }
        public async Task <IActionResult> ListLogs(ActivityLogSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }

            var model = await _activityLogModelFactory.PrepareActivityLogListModel(searchModel);

            return(Json(model));
        }
Beispiel #12
0
        public async Task <IActionResult> ListStats(DataSourceRequest command, ActivityLogSearchModel model)
        {
            var activityStatmodel = await _activityLogViewModelService.PrepareActivityStatModel(model, command.Page, command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data  = activityStatmodel.activityStats,
                Total = activityStatmodel.totalCount
            };

            return(Json(gridModel));
        }
Beispiel #13
0
        public virtual async Task <IActionResult> ListLogs(ActivityLogSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageActivityLog))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = await _activityLogModelFactory.PrepareActivityLogListModelAsync(searchModel);

            return(Json(model));
        }
        public JsonResult ListActivityLogs(GridCommand command, 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 = _customerActivityService.GetAllActivities(startDateValue, endDateValue, null, model.ActivityLogTypeId,
                                                                        command.Page - 1, command.PageSize, model.CustomerEmail, model.CustomerSystemAccount);

            var systemAccountCustomers = _customerService.GetSystemAccountCustomers();

            var gridModel = new GridModel <ActivityLogModel>
            {
                Data = activityLog.Select(x =>
                {
                    var m = x.ToModel();
                    var systemCustomer = systemAccountCustomers.FirstOrDefault(y => y.Id == x.CustomerId);

                    m.CreatedOn       = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.IsSystemAccount = (systemCustomer != null);

                    if (systemCustomer != null)
                    {
                        if (systemCustomer.IsSearchEngineAccount())
                        {
                            m.SystemAccountName = T("Admin.System.SystemCustomerNames.SearchEngine");
                        }
                        else if (systemCustomer.IsBackgroundTaskAccount())
                        {
                            m.SystemAccountName = T("Admin.System.SystemCustomerNames.BackgroundTask");
                        }
                        else if (systemCustomer.IsPdfConverter())
                        {
                            m.SystemAccountName = T("Admin.System.SystemCustomerNames.PdfConverter");
                        }
                        else
                        {
                            m.SystemAccountName = "".NaIfEmpty();
                        }
                    }

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

            return(new JsonResult {
                Data = gridModel
            });
        }
        /// <summary>
        /// Prepare activity log search model
        /// </summary>
        /// <param name="searchModel">Activity log search model</param>
        /// <returns>Activity log search model</returns>
        public virtual ActivityLogSearchModel PrepareActivityLogSearchModel(ActivityLogSearchModel searchModel)
        {
            //if (searchModel == null)
            //    throw new ArgumentNullException(nameof(searchModel));

            //prepare available activity log types
            _baseAdminModelFactory.PrepareActivityLogTypes(searchModel.ActivityLogType);

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
        public async Task <ActivityLogSearchModel> PrepareActivityLogSearchModel(ActivityLogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare selectlist
            await _baseModelFactory.PrepareActivityLogTypes(searchModel.ActivityLogType);

            searchModel.SetGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare paged activity log list model
        /// </summary>
        /// <param name="searchModel">Activity log search model</param>
        /// <returns>Activity log list model</returns>
        public virtual ActivityLogListModel PrepareActivityLogListModel(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, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = searchModel.CreatedOnTo == null ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //get log
            var activityLog = _customerActivityService.GetAllActivities(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 model = new ActivityLogListModel().PrepareToGrid(searchModel, activityLog, () =>
            {
                var activityLogCustomers = _customerService.GetCustomersByIds(activityLog.GroupBy(x => x.CustomerId).Select(x => x.Key).ToArray());

                return(activityLog.Select(logItem =>
                {
                    //fill in model values from the entity
                    var logItemModel = logItem.ToModel <ActivityLogModel>();
                    logItemModel.ActivityLogTypeName = _customerActivityService.GetActivityTypeById(logItem.ActivityLogTypeId)?.Name;
                    logItemModel.CustomerEmail = activityLogCustomers?.FirstOrDefault(x => x.Id == logItem.CustomerId)?.Email;

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

                    return logItemModel;
                }));
            });

            return(model);
        }
        public ActionResult ListLogs(DataSourceRequest command, ActivityLogSearchModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }
            var customerLogs = _customerActivityService.GetAllActivities(model.SearchStartDate,
                                                                         model.SearchEndDate, null, model.ActivityLogTypeId, command.Page - 1,
                                                                         command.PageSize, model.IpAddress);
            var modle     = customerLogs.Select(x => x.ToModel()).ToList();
            var gridModel = new DataSourceResult
            {
                Data  = modle,
                Total = customerLogs.TotalCount
            };

            return(Json(gridModel));
        }
        public ActionResult ListLogs()
        {
            var model = new ActivityLogSearchModel
            {
                GridPageSize = _adminAreaSettings.GridPageSize
            };

            model.ActivityLogType = _customerActivityService.GetAllActivityTypes()
                                    .OrderBy(x => x.Name)
                                    .Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            })
                                    .ToList();

            return(View(model));
        }
        public virtual async Task <ActivityLogSearchModel> PrepareActivityLogSearchModel()
        {
            var activityLogSearchModel = new ActivityLogSearchModel();

            activityLogSearchModel.ActivityLogType.Add(new SelectListItem
            {
                Value = "",
                Text  = "All"
            });
            foreach (var at in await _customerActivityService.GetAllActivityTypes())
            {
                activityLogSearchModel.ActivityLogType.Add(new SelectListItem
                {
                    Value = at.Id.ToString(),
                    Text  = at.Name
                });
            }
            return(activityLogSearchModel);
        }
        /// <summary>
        /// Prepare paged activity log list model
        /// </summary>
        /// <param name="searchModel">Activity log search model</param>
        /// <returns>Activity log list model</returns>
        public virtual ActivityLogListModel PrepareActivityLogListModel(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, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = searchModel.CreatedOnTo == null ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

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

            //prepare list model
            var model = new ActivityLogListModel
            {
                Data = activityLog.Select(logItem =>
                {
                    //fill in model values from the entity
                    var logItemModel = logItem.ToModel <ActivityLogModel>();
                    logItemModel.ActivityLogTypeName = logItem.ActivityLogType.Name;
                    logItemModel.CustomerEmail       = logItem.Customer.Email;

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

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

            return(model);
        }
        /// <summary>
        /// Prepare paged activity log list model
        /// </summary>
        /// <param name="searchModel">Activity log search model</param>
        /// <returns>Activity log list model</returns>
        public virtual ActivityLogListModel PrepareActivityLogListModel(ActivityLogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter log
            DateTime?startDateValue = searchModel.CreatedOnFrom == null ? null
                : (DateTime?)searchModel.CreatedOnFrom.Value;
            DateTime?endDateValue = searchModel.CreatedOnTo == null ? null
                : (DateTime?)searchModel.CreatedOnTo.Value.AddDays(1);

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

            //prepare list model
            ActivityLogListModel model = new ActivityLogListModel
            {
                Data = activityLog.Select(logItem =>
                {
                    //fill in model values from the entity
                    ActivityLogModel logItemModel = logItem.ToModel <ActivityLogModel>();

                    //convert dates to the user time
                    logItemModel.CreatedOn = logItem.CreatedOnUtc;

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

            return(model);
        }
        public ActionResult ListLogs()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }

            var model = new ActivityLogSearchModel
            {
                GridPageSize = _adminAreaSettings.GridPageSize
            };

            model.ActivityLogType = _customerActivityService.GetAllActivityTypes()
                                    .OrderBy(x => x.Name)
                                    .Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            })
                                    .ToList();

            return(View(model));
        }
        public JsonResult ListLogs(GridCommand command, 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 activityLogModel = _customerActivityService.GetAllActivities(startDateValue, endDateValue, model.CustomerEmail, null, model.ActivityLogTypeId, command.Page - 1, command.PageSize);
            var gridModel        = new GridModel <ActivityLogModel>
            {
                Data = activityLogModel.Select(x =>
                {
                    var m       = x.ToModel();
                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }),
                Total = activityLogModel.TotalCount
            };

            return(new JsonResult {
                Data = gridModel
            });;
        }
        public ActionResult ListLogs()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }
            var logTypes = _customerActivityService.GetAllActivityTypes();
            var model    = new ActivityLogSearchModel();

            model.ActivityLogTypes.Add(new SelectListItem
            {
                Value = "0",
                Text  = "All"
            });
            foreach (var at in logTypes)
            {
                model.ActivityLogTypes.Add(new SelectListItem
                {
                    Value = at.Id.ToString(),
                    Text  = at.Name
                });
            }
            return(View(model));
        }
        public virtual (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 = _customerActivityService.GetAllActivities(startDateValue, endDateValue, null, model.ActivityLogTypeId, model.IpAddress, pageIndex - 1, pageSize);

            return(activityLog.Select(x => {
                var customer = _customerService.GetCustomerById(x.CustomerId);
                var m = x.ToModel();
                m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                m.ActivityLogTypeName = _customerActivityService.GetActivityTypeById(m.ActivityLogTypeId)?.Name;
                m.CustomerEmail = customer != null ? customer.Email : "NULL";
                return m;
            }), activityLog.TotalCount);
        }
        public virtual async Task <(IEnumerable <ActivityStatsModel> activityStats, int totalCount)> PrepareActivityStatModel(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 activityStat = await _customerActivityService.GetStatsActivities(startDateValue, endDateValue, model.ActivityLogTypeId, pageIndex - 1, pageSize);

            var activityStatModel = new List <ActivityStatsModel>();

            foreach (var x in activityStat)
            {
                var activityLogType = await _customerActivityService.GetActivityTypeById(x.ActivityLogTypeId);

                string _name = "-empty-";
                if (activityLogType != null)
                {
                    IList <string> systemKeywordsCategory = new List <string>();
                    systemKeywordsCategory.Add("PublicStore.ViewCategory");
                    systemKeywordsCategory.Add("EditCategory");
                    systemKeywordsCategory.Add("AddNewCategory");

                    if (systemKeywordsCategory.Contains(activityLogType.SystemKeyword))
                    {
                        var category = await _categoryService.GetCategoryById(x.EntityKeyId);

                        if (category != null)
                        {
                            _name = category.Name;
                        }
                    }

                    IList <string> systemKeywordsManufacturer = new List <string>();
                    systemKeywordsManufacturer.Add("PublicStore.ViewManufacturer");
                    systemKeywordsManufacturer.Add("EditManufacturer");
                    systemKeywordsManufacturer.Add("AddNewManufacturer");

                    if (systemKeywordsManufacturer.Contains(activityLogType.SystemKeyword))
                    {
                        var manufacturer = await _manufacturerService.GetManufacturerById(x.EntityKeyId);

                        if (manufacturer != null)
                        {
                            _name = manufacturer.Name;
                        }
                    }

                    IList <string> systemKeywordsProduct = new List <string>();
                    systemKeywordsProduct.Add("PublicStore.ViewProduct");
                    systemKeywordsProduct.Add("EditProduct");
                    systemKeywordsProduct.Add("AddNewProduct");

                    if (systemKeywordsProduct.Contains(activityLogType.SystemKeyword))
                    {
                        var product = await _productService.GetProductById(x.EntityKeyId);

                        if (product != null)
                        {
                            _name = product.Name;
                        }
                    }
                    IList <string> systemKeywordsUrl = new List <string>();
                    systemKeywordsUrl.Add("PublicStore.Url");
                    if (systemKeywordsUrl.Contains(activityLogType.SystemKeyword))
                    {
                        _name = x.EntityKeyId;
                    }

                    IList <string> systemKeywordsKnowledgebaseCategory = new List <string>();
                    systemKeywordsKnowledgebaseCategory.Add("CreateKnowledgebaseCategory");
                    systemKeywordsKnowledgebaseCategory.Add("UpdateKnowledgebaseCategory");
                    systemKeywordsKnowledgebaseCategory.Add("DeleteKnowledgebaseCategory");

                    if (systemKeywordsKnowledgebaseCategory.Contains(activityLogType.SystemKeyword))
                    {
                        var category = await _knowledgebaseService.GetKnowledgebaseCategory(x.EntityKeyId);

                        if (category != null)
                        {
                            _name = category.Name;
                        }
                    }

                    IList <string> systemKeywordsKnowledgebaseArticle = new List <string>();
                    systemKeywordsKnowledgebaseArticle.Add("CreateKnowledgebaseArticle");
                    systemKeywordsKnowledgebaseArticle.Add("UpdateKnowledgebaseArticle");
                    systemKeywordsKnowledgebaseArticle.Add("DeleteKnowledgebaseArticle");

                    if (systemKeywordsKnowledgebaseArticle.Contains(activityLogType.SystemKeyword))
                    {
                        var article = await _knowledgebaseService.GetKnowledgebaseArticle(x.EntityKeyId);

                        if (article != null)
                        {
                            _name = article.Name;
                        }
                    }
                }

                var m = x.ToModel();
                m.ActivityLogTypeName = activityLogType != null ? activityLogType.Name : "-empty-";
                m.Name = _name;
                activityStatModel.Add(m);
            }
            return(activityStatModel, activityStat.TotalCount);
        }
        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 IActionResult ListStats(DataSourceRequest command, ActivityLogSearchModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }

            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.GetStatsActivities(startDateValue, endDateValue, model.ActivityLogTypeId, command.Page - 1, command.PageSize);
            var gridModel   = new DataSourceResult
            {
                Data = activityLog.Select(x =>
                {
                    var activityLogType = _customerActivityService.GetActivityTypeById(x.ActivityLogTypeId);
                    string _name        = "-empty-";
                    if (activityLogType != null)
                    {
                        IList <string> systemKeywordsCategory = new List <string>();
                        systemKeywordsCategory.Add("PublicStore.ViewCategory");
                        systemKeywordsCategory.Add("EditCategory");
                        systemKeywordsCategory.Add("AddNewCategory");

                        if (systemKeywordsCategory.Contains(activityLogType.SystemKeyword))
                        {
                            var category = _categoryService.GetCategoryById(x.EntityKeyId);
                            if (category != null)
                            {
                                _name = category.Name;
                            }
                        }

                        IList <string> systemKeywordsManufacturer = new List <string>();
                        systemKeywordsManufacturer.Add("PublicStore.ViewManufacturer");
                        systemKeywordsManufacturer.Add("EditManufacturer");
                        systemKeywordsManufacturer.Add("AddNewManufacturer");

                        if (systemKeywordsManufacturer.Contains(activityLogType.SystemKeyword))
                        {
                            var manufacturer = _manufacturerService.GetManufacturerById(x.EntityKeyId);
                            if (manufacturer != null)
                            {
                                _name = manufacturer.Name;
                            }
                        }

                        IList <string> systemKeywordsProduct = new List <string>();
                        systemKeywordsProduct.Add("PublicStore.ViewProduct");
                        systemKeywordsProduct.Add("EditProduct");
                        systemKeywordsProduct.Add("AddNewProduct");

                        if (systemKeywordsProduct.Contains(activityLogType.SystemKeyword))
                        {
                            var product = _productService.GetProductById(x.EntityKeyId);
                            if (product != null)
                            {
                                _name = product.Name;
                            }
                        }
                        IList <string> systemKeywordsUrl = new List <string>();
                        systemKeywordsUrl.Add("PublicStore.Url");
                        if (systemKeywordsUrl.Contains(activityLogType.SystemKeyword))
                        {
                            _name = x.EntityKeyId;
                        }

                        IList <string> systemKeywordsKnowledgebaseCategory = new List <string>();
                        systemKeywordsKnowledgebaseCategory.Add("CreateKnowledgebaseCategory");
                        systemKeywordsKnowledgebaseCategory.Add("UpdateKnowledgebaseCategory");
                        systemKeywordsKnowledgebaseCategory.Add("DeleteKnowledgebaseCategory");

                        if (systemKeywordsKnowledgebaseCategory.Contains(activityLogType.SystemKeyword))
                        {
                            var category = _knowledgebaseService.GetKnowledgebaseCategory(x.EntityKeyId);
                            if (category != null)
                            {
                                _name = category.Name;
                            }
                        }

                        IList <string> systemKeywordsKnowledgebaseArticle = new List <string>();
                        systemKeywordsKnowledgebaseArticle.Add("CreateKnowledgebaseArticle");
                        systemKeywordsKnowledgebaseArticle.Add("UpdateKnowledgebaseArticle");
                        systemKeywordsKnowledgebaseArticle.Add("DeleteKnowledgebaseArticle");

                        if (systemKeywordsKnowledgebaseArticle.Contains(activityLogType.SystemKeyword))
                        {
                            var article = _knowledgebaseService.GetKnowledgebaseArticle(x.EntityKeyId);
                            if (article != null)
                            {
                                _name = article.Name;
                            }
                        }
                    }

                    var m = x.ToModel();
                    m.ActivityLogTypeName = activityLogType != null ? activityLogType.Name : "-empty-";
                    m.Name = _name;
                    return(m);
                }),
                Total = activityLog.TotalCount
            };

            return(Json(gridModel));
        }
Beispiel #30
0
        /// <summary>
        /// Prepare activity log search 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 search model
        /// </returns>
        public virtual async Task <ActivityLogSearchModel> PrepareActivityLogSearchModelAsync(ActivityLogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available activity log types
            await _baseAdminModelFactory.PrepareActivityLogTypesAsync(searchModel.ActivityLogType);

            //prepare grid
            searchModel.SetGridPageSize();

            return(searchModel);
        }