public ActionResult MyRequests(POMyRequestsSearchModel model) { var user = User.Identity.Name; var login = AccountService.GetLoginByEmail(user); if (String.IsNullOrWhiteSpace(model.SortOrder)) { model.SortOrder = "Latest First"; } if (model.RequestStatus == null) { model.RequestStatus = PropertyRequestStatus.Submitted; } var res = PropertyOwnerService.GetMyRequests(model, login); model.PagedInput = new PagedInput { ActionName = "MyRequests", ControllerName = "Property", PagedLinkValues = new RouteValueDictionary(new { SortOrder = model.SortOrder, SearchString = model.SearchString, ReturnUrl = model.ReturnUrl, RequestStatus = model.RequestStatus.ToString() }), }; model.InputValues = new List <SearchInput>() { new SearchInput { Name = "RequestStatus", Value = model.RequestStatus.ToString() } }; var rvr = new RouteValueDictionary(new { SearchString = model.SearchString, ReturnUrl = model.ReturnUrl, RequestStatus = model.RequestStatus.ToString() }); var sortOrders = new List <SortOrderModel>(); sortOrders.Add(new SortOrderModel { SortOrder = "Latest First", ActionName = "MyRequests", RouteValues = rvr.AddRouteValue("SortOrder", "Latest First") }); sortOrders.Add(new SortOrderModel { SortOrder = "Earliest First", ActionName = "MyRequests", RouteValues = rvr.AddRouteValue("SortOrder", "Earliest First") }); model.SortOrders = sortOrders; model.SearchCount = res.SearchCount; if (String.IsNullOrWhiteSpace(model.SearchString)) { model.Page = 1; } model.PageCount = res.Items.PageCount; model.Items = res.Items; model.EditUrl = "/PropertyOwners/Property/EditMyRequest"; model.DeleteUrl = "/PropertyOwners/Property/DeleteMyRequest"; TempData["CurrentLink"] = "POMyRequests"; return(View(model)); }
public static SearchResult GetMyRequests(POMyRequestsSearchModel model, Login login) { using (var db = new KeysEntities()) { var data = db.OwnerProperty.Where(x => x.OwnerId == login.Id).SelectMany(x => x.Property.PropertyRequest) .Where(x => x.RequestStatusId != 4 && x.IsActive == true && x.ToTenant && !x.ToOwner) .Select(x => new { Model = new RequestModel { Id = x.Id, PropertyId = x.PropertyId, RequestStatusId = x.RequestStatus.Id, RequestMessage = x.RequestMessage, Reason = x.Reason, IsViewed = x.IsViewed, MediaFiles = x.PropertyRequestMedia.Select(y => new MediaModel { Data = y.NewFileName, Id = y.Id, NewFileName = y.NewFileName, OldFileName = y.OldFileName, Status = "load" }).ToList(), }, RequestType = x.RequestType.Name, RequestStatus = x.RequestStatus.Name, Address = new AddressViewModel { AddressId = x.Property.Address.AddressId, CountryId = x.Property.Address.CountryId, Number = x.Property.Address.Number.Replace(" ", ""), Street = x.Property.Address.Street.Trim(), City = x.Property.Address.City.Trim(), Suburb = x.Property.Address.Suburb.Trim() ?? "", PostCode = x.Property.Address.PostCode.Replace(" ", ""), }, PropertyAddress = x.Property.Address.Number.Replace(" ", "") + " " + x.Property.Address.Street.Trim() + " " + x.Property.Address.City.Trim() + " " + x.Property.Address.Suburb.Trim() + " " + x.Property.Address.PostCode.Replace(" ", ""), CreatedOn = x.CreatedOn, }); if (model.PropertyId.HasValue) { data = data.Where(x => x.Model.PropertyId == model.PropertyId); } if (model.RequestStatus.HasValue) { data = data.Where(x => x.Model.RequestStatusId == (int)model.RequestStatus.Value); } var allItems = data.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10); switch (model.SortOrder) { case "Latest First": data = data.OrderByDescending(s => s.CreatedOn); break; case "Earliest First": data = data.OrderByDescending(s => s.CreatedOn); break; default: data = data.OrderByDescending(s => s.CreatedOn); break; } if (!String.IsNullOrWhiteSpace(model.SearchString)) { SearchUtil searchTool = new SearchUtil(); int searchType = searchTool.CheckDisplayType(model.SearchString); string formatString = searchTool.ConvertString(model.SearchString); switch (searchType) { case 1: data = data.Where(x => x.Model.RequestMessage.ToLower().EndsWith(formatString) || x.PropertyAddress.ToLower().EndsWith(formatString)); break; case 2: data = data.Where(x => x.Model.RequestMessage.ToLower().StartsWith(formatString) || x.PropertyAddress.ToLower().StartsWith(formatString)); break; case 3: data = data.Where(x => x.Model.RequestMessage.ToLower().Contains(formatString) || x.PropertyAddress.ToLower().Contains(formatString)); break; } } var items = data.ToPagedList(model.Page, 10); var count = items.Count; items = count == 0 ? allItems : items; items.ToList().ForEach(x => x.Model.MediaFiles.ForEach(y => y.InjectMediaModelViewProperties())); var result = new SearchResult { SearchCount = count, Items = items }; return(result); } }