public WatchlistDisplayModel GetRentalWatchlist(WatchlistDisplayModel model, Login login)
        {
            var data = db.RentalWatchList.Where(x => x.PersonId == login.Id && x.IsActive)
                       .Select(x => new WatctlistItem <RentListingModel>
            {
                View = new RentListingViewModel
                {
                    IsOwner   = db.OwnerProperty.FirstOrDefault(y => y.PropertyId == x.RentalListing.PropertyId).OwnerId == login.Id,
                    IsApplied = db.RentalApplication.Any(y => y.RentalListingId == x.RentalListing.Id && y.PersonId == login.Id),
                },

                Model = new RentListingModel
                {
                    Id             = x.RentalListing.Id,
                    WatchListId    = x.Id,
                    MovingCost     = x.RentalListing.MovingCost,
                    TargetRent     = x.RentalListing.TargetRent,
                    AvailableDate  = x.RentalListing.AvailableDate,
                    Furnishing     = x.RentalListing.Furnishing,
                    OccupantCount  = x.RentalListing.OccupantCount,
                    PetsAllowed    = x.RentalListing.PetsAllowed,
                    Title          = x.RentalListing.Title,
                    Description    = x.RentalListing.Description,
                    PropertyId     = x.RentalListing.PropertyId,
                    IdealTenant    = x.RentalListing.IdealTenant,
                    IsActive       = x.RentalListing.IsActive,
                    RentalStatusId = x.RentalListing.RentalStatusId,
                    MediaFiles     = x.RentalListing.RentalListingMedia.Select(y => new MediaModel {
                        Id = y.Id, NewFileName = y.NewFileName, OldFileName = y.OldFileName
                    }).ToList()
                },
                Address = new AddressViewModel
                {
                    Street    = x.RentalListing.Property.Address.Street,
                    Suburb    = x.RentalListing.Property.Address.Suburb,
                    AddressId = x.RentalListing.Property.Address.AddressId,
                    CountryId = x.RentalListing.Property.Address.AddressId,
                    Number    = x.RentalListing.Property.Address.Number,
                    Region    = x.RentalListing.Property.Address.Region,
                    City      = x.RentalListing.Property.Address.City,
                    PostCode  = x.RentalListing.Property.Address.PostCode,
                    Latitude  = x.RentalListing.Property.Address.Lat,
                    Longitude = x.RentalListing.Property.Address.Lng
                },
                Property = new PropertyViewModel
                {
                    Bedroom           = x.RentalListing.Property.Bedroom,
                    Bathroom          = x.RentalListing.Property.Bathroom,
                    FloorArea         = x.RentalListing.Property.FloorArea,
                    LandArea          = x.RentalListing.Property.LandSqm,
                    ParkingSpace      = x.RentalListing.Property.ParkingSpace,
                    CreatedDate       = x.RentalListing.Property.CreatedOn,
                    PropertyType      = x.RentalListing.Property.PropertyType.Name,
                    RentalPaymentType = x.RentalListing.Property.TargetRentType.Name
                },
            });

            var allItems = data.OrderBy(x => x.Model.Title).ToPagedList(model.Page, 2);

            allItems.ToList().ForEach(x => x.Model.MediaFiles.ToList().ForEach(y => y.InjectMediaModelViewProperties()));

            if (string.IsNullOrWhiteSpace(model.SortOrder))
            {
                model.SortOrder = "Latest Listing";
            }
            switch (model.SortOrder)
            {
            case "Title":
                data = data.OrderBy(x => x.Model.Title);
                break;

            case "Title_Desc":
                data = data.OrderByDescending(x => x.Model.Title);
                break;

            case "Highest Rent":
                data = data.OrderByDescending(x => x.Model.TargetRent);
                break;

            case "Lowest Rent":
                data = data.OrderBy(x => x.Model.TargetRent);
                break;

            case "Latest Avaible":
                data = data.OrderByDescending(x => x.Model.AvailableDate);
                break;

            case "Earliest Avaible":
                data = data.OrderBy(x => x.Model.AvailableDate);
                break;

            case "Latest Listing":
                data = data.OrderByDescending(x => x.Property.CreatedDate);
                break;

            case "Earliest Listing":
                data = data.OrderBy(x => x.Property.CreatedDate);
                break;

            default:
                data = data.OrderByDescending(x => x.Property.CreatedDate);
                break;
            }
            if (!String.IsNullOrWhiteSpace(model.SearchString))
            {
                SearchUtil searchTool   = new SearchUtil();
                int        searchType   = searchTool.CheckDisplayType(model.SearchString);
                string     formatString = searchTool.ConvertString(model.SearchString);
                data = data.Where(x => x.Model.Title.ToLower().Contains(formatString) ||
                                  x.Address.City.ToLower().Contains(formatString) ||
                                  x.Address.Number.ToLower().Contains(formatString) ||
                                  x.Address.PostCode.ToLower().Contains(formatString) ||
                                  x.Address.Region.ToLower().Contains(formatString) ||
                                  x.Address.Street.ToLower().Contains(formatString) ||
                                  x.Address.Suburb.ToLower().Contains(formatString) ||
                                  x.Model.AvailableDate.ToString().Contains(formatString) ||
                                  x.Model.Description.ToLower().Contains(formatString)
                                  );
            }
            ;
            var items = data.ToPagedList(model.Page, 9);

            items.ToList().ForEach(x => x.Model.MediaFiles.ToList().ForEach(y => y.InjectMediaModelViewProperties()));
            if (String.IsNullOrWhiteSpace(model.SearchString))
            {
                model.Page = 1;
            }
            var sortOrders = new List <SortOrderModel>();
            var rvr        = new RouteValueDictionary(new { SearchString = model.SearchString });

            sortOrders.Add(new SortOrderModel {
                SortOrder = "Title", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Title")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Title_Desc", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Title_Desc")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Highest Rent", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Highest Rent")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Lowest Rent", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Lowest Rent")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Latest Available", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Latest Available")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Earliest Available", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Earliest Available")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Latest Listing", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Latest Listing")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Earliest Listing", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Earliest Listing")
            });
            model.SortOrders = sortOrders;
            model.PagedInput = new PagedInput
            {
                ActionName      = "Index",
                ControllerName  = "Watchlist",
                PagedLinkValues = new RouteValueDictionary(new { SortOrder = model.SortOrder, SearchString = model.SearchString })
            };
            model.PageCount   = items.Count == 0 ? allItems.PageCount : items.PageCount;
            model.SearchCount = items.Count;
            model.Items       = items.Count == 0 ? allItems : items;
            return(model);
        }
Ejemplo n.º 2
0
        public ActionResult AcceptedJobs(POJobSearchModel model)
        {
            var login = AccountService.GetLoginByEmail(User.Identity.Name);

            if (String.IsNullOrWhiteSpace(model.SortOrder))
            {
                model.SortOrder = "Latest Date";
            }
            var data = db.Job.Where(x => x.OwnerId == login.Id && x.JobStatusId != 5 && x.JobStatusId != 6 && x.JobStatusId != 1)
                       .Select(x => new
            {
                Model = new JobModel
                {
                    Id             = x.Id,
                    PropertyId     = x.PropertyId,
                    ProviderId     = x.ProviderId,
                    JobStartDate   = x.JobStartDate,
                    JobEndDate     = x.JobEndDate,
                    JobStatusId    = x.JobStatusId,
                    JobRequestId   = x.JobRequestId,
                    PercentDone    = x.PercentDone,
                    Note           = x.Note,
                    JobDescription = x.JobDescription,
                    AcceptedQuote  = x.AcceptedQuote,
                    OwnerUpdate    = x.OwnerUpdate,
                    ServiceUpdate  = x.ServiceUpdate,
                    MediaFiles     = x.JobMedia.Select(y => new MediaModel {
                        Id = y.Id, NewFileName = y.NewFileName, OldFileName = y.OldFileName
                    }).ToList(),
                },
                ProviderCompanyName = x.ServiceProvider.Company.Name,
                JobStatus           = x.ServiceProviderJobStatus.Name,
                CreatedOn           = x.CreatedOn,
                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.Suburb.Trim() ?? "") + " " +
                                  (x.Property.Address.City.Trim() ?? "") + "-" +
                                  (x.Property.Address.PostCode.Replace(" ", "")),
                IsDIY = x.ProviderId == null,
            });
            var allItems = data.OrderBy(x => x.Model.PercentDone).ToPagedList(model.Page, 2);

            allItems.ToList().ForEach(x => x.Model.MediaFiles.ToList().ForEach(y => y.InjectMediaModelViewProperties()));
            switch (model.SortOrder)
            {
            case "Low Progress":
                data = data.OrderBy(x => x.Model.PercentDone);
                break;

            case "High Progress":
                data = data.OrderByDescending(x => x.Model.PercentDone);
                break;

            case "Low Budget":
                data = data.OrderBy(x => x.Model.AcceptedQuote);
                break;

            case "High Budget":
                data = data.OrderByDescending(x => x.Model.AcceptedQuote);
                break;

            case "Earliest Date":
                data = data.OrderBy(x => x.CreatedOn);
                break;

            case "Latest Date":
                data = data.OrderByDescending(s => s.CreatedOn);
                break;

            default:
                data = data.OrderBy(x => x.CreatedOn);
                break;
            }
            if (!String.IsNullOrWhiteSpace(model.SearchString))
            {
                SearchUtil searchTool   = new SearchUtil();
                int        searchType   = searchTool.CheckDisplayType(model.SearchString);
                string     formatString = searchTool.ConvertString(model.SearchString);
                data = data.Where(x => x.PropertyAddress.ToLower().Contains(formatString) ||
                                  x.ProviderCompanyName.ToLower().Contains(formatString) ||
                                  x.Model.AcceptedQuote.ToString().ToLower().Contains(formatString) ||
                                  x.Model.JobDescription.ToLower().Contains(formatString) ||
                                  x.JobStatus.ToLower().Contains(formatString)
                                  );
            }
            ;
            var items = data.ToPagedList(model.Page, 10);

            items.ToList().ForEach(x => x.Model.MediaFiles.ToList().ForEach(y => y.InjectMediaModelViewProperties()));
            if (String.IsNullOrWhiteSpace(model.SearchString))
            {
                model.Page = 1;
            }
            var sortOrders = new List <SortOrderModel>();
            var rvr        = new RouteValueDictionary(new { SearchString = model.SearchString });

            sortOrders.Add(new SortOrderModel {
                SortOrder = "Low Progress", ActionName = "AcceptedJobs", RouteValues = rvr.AddRouteValue("SortOrder", "Low Progress")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "High Progress", ActionName = "AcceptedJobs", RouteValues = rvr.AddRouteValue("SortOrder", "High Progress")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Low Budget", ActionName = "AcceptedJobs", RouteValues = rvr.AddRouteValue("SortOrder", "Low Budget")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "High Budget", ActionName = "AcceptedJobs", RouteValues = rvr.AddRouteValue("SortOrder", "High Budget")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Earliest Date", ActionName = "AcceptedJobs", RouteValues = rvr.AddRouteValue("SortOrder", "Earliest Date")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Latest Date", ActionName = "AcceptedJobs", RouteValues = rvr.AddRouteValue("SortOrder", "Latest Date")
            });
            //sortOrders.Add((SortOrderModel)Activator.CreateInstance(typeof(SortOrderModel), "Latest Date", "AcceptedJobs", rvr.AddRouteValue("SortOrder", "Latest Date")));
            model.SortOrders = sortOrders;
            model.PagedInput = new PagedInput
            {
                ActionName      = "AcceptedJobs",
                ControllerName  = "Manage",
                PagedLinkValues = new RouteValueDictionary(new { SortOrder = model.SortOrder, SearchString = model.SearchString })
            };
            model.PageCount   = items.Count == 0 ? allItems.PageCount: items.PageCount;
            model.SearchCount = items.Count;
            model.Items       = items.Count == 0 ? allItems : items;
            model.EditUrl     = "/Jobs/Home/UpdateJobStatus";
            model.DeleteUrl   = "/Jobs/Home/DeleteJob";
            return(View(model));
        }
        private WatchlistDisplayModel GetMarketJobWatchlist(WatchlistDisplayModel model, Login login)
        {
            var data = db.JobWatchList.Where(x => x.PersonId == login.Id && x.IsActive)
                       .Select(x => new WatctlistItem <JobMarketModel>
            {
                Market = new MarketJobViewModel
                {
                    IsApplyByUser = db.JobQuote.Any(y => y.JobRequestId == x.TenantJobRequest.Id && y.ProviderId == login.Id && y.Status.ToLower() == "opening"),
                    IsOwnedByUser = db.TenantJobRequest.FirstOrDefault(y => y.Id == x.TenantJobRequest.Id).OwnerId == login.Id,
                },
                Model = new JobMarketModel
                {
                    WatchListId    = x.Id,
                    Id             = x.TenantJobRequest.Id,
                    Title          = x.TenantJobRequest.Title,
                    MaxBudget      = x.TenantJobRequest.MaxBudget,
                    JobDescription = x.TenantJobRequest.JobDescription,
                    PostedDate     = x.TenantJobRequest.CreatedOn,
                    MediaFiles     = x.TenantJobRequest.TenantJobRequestMedia.Select(y => new MediaModel {
                        Id = y.Id, NewFileName = y.NewFileName, OldFileName = y.OldFileName
                    }).ToList()
                },
                Address = new AddressViewModel
                {
                    AddressId = x.TenantJobRequest.Property.Address.AddressId,
                    CountryId = x.TenantJobRequest.Property.Address.AddressId,
                    Number    = x.TenantJobRequest.Property.Address.Number,
                    Street    = x.TenantJobRequest.Property.Address.Street,
                    Suburb    = x.TenantJobRequest.Property.Address.Suburb,
                    Region    = x.TenantJobRequest.Property.Address.Region,
                    City      = x.TenantJobRequest.Property.Address.City,
                    PostCode  = x.TenantJobRequest.Property.Address.PostCode,
                    Longitude = x.TenantJobRequest.Property.Address.Lng,
                    Latitude  = x.TenantJobRequest.Property.Address.Lat
                }
            });

            var allItems = data.OrderBy(x => x.Model.Title).ToPagedList(model.Page, 2);

            allItems.ToList().ForEach(x => x.Model.MediaFiles.ToList().ForEach(y => y.InjectMediaModelViewProperties()));

            if (string.IsNullOrWhiteSpace(model.SortOrder))
            {
                model.SortOrder = "Title";
            }
            switch (model.SortOrder)
            {
            case "Title":
                data = data.OrderBy(x => x.Model.Title);
                break;

            case "Title_Desc":
                data = data.OrderByDescending(x => x.Model.Title);
                break;

            case "MaxBudget":
                data = data.OrderBy(x => x.Model.MaxBudget);
                break;

            case "MaxBudget_Desc":
                data = data.OrderByDescending(x => x.Model.MaxBudget);
                break;

            case "Date_Desc":
                data = data.OrderByDescending(x => x.Model.PostedDate);
                break;

            case "Date":
                data = data.OrderBy(x => x.Model.PostedDate);
                break;

            default:
                data = data.OrderByDescending(x => x.Model.Title);
                break;
            }
            if (!String.IsNullOrWhiteSpace(model.SearchString))
            {
                SearchUtil searchTool   = new SearchUtil();
                int        searchType   = searchTool.CheckDisplayType(model.SearchString);
                string     formatString = searchTool.ConvertString(model.SearchString);
                data = data.Where(x => x.Model.Title.ToLower().Contains(formatString)
                                  );
            }
            ;

            var items = data.ToPagedList(model.Page, 9);

            items.ToList().ForEach(x => x.Model.MediaFiles.ToList().ForEach(y => y.InjectMediaModelViewProperties()));
            if (String.IsNullOrWhiteSpace(model.SearchString))
            {
                model.Page = 1;
            }
            var sortOrders = new List <SortOrderModel>();
            var rvr        = new RouteValueDictionary(new { ItemType = "MarketJob", SearchString = model.SearchString });

            sortOrders.Add(new SortOrderModel {
                SortOrder = "Title", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Title")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Title_Desc", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Title_Desc")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "MaxBudget", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "MaxBudget")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "MaxBudget_Desc", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "MaxBudget_Desc")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Date_Desc", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Date_Desc")
            });
            sortOrders.Add(new SortOrderModel {
                SortOrder = "Date", ActionName = "Index", RouteValues = rvr.AddRouteValue("SortOrder", "Date")
            });
            model.SortOrders = sortOrders;
            model.PagedInput = new PagedInput
            {
                ActionName      = "Index",
                ControllerName  = "Watchlist",
                PagedLinkValues = new RouteValueDictionary(new { ItemType = "MarketJob", SortOrder = model.SortOrder, SearchString = model.SearchString })
            };
            model.PageCount   = items.Count == 0 ? allItems.PageCount : items.PageCount;
            model.SearchCount = items.Count;
            model.Items       = items.Count == 0 ? allItems : items;
            return(model);
        }