示例#1
0
        public virtual IActionResult ListLogs(ActivityLogSearchModel searchModel)
        {
            //prepare model
            ActivityLogListModel model = _activityLogModelFactory.PrepareActivityLogListModel(searchModel);

            return(Json(model));
        }
示例#2
0
        public virtual ActionResult ListLogs(DataSourceRequest command, ActivityLogListModel 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));
        }
示例#3
0
        private ActivityLogListModel GetRecords(ActivityLogListFilter filter, int pageNumber)
        {
            int totalCount = 0;
            var model      = new ActivityLogListModel();

            try
            {
                filter.EndDate = filter.EndDate.AddHours(23).AddMinutes(59);
                model          = _activityLogViewService.GetList(filter, pageNumber, _settings.DefaultPageSizeForReports,
                                                                 out totalCount);
            }
            catch (Exception e)
            {
                _logger.Error(e);
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Some Error Occured");
            }

            model.PagingModel = new PagingModel(pageNumber, _settings.DefaultPageSizeForReports, totalCount,
                                                p =>
                                                Server.UrlDecode(Url.Action("Index",
                                                                            new
            {
                StartDate  = filter.StartDate.Date,
                EndDate    = filter.EndDate.Date,
                pageNumber = p,
                filter.AccessedBy,
                filter.CustomerName,
                filter.AccessedByName,
                filter.CustomerId
            })));

            return(model);
        }
示例#4
0
        public virtual ActionResult ListLogs()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageActivityLog))
            {
                return(AccessDeniedView());
            }

            var model = new ActivityLogListModel();

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

            foreach (var at in _customerActivityService.GetAllActivityTypes())
            {
                model.ActivityLogType.Add(new SelectListItem
                {
                    Value = at.Id.ToString(),
                    Text  = at.Name
                });
            }

            return(View(model));
        }
        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 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);
        }
        /// <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);
        }
示例#8
0
        /// <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);
        }