public Response <PagedModel <UserCalculationVM> > GetAllForList(UserListingProperty listingProperty) { var repository = GetInstance <IUserRepository>(); var result = SafeExecute(() => repository.GetAllForList(listingProperty)); return(result); }
public PagedModel <UserCalculationVM> GetAllForList(UserListingProperty listingProperty) { DateTime startDate, endDate; DateTime.TryParse(listingProperty.StartDate, out startDate); endDate = DateTime.TryParse(listingProperty.EndDate, out endDate) ? endDate : DateTime.Now; var userList = (from users in MisfitDBSet.AsNoTracking() join calculation in MisfitDBContext.Calculations on users.Id equals calculation.UserId where (String.IsNullOrWhiteSpace(listingProperty.UserName) ? true : users.UserName.Contains(listingProperty.UserName)) && (DateTime.TryParse(listingProperty.StartDate, out startDate) ? calculation.CreatedOn >= startDate : true) && calculation.CreatedOn <= endDate //select users) //.Include(i => i.Calculations).AsQueryable(); select new UserCalculationVM { UserId = users.Id, UserName = users.UserName, Num1 = calculation.Num1, Num2 = calculation.Num2, Sum = calculation.Sum, CreatedOn = calculation.CreatedOn.Value }).AsQueryable(); var total = userList.Count(); if (!String.IsNullOrEmpty(listingProperty.SortBy)) { var sortContext = typeof(UserCalculationVM).GetProperty(listingProperty.SortBy); if (listingProperty.SortingOrder.Equals("asc")) { userList = userList.OrderBy(c => sortContext.GetValue(c)); } else { userList = userList.OrderByDescending(c => sortContext.GetValue(c)); } } else { var defaultSort = typeof(UserCalculationVM).GetProperty("CreatedOn"); userList = userList.OrderByDescending(c => defaultSort.GetValue(c)); } //var pageCount = (double)total / listingProperty.PageSize; // var skip = (listingProperty.PageNumber - 1) * listingProperty.PageSize; // userList = userList.Skip(skip).Take(listingProperty.PageSize); return(CreatedPagedModel <UserCalculationVM>(userList, listingProperty.PageNumber, listingProperty.PageSize)); }
public IActionResult GetForList(UserListingProperty listingProperty) { return(Ok(userService.GetAllForList(listingProperty))); }