public async Task <UserActivityLogListModel> PrepareUserActivityLogListModel(UserActivityLogSearchModel searchModel, User user) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (user == null) { throw new ArgumentNullException(nameof(user)); } var activityLog = _userActivityService.GetAllActivities( userId: user.Id, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); var model = new UserActivityLogListModel { Data = activityLog.Select(logItem => { var userActivityLogModel = logItem.ToModel <UserActivityLogModel>(); userActivityLogModel.ActivityLogTypeName = logItem.ActivityLogType.Name; userActivityLogModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc); return(userActivityLogModel); }), 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 != null && 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 user activity log list model /// </summary> /// <param name="searchModel">User activity log search model</param> /// <param name="user">User</param> /// <returns>User activity log list model</returns> public virtual UserActivityLogListModel PrepareUserActivityLogListModel(UserActivityLogSearchModel searchModel, User user) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (user == null) { throw new ArgumentNullException(nameof(user)); } //get user activity log var activityLog = _userActivityService.GetAllActivities(userId: user.Id, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare list model var model = new UserActivityLogListModel { Data = activityLog.Select(logItem => { //fill in model values from the entity var userActivityLogModel = new UserActivityLogModel { Id = logItem.Id, ActivityLogTypeName = logItem.ActivityLogType.Name, Comment = logItem.Comment, IpAddress = logItem.IpAddress }; //convert dates to the user time userActivityLogModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc); return(userActivityLogModel); }), Total = activityLog.TotalCount }; return(model); }