public List <PointByUserModel> GetPointByUser(int userId, int numberOfRow) { var output = _ctx.Points .Include("User").Include("User.Position").Include("User.Position.Department") .Include("User.Subdivision") .Where(point => point.UserId == userId).OrderByDescending(point => point.YM).ToList(); if (numberOfRow > 0) { output = output.Take(numberOfRow).ToList(); } List <PointByUserModel> pointUserList = new List <PointByUserModel>(); foreach (var point in output) { PointByUserModel pointUser = new PointByUserModel(point); pointUserList.Add(pointUser); } return(pointUserList); }
public List <PointByUserModel> SearchPointForInputPoint(PointFilters pointFilters, Sorter sorter, PagingTable pagingTable) { var output = _ctx.Points .Include("User").Include("User.Position").Include("User.Position.Department") .Include("User.Subdivision"); //filter if (pointFilters != null) { if (pointFilters.DepartmentId.HasValue && pointFilters.DepartmentId > 0) { output.Where(point => point.User.Position.DepartmentId == pointFilters.DepartmentId); } if (pointFilters.SubdivisionId.HasValue && pointFilters.SubdivisionId > 0) { output.Where(point => point.User.SubdivisionId == pointFilters.SubdivisionId); } if (pointFilters.PositionId.HasValue && pointFilters.PositionId > 0) { output.Where(point => point.User.PositionId == pointFilters.PositionId); } if (pointFilters.UserId.HasValue && pointFilters.UserId > 0) { output.Where(point => point.UserId == pointFilters.UserId); } if (pointFilters.YMStart.HasValue) { output.Where(point => point.YM >= pointFilters.YMStart); } if (pointFilters.YMEnd.HasValue) { output.Where(point => point.YM <= pointFilters.YMEnd); } } //sorter if (sorter != null) { if (!string.IsNullOrEmpty(sorter.FieldName)) { Type pointModelType = typeof(PointByUserModel); var property = pointModelType.GetProperty(sorter.FieldName); if (property != null) { string pointModelPropertyName = property.Name; if (pointModelPropertyName == "YM") { if (sorter.OnDesc) { output.OrderByDescending(p => p.YM); } else { output.OrderBy(p => p.YM); } } else if (pointModelPropertyName == "UserId") { if (sorter.OnDesc) { output.OrderByDescending(p => p.UserId); } else { output.OrderBy(p => p.UserId); } } else if (pointModelPropertyName == "Name") { if (sorter.OnDesc) { output.OrderByDescending(p => p.User.Name); } else { output.OrderBy(p => p.User.Name); } } else if (pointModelPropertyName == "Lastname") { if (sorter.OnDesc) { output.OrderByDescending(p => p.User.Lastname); } else { output.OrderBy(p => p.User.Lastname); } } else if (pointModelPropertyName == "PositionName") { if (sorter.OnDesc) { output.OrderByDescending(p => p.User.Position.Name); } else { output.OrderBy(p => p.User.Position.Name); } } else if (pointModelPropertyName == "DepartmentName") { if (sorter.OnDesc) { output.OrderByDescending(p => p.User.Position.Department.Name); } else { output.OrderBy(p => p.User.Position.Department.Name); } } else if (pointModelPropertyName == "SubdivisionName") { if (sorter.OnDesc) { output.OrderByDescending(p => p.User.Subdivision.Name); } else { output.OrderBy(p => p.User.Subdivision.Name); } } else if (pointModelPropertyName == "Point") { if (sorter.OnDesc) { output.OrderByDescending(p => p.MonthlyPoint); } else { output.OrderBy(p => p.MonthlyPoint); } } else if (pointModelPropertyName == "Remark") { if (sorter.OnDesc) { output.OrderByDescending(p => p.Remark); } else { output.OrderBy(p => p.Remark); } } else if (pointModelPropertyName == "TargetPoint") { if (sorter.OnDesc) { output.OrderByDescending(p => p.User.Position.TargetPoint); } else { output.OrderBy(p => p.User.Position.TargetPoint); } } else if (pointModelPropertyName == "ModifyDate") { if (sorter.OnDesc) { output.OrderByDescending(p => p.ModifyDate); } else { output.OrderBy(p => p.ModifyDate); } } } } } //paging if (pagingTable != null) { if (pagingTable.CurrentPage < 1) { pagingTable.CurrentPage = 1; } if (pagingTable.PageSize > 0) { output.ToPagedList(pagingTable.CurrentPage, pagingTable.PageSize); } } List <Point> rawPoint = output.ToList(); List <PointByUserModel> points = new List <PointByUserModel>(); foreach (Point point in rawPoint) { PointByUserModel pm = new PointByUserModel(point); points.Add(pm); } return(points); }