public MainResponse GetAllGroups(BaseRecordFilterRequest request) { IEnumerable <GroupResponse> GroupResponses; GroupListResponse GroupListResponse = new GroupListResponse(); GroupResponses = (from Group in _context.Groups join address in _context.Addresses on Group.AddressId equals address.AddressId into data1 from data in data1.DefaultIfEmpty() where Group.IsActive == true && Group.IsDeleted == false && data.IsActive == true && data.IsDeleted == false select new GroupResponse { GroupId = Group.GroupId, GroupName = Group.GroupName, ContactName = Group.ContactName, Phone = Group.Phone, Email = Group.Email, AmountReceived = Group.AmountReceived, Address = data != null ? data.Address : "", ZipCodeId = data != null ? data.ZipCodeId : 0, CityId = data != null ? data.CityId : 0, StateId = data != null ? _context.Cities.Where(x => x.CityId == data.CityId).Select(y => y.StateId).FirstOrDefault() : 0, }).ToList(); if (GroupResponses.Count() > 0) { if (request.SearchTerm != null && request.SearchTerm != "") { GroupResponses = GroupResponses.Where(x => Convert.ToString(x.GroupId).ToLower().Contains(request.SearchTerm) || x.GroupName.ToLower().Contains(request.SearchTerm.ToLower())); } var propertyInfo = typeof(GroupResponse).GetProperty(request.OrderBy); if (request.OrderByDescending == true) { GroupResponses = GroupResponses.OrderByDescending(s => s.GetType().GetProperty(request.OrderBy).GetValue(s)).ToList(); } else { GroupResponses = GroupResponses.AsEnumerable().OrderBy(s => propertyInfo.GetValue(s, null)).ToList(); } GroupListResponse.TotalRecords = GroupResponses.Count(); if (request.AllRecords == true) { GroupResponses = GroupResponses.ToList(); } else { GroupResponses = GroupResponses.Skip((request.Page - 1) * request.Limit).Take(request.Limit).ToList(); } } GroupListResponse.groupResponses = GroupResponses.ToList(); _MainResponse.GroupListResponse = GroupListResponse; return(_MainResponse); }
public GroupListResponse SearchGroup(SearchRequest searchRequest) { IEnumerable <GroupResponse> GroupResponses; GroupListResponse GroupListResponse = new GroupListResponse(); GroupResponses = (from Group in _context.Groups join address in _context.Addresses on Group.AddressId equals address.AddressId into data1 from data in data1.DefaultIfEmpty() where Group.IsActive == true && Group.IsDeleted == false && data.IsActive == true && data.IsDeleted == false && ((searchRequest.SearchTerm != string.Empty ? Convert.ToString(Group.GroupId).Contains(searchRequest.SearchTerm) : (1 == 1)) || (searchRequest.SearchTerm != string.Empty ? Group.GroupName.Contains(searchRequest.SearchTerm) : (1 == 1))) select new GroupResponse { GroupId = Group.GroupId, GroupName = Group.GroupName, ContactName = Group.ContactName, Phone = Group.Phone, Email = Group.Email, AmountReceived = Group.AmountReceived, Address = data != null ? data.Address : "", ZipCode = data != null ? data.ZipCode : "", City = data != null ? data.City : "", StateId = data != null ? data.StateId : 0, }).ToList(); if (GroupResponses.Count() > 0) { var propertyInfo = typeof(GroupResponse).GetProperty(searchRequest.OrderBy); if (searchRequest.OrderByDescending == true) { GroupResponses = GroupResponses.OrderByDescending(s => s.GetType().GetProperty(searchRequest.OrderBy).GetValue(s)).ToList(); } else { GroupResponses = GroupResponses.AsEnumerable().OrderBy(s => propertyInfo.GetValue(s, null)).ToList(); } GroupListResponse.TotalRecords = GroupResponses.Count(); if (searchRequest.AllRecords == true) { GroupResponses = GroupResponses.ToList(); } else { GroupResponses = GroupResponses.Skip((searchRequest.Page - 1) * searchRequest.Limit).Take(searchRequest.Limit).ToList(); } } GroupListResponse.groupResponses = GroupResponses.ToList(); return(GroupListResponse); }