Beispiel #1
0
        public static SearchResult GetAllInspections(TenantInspectionSearchModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var props = db.TenantProperty.Where(x => x.TenantId == login.Id && (x.IsActive ?? true)).Select(x => x.PropertyId);
                var data  = db.Inspection.Where(x => props.Contains(x.PropertyId))
                            .Select(x => new TenantInsPectionViewModel
                {
                    Model = new InspectionModel {
                        Id          = x.Id,
                        Message     = x.Message,
                        StatusId    = x.StatusId,
                        IsViewed    = x.IsViewed ?? false,
                        PercentDone = x.PercentDone,
                        OwnerUpdate = x.OwnerUpdate ?? false,
                        Reason      = x.Reason,
                        MediaFiles  = x.InspectionMedia.Select(y => new MediaModel {
                            Id = y.Id, NewFileName = y.NewFileName, OldFileName = y.OldFileName
                        }).ToList()
                    },
                    CreatedOn     = x.CreatedOn,
                    Status        = x.InspectionStatus.Name,
                    DueDate       = x.PropertyRequest.DueDate,
                    LandlordName  = x.Property.OwnerProperty.FirstOrDefault().Person.FirstName + " " + x.Property.OwnerProperty.FirstOrDefault().Person.LastName,
                    LandlordPhone = x.Property.OwnerProperty.FirstOrDefault().Person.Login.PhoneNumber,
                    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(" ", ""),
                    },
                });
                var allItems = data.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10);
                switch (model.SortOrder)
                {
                case "Latest First":
                    data = data.OrderByDescending(x => x.CreatedOn);
                    break;

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

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

                case "Low Progress":
                    data = data.OrderBy(x => x.Model.PercentDone);
                    break;

                default:
                    data = data.OrderByDescending(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);
                    switch (searchType)
                    {
                    case 1:
                        data = data.Where(x => x.Model.Message.ToLower().EndsWith(formatString) ||
                                          x.Status.ToLower().EndsWith(formatString) ||
                                          x.Model.Reason.ToLower().EndsWith(formatString));
                        break;

                    case 2:
                        data = data.Where(x => x.Model.Message.ToLower().StartsWith(formatString) ||
                                          x.Status.ToLower().StartsWith(formatString) ||
                                          x.Model.Reason.ToLower().StartsWith(formatString));
                        break;

                    case 3:
                        data = data.Where(x => x.Model.Message.ToLower().Contains(formatString) ||
                                          x.Status.ToLower().StartsWith(formatString) ||
                                          x.Model.Reason.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.CanBeEdited = x.DueDate != null ? DateTime.UtcNow > x.DueDate : true;
                    x.Model.MediaFiles.ForEach(y => y.InjectMediaModelViewProperties());
                });
                var result = new SearchResult {
                    SearchCount = items.Count, Items = count == 0 ? allItems : items
                };
                return(result);
            }
        }
Beispiel #2
0
        public static SearchResult GetAllRequests(MyRequestSearchModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var data = db.TenantProperty.Where(x => x.TenantId == login.Id).SelectMany(x => x.Property.PropertyRequest)
                           .Where(x => x.RequestStatusId != 4 && x.IsActive == true && x.ToOwner && x.CreatedBy == login.Id)
                           .Select(x => new MyRequestViewModel
                {
                    Model = new RequestModel {
                        Id              = x.Id,
                        PropertyId      = x.PropertyId,
                        RequestMessage  = x.RequestMessage,
                        IsUpdated       = x.IsUpdated ?? false,
                        RequestStatusId = x.RequestStatusId,
                        MediaFiles      = x.PropertyRequestMedia.Select(y => new MediaModel
                        {
                            Data        = y.NewFileName,
                            Id          = y.Id,
                            NewFileName = y.NewFileName,
                            OldFileName = y.OldFileName,
                            Status      = "load"
                        }).ToList()
                    },
                    PropertyAddress       = x.Property.Address.Number + " " + x.Property.Address.Street + ", " + x.Property.Address.Suburb + ", " + x.Property.Address.City + " - " + x.Property.Address.PostCode,
                    LandlordName          = x.Property.OwnerProperty.FirstOrDefault().Person.FirstName + " " + x.Property.OwnerProperty.FirstOrDefault().Person.LastName,
                    LandlordContactNumber = x.Property.OwnerProperty.FirstOrDefault().Person.Login.PhoneNumber ?? "Not Available",
                    RequestType           = x.RequestType.Name,
                    RequestStatus         = (x.IsViewed && !x.RequestStatusId.Equals((int)JobRequestStatus.Accepted)) ? " Viewed by Owner Decision Pending" : x.RequestStatus.Name,
                    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 Request":
                    data = data.OrderByDescending(s => s.CreatedOn);
                    break;

                case "Earliest Request":
                    data = data.OrderBy(s => s.CreatedOn);
                    break;

                case "Requested Type":
                    data = data.OrderBy(s => s.RequestType);
                    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.AsEnumerable().Where(x => x.Model.RequestMessage.ToLower().EndsWith(formatString) ||
                                                         x.RequestStatus.ToLower().EndsWith(formatString) ||
                                                         x.LandlordName.ToLower().EndsWith(formatString) ||
                                                         x.LandlordContactNumber.ToLower().EndsWith(formatString) ||
                                                         x.RequestType.ToLower().EndsWith(formatString)).AsQueryable();
                        break;

                    case 2:
                        data = data.AsEnumerable().Where(x => x.Model.RequestMessage.ToLower().StartsWith(formatString) ||
                                                         x.RequestStatus.ToLower().StartsWith(formatString) ||
                                                         x.LandlordName.ToLower().StartsWith(formatString) ||
                                                         x.LandlordContactNumber.ToLower().StartsWith(formatString) ||
                                                         x.RequestType.ToLower().StartsWith(formatString)).AsQueryable();
                        break;

                    case 3:
                        data = data.AsEnumerable().Where(x => x.Model.RequestMessage.ToLower().Contains(formatString) ||
                                                         x.RequestStatus.ToLower().Contains(formatString) ||
                                                         x.LandlordName.ToLower().Contains(formatString) ||
                                                         x.LandlordContactNumber.ToLower().Contains(formatString) ||
                                                         x.RequestType.ToLower().Contains(formatString)).AsQueryable();
                        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);
            }
        }
Beispiel #3
0
        public static SearchResult GetLandlordRequests(Login login, LandlordRequestsSearchModel model)
        {
            using (var db = new KeysEntities())
            {
                var props = db.TenantProperty.Where(x => x.TenantId == login.Id && (x.IsActive ?? true));
                if (model.PropId.HasValue)
                {
                    props = props.Where(x => x.PropertyId == model.PropId);
                }
                var propIds   = props.Select(x => x.PropertyId);
                var landLords = db.OwnerProperty.Where(x => propIds.Contains(x.PropertyId))
                                .Select(x => x.Person).GroupBy(x => x.Id).Select(g => g.FirstOrDefault());
                var reqs = db.Property.Where(x => propIds.Contains(x.Id)).SelectMany(x => x.PropertyRequest).Where(y => (y.IsActive && y.ToTenant && !y.ToOwner));
                var data = from req in reqs
                           join per in landLords on req.CreatedBy equals per.Id
                           select new MyRequestViewModel
                {
                    Model = new RequestModel {
                        RecipientId     = req.RecipientId,
                        Id              = req.Id,
                        PropertyId      = req.PropertyId,
                        RequestMessage  = req.RequestMessage,
                        RequestTypeId   = req.RequestTypeId,
                        RequestStatusId = req.RequestStatusId,
                        DueDate         = req.DueDate,
                        MediaFiles      = req.PropertyRequestMedia.Select(x => new MediaModel
                        {
                            Id          = x.Id,
                            NewFileName = x.NewFileName,
                            OldFileName = x.OldFileName,
                            Status      = "load",
                        }).ToList(),
                    },
                    RequestType           = req.RequestType.Name,
                    RequestStatus         = req.RequestStatus.Name,
                    LandlordName          = per.FirstName + " " + per.LastName,
                    LandlordContactNumber = per.Login.PhoneNumber,
                    CreatedOn             = req.CreatedOn,
                    Address = new AddressViewModel
                    {
                        AddressId = req.Property.Address.AddressId,
                        CountryId = req.Property.Address.CountryId,
                        Number    = req.Property.Address.Number.Replace(" ", ""),
                        Street    = req.Property.Address.Street.Trim(),
                        City      = req.Property.Address.City.Trim(),
                        Suburb    = req.Property.Address.Suburb.Trim() ?? "",
                        PostCode  = req.Property.Address.PostCode.Replace(" ", ""),
                    }
                };
                if (login != null)
                {
                    data = data.Where(x => x.Model.RecipientId == login.Id);
                }
                if (model.PropId.HasValue)
                {
                    data = data.Where(x => x.Model.PropertyId == model.PropId);
                }
                if (model.RequestStatus.HasValue)
                {
                    data = data.Where(x => x.Model.RequestStatusId == (int)model.RequestStatus.Value);
                }
                var allItems = data.OrderByDescending(s => s.CreatedOn).ToPagedList(model.Page, 10);

                switch (model.SortOrder)
                {
                case "Latest First":
                    data = data.OrderByDescending(s => s.CreatedOn);
                    break;

                case "Earliest First":
                    data = data.OrderBy(s => s.CreatedOn);
                    break;

                default:
                    data = data.OrderByDescending(s => s.RequestStatus);
                    break;
                }
                if (!String.IsNullOrWhiteSpace(model.SearchString))
                {
                    var    searchTool   = new SearchUtil();
                    string formatString = searchTool.ConvertString(model.SearchString);
                    data = data.Where(x => x.Model.RequestMessage.ToLower().Contains(formatString) ||
                                      x.RequestStatus.ToLower().Contains(formatString) ||
                                      x.LandlordName.ToLower().Contains(formatString) ||
                                      x.RequestType.ToLower().Contains(formatString));
                }
                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);
            }
        }
Beispiel #4
0
        public static SearchResult GetJobs(SSMyJobsSearchModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var data = db.Job.Where(x => (x.JobStatusId == 2 || x.JobStatusId == 3 || x.JobStatusId == 4) && x.ProviderId == login.Id)
                           .Select(x => new JobViewModel
                {
                    Model = new JobModel
                    {
                        Id             = x.Id,
                        PropertyId     = x.PropertyId,
                        ProviderId     = x.ProviderId,
                        OwnerId        = x.OwnerId,
                        JobStatusId    = x.JobStatusId,
                        JobRequestId   = x.JobRequestId,
                        JobStartDate   = x.JobStartDate,
                        JobEndDate     = x.JobEndDate,
                        JobDescription = x.JobDescription,
                        Note           = x.Note,
                        AcceptedQuote  = x.AcceptedQuote,
                        PercentDone    = x.PercentDone,
                        OwnerUpdate    = x.OwnerUpdate ?? false,
                        ServiceUpdate  = x.ServiceUpdate ?? false,
                        MediaFiles     = x.JobMedia.Select(y => new MediaModel {
                            Id = y.Id, NewFileName = y.NewFileName, OldFileName = y.OldFileName, Status = "load"
                        }).ToList(),
                    },
                    CreatedOn       = x.CreatedOn,
                    JobStatusName   = x.ServiceProviderJobStatus.Name,
                    ProviderName    = x.ServiceProvider.Person.FirstName + " " + x.ServiceProvider.Person.LastName,
                    ProviderCompany = x.ServiceProvider.Company.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 + " " + x.Property.Address.Street + " " + x.Property.Address.Suburb + " " + x.Property.Address.City + " " + x.Property.Address.PostCode,
                });
                var allItems = data.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10);
                switch (model.SortOrder)
                {
                case "Lowest Progress":
                    data = data.OrderBy(s => s.Model.PercentDone);
                    break;

                case "Highest Progress":
                    data = data.OrderByDescending(s => s.Model.PercentDone);
                    break;

                case "Highest Accepted Quote":
                    data = data.OrderByDescending(s => s.Model.AcceptedQuote);
                    break;

                case "Lowest Accepted Quote":
                    data = data.OrderBy(s => s.Model.AcceptedQuote);
                    break;

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

                case "Earliest Jobs":
                    data = data.OrderBy(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(job => job.PropertyName.ToLower().StartsWith(formatString) ||
                                          job.PropertyAddress.ToLower().StartsWith(formatString) ||
                                          job.ProviderName.ToLower().StartsWith(formatString) ||
                                          job.Model.AcceptedQuote.ToString().ToLower().StartsWith(formatString) ||
                                          job.Model.JobDescription.ToLower().StartsWith(formatString) ||
                                          job.JobStatusName.ToLower().StartsWith(formatString));
                        break;

                    case 2:
                        data = data.Where(job => job.PropertyName.ToLower().EndsWith(formatString) ||
                                          job.PropertyAddress.ToLower().EndsWith(formatString) ||
                                          job.ProviderName.ToLower().EndsWith(formatString) ||
                                          job.Model.AcceptedQuote.ToString().ToLower().EndsWith(formatString) ||
                                          job.Model.JobDescription.ToLower().EndsWith(formatString) ||
                                          job.JobStatusName.ToLower().EndsWith(formatString));
                        break;

                    case 3:
                        data = data.Where(job => job.PropertyName.ToLower().Contains(formatString) ||
                                          job.PropertyAddress.ToLower().Contains(formatString) ||
                                          job.ProviderName.ToLower().Contains(formatString) ||
                                          job.Model.AcceptedQuote.ToString().ToLower().Contains(formatString) ||
                                          job.Model.JobDescription.ToLower().Contains(formatString) ||
                                          job.JobStatusName.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 = items.Count, Items = count == 0 ? allItems : items
                };
                return(result);
            }
        }
Beispiel #5
0
        public static SearchResult GetAllRentApplications(RentalAppSearchModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var data = db.RentalApplication.Where(x => x.PersonId == login.Id && x.IsActive == true)
                           .Select(x => new
                {
                    Model = new RentalApplicationModel
                    {
                        Id = x.Id,
                        RentalListingId = x.RentalListingId,
                        PersonId        = x.PersonId,
                        Note            = x.Note,
                        TenantsCount    = x.TenantsCount,
                        IsViewedByOwner = x.IsViewedByOwner ?? false,
                        MediaFiles      = x.RentalApplicationMedia.Select(y => new MediaModel {
                            Id          = y.Id,
                            Status      = "load",
                            NewFileName = y.NewFileName,
                            OldFileName = y.OldFileName
                        }).ToList()
                    },
                    CreatedOn = x.CreatedOn,
                    Status    = new {
                        Id     = x.RentalApplicationStatus.Id,
                        Status = x.RentalApplicationStatus.Status,
                    },

                    RentalListing = new RentListingModel {
                        Title         = x.RentalListing.Title,
                        Description   = x.RentalListing.Description,
                        MovingCost    = x.RentalListing.MovingCost,
                        TargetRent    = x.RentalListing.TargetRent,
                        AvailableDate = x.RentalListing.AvailableDate,
                        Furnishing    = x.RentalListing.Furnishing,
                        IdealTenant   = x.RentalListing.IdealTenant,
                        OccupantCount = x.RentalListing.OccupantCount,
                        PetsAllowed   = x.RentalListing.PetsAllowed,
                    },
                    RentalPaymentType = x.RentalListing.Property.TargetRentType.Name,
                    Bedrooms          = x.RentalListing.Property.Bedroom ?? 0,
                    Bathrooms         = x.RentalListing.Property.Bathroom ?? 0,
                    ParkingSpaces     = x.RentalListing.Property.ParkingSpace ?? 0,
                    LandSqm           = x.RentalListing.Property.LandSqm ?? 0,
                    FloorArea         = x.RentalListing.Property.FloorArea ?? 0,
                    PropertyType      = x.RentalListing.Property.TargetRentType.Name,
                    AddressString     = x.RentalListing.Property.Address.Number + " " + x.RentalListing.Property.Address.Street + ", " + x.RentalListing.Property.Address.Suburb + ", " + x.RentalListing.Property.Address.City + " - " + x.RentalListing.Property.Address.PostCode,
                    Address           = new AddressViewModel
                    {
                        AddressId = x.RentalListing.Property.Address.AddressId,
                        CountryId = x.RentalListing.Property.Address.CountryId,
                        Number    = x.RentalListing.Property.Address.Number.Replace(" ", ""),
                        Street    = x.RentalListing.Property.Address.Street.Trim(),
                        City      = x.RentalListing.Property.Address.City.Trim(),
                        Suburb    = x.RentalListing.Property.Address.Suburb.Trim() ?? "",
                        PostCode  = x.RentalListing.Property.Address.PostCode.Replace(" ", ""),
                    },
                });
                var allItems = data.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10);
                switch (model.SortOrder)
                {
                case "Lowest Rent":
                    data = data.OrderBy(x => x.RentalListing.TargetRent);
                    break;

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

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

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

                case "Earliest Available":
                    data = data.OrderBy(x => x.RentalListing.AvailableDate);
                    break;

                case "Latest Available":
                    data = data.OrderByDescending(x => x.RentalListing.AvailableDate);
                    break;

                case "Accepted First":
                    data = data.OrderBy(x => x.Status.Status);
                    break;

                default:
                    data = data.OrderByDescending(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.AsEnumerable().Where(x => (x.AddressString?.ToLower().Contains(formatString) ?? false) ||
                                                     (x.Model.Note?.ToLower().Contains(formatString) ?? false) ||
                                                     x.RentalListing.AvailableDate.Value.ToString("MMMM d yyyy").ToLower().Contains(formatString.Replace(",", "")) ||
                                                     x.RentalListing.AvailableDate.Value.ToString("d MMMM yyyy").ToLower().Contains(formatString.Replace(",", "")) ||
                                                     x.RentalListing.AvailableDate.Value.ToString("MMM d yyyy").ToLower().Contains(formatString.Replace(",", "")) ||
                                                     x.RentalListing.AvailableDate.Value.ToString("d MMM yyyy").ToLower().Contains(formatString.Replace(",", "")) ||
                                                     (x.Status.Status ?? "").ToLower().Contains(formatString)).AsQueryable();
                }
                ;
                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()); });
                return(new SearchResult {
                    SearchCount = count, Items = items
                });
            }
        }
Beispiel #6
0
        public static SearchResult GetJobQuotes(QuotesSearchViewModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var data = db.JobQuote.Where(x => x.ProviderId == login.Id)
                           .Select(q => new
                {
                    Model = new JobQuoteModel {
                        Id           = q.Id,
                        Amount       = q.Amount,
                        Note         = q.Note,
                        JobRequestId = q.JobRequestId,
                        MediaFiles   = q.JobQuoteMedia.Select(y => new MediaModel {
                            Id = y.Id, OldFileName = y.FileName.Substring(36), NewFileName = y.FileName
                        }).ToList(),
                    },
                    JobDescription  = q.TenantJobRequest.JobDescription,
                    CreatedOn       = q.CreatedOn,
                    PropertyAddress = q.TenantJobRequest.Property.Address.Number + " " + q.TenantJobRequest.Property.Address.Street + ", " + q.TenantJobRequest.Property.Address.Suburb + ", " + q.TenantJobRequest.Property.Address.City + " - " + q.TenantJobRequest.Property.Address.PostCode,
                    Address         = new AddressViewModel
                    {
                        AddressId = q.TenantJobRequest.Property.Address.AddressId,
                        CountryId = q.TenantJobRequest.Property.Address.CountryId,
                        Number    = q.TenantJobRequest.Property.Address.Number.Replace(" ", ""),
                        Street    = q.TenantJobRequest.Property.Address.Street.Trim(),
                        City      = q.TenantJobRequest.Property.Address.City.Trim(),
                        Suburb    = q.TenantJobRequest.Property.Address.Suburb.Trim() ?? "",
                        PostCode  = q.TenantJobRequest.Property.Address.PostCode.Replace(" ", "")
                    },
                    Status = q.Status
                });
                if (!String.IsNullOrWhiteSpace(model.Status))
                {
                    data = data.Where(x => x.Status.ToLower() == model.Status);
                }
                var allItems = data.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10);
                switch (model.SortOrder)
                {
                case "Lowest Amount":
                    data = data.OrderBy(s => s.Model.Amount);
                    break;

                case "Highest Amount":
                    data = data.OrderByDescending(s => s.Model.Amount);
                    break;

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

                case "Earliest Date":
                    data = data.OrderBy(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);
                    decimal    number;
                    var        canParse = Decimal.TryParse(formatString, out number);
                    switch (searchType)
                    {
                    case 1:
                        data = data.Where(x => x.PropertyAddress.ToLower().EndsWith(formatString) || (x.Status ?? "").ToLower().EndsWith(formatString));
                        if (canParse)
                        {
                            data = data.Where(x => x.Model.Amount.Equals(number));
                        }
                        break;

                    case 2:
                        data = data.Where(x => x.PropertyAddress.ToLower() == formatString || (x.Status ?? "").ToLower().StartsWith(formatString));
                        if (canParse)
                        {
                            data = data.Where(x => x.Model.Amount.Equals(number));
                        }
                        break;

                    case 3:

                        data = data.Where(x => x.PropertyAddress.ToLower().Contains(formatString) || (x.Status ?? "").ToLower().Contains(formatString));
                        if (canParse)
                        {
                            data = data.Where(x => x.Model.Amount.Equals(number));
                        }
                        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 = items.Count, Items = count == 0 ? allItems : items
                };
                return(result);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        public static SearchResult GetTenantRequests(POTenantRequestSearchModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var props   = db.OwnerProperty.Where(x => x.OwnerId == login.Id && x.Property.IsActive);
                var propsId = props.Select(x => x.Property.Id);
                var reqs    = props.Select(x => x.Property)
                              .SelectMany(x => x.PropertyRequest.Where(y => y.ToOwner && !y.ToTenant && y.IsActive));
                var tents = db.TenantProperty.Where(x => propsId.Contains(x.PropertyId)).Select(x => x.Tenant).GroupBy(x => x.Id).Select(g => g.FirstOrDefault());
                var data  = from req in reqs
                            join ten in tents on req.CreatedBy equals ten.Id
                            select new TenantRequestViewModel
                {
                    Model = new RequestModel
                    {
                        Id              = req.Id,
                        PropertyId      = req.PropertyId,
                        RequestTypeId   = req.RequestTypeId,
                        RequestMessage  = req.RequestMessage,
                        IsViewed        = req.IsViewed,
                        RequestStatusId = req.RequestStatusId,
                        MediaFiles      = req.PropertyRequestMedia.Select(y => new MediaModel
                        {
                            Data        = y.NewFileName,
                            Id          = y.Id,
                            NewFileName = y.NewFileName,
                            OldFileName = y.OldFileName,
                            Status      = "load"
                        }).ToList()
                    },
                    RequestType   = req.RequestType.Name,
                    RequestStatus = req.RequestStatus.Name,
                    TenantId      = ten.Id,
                    CreatedOn     = req.CreatedOn,
                    Address       = new AddressViewModel
                    {
                        AddressId = req.Property.Address.AddressId,
                        CountryId = req.Property.Address.CountryId,
                        Number    = req.Property.Address.Number.Replace(" ", ""),
                        Street    = req.Property.Address.Street.Trim(),
                        City      = req.Property.Address.City.Trim(),
                        Suburb    = req.Property.Address.Suburb.Trim() ?? "",
                        PostCode  = req.Property.Address.PostCode.Replace(" ", "")
                    },
                    TenantName        = (ten.Person.FirstName ?? "") + " " + (ten.Person.LastName ?? ""),
                    TenantPhoneNumber = ten.MobilePhoneNumber,
                    TenantProfileFoto = ten.Person.ProfilePhoto,
                };
                if (model.RequestStatus.HasValue)
                {
                    var status = (int)model.RequestStatus.Value;
                    data = data.Where(x => x.Model.RequestStatusId == status);
                }
                var allItems = data.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10);
                switch (model.SortOrder)
                {
                case "Earliest Date":
                    data = data.OrderBy(s => s.CreatedOn);
                    break;

                case "Latest Date":
                    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);

                    data = data.AsEnumerable().Where(x => x.Model.RequestMessage.ToLower().Contains(formatString) ||
                                                     x.CreatedOn.ToString("MMMM d yyyy").ToLower().Contains(formatString.Replace(",", "")) ||
                                                     (x.RequestStatus ?? "").ToLower().Contains(formatString)).AsQueryable();
                }
                ;
                var items = data.ToPagedList(model.Page, 10);
                var count = items.Count;
                items = count == 0 ? allItems : items;
                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                items.ToList().ForEach(x =>
                {
                    x.Model.MediaFiles.ForEach(y => y.InjectMediaModelViewProperties());
                    x.TenantProfileFoto = urlHelper.Content(MediaService.GetContentPath(x.TenantProfileFoto));
                });
                return(new SearchResult {
                    SearchCount = count, Items = items
                });
            }
        }
Beispiel #9
0
        public static SearchResult GetAllRentalProperties(RentalListingSearchModel model)
        {
            using (var db = new KeysEntities())
            {
                var data = db.RentalListing.Where(x => x.IsActive == true)
                           .Select(x => new RentListingViewModel
                {
                    Model = new RentListingModel
                    {
                        Id            = x.Id,
                        PropertyId    = x.PropertyId,
                        Title         = x.Title,
                        Description   = x.Description.Trim(),
                        MovingCost    = x.MovingCost ?? 0,
                        TargetRent    = x.TargetRent,
                        AvailableDate = x.AvailableDate,
                        Furnishing    = x.Furnishing,
                        IdealTenant   = x.IdealTenant,
                        OccupantCount = x.OccupantCount ?? 0,
                        PetsAllowed   = x.PetsAllowed,
                        MediaFiles    = x.RentalListingMedia.Select(y => new MediaModel
                        {
                            Id          = y.Id,
                            Status      = "load",
                            NewFileName = y.NewFileName,
                            OldFileName = y.OldFileName
                        }).ToList(),
                    },
                    IsOwner       = db.OwnerProperty.FirstOrDefault(y => y.PropertyId == x.PropertyId).OwnerId == model.UserId,
                    IsApplied     = db.RentalApplication.Any(y => y.RentalListingId == x.Id && y.PersonId == model.UserId),
                    Bedrooms      = x.Property.Bedroom ?? 0,
                    Bathrooms     = x.Property.Bathroom ?? 0,
                    ParkingSpaces = x.Property.ParkingSpace ?? 0,
                    LandSqm       = x.Property.LandSqm ?? 0,
                    FloorArea     = x.Property.FloorArea ?? 0,
                    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(" ", ""),
                        Latitude  = x.Property.Address.Lat,
                        Longitude = x.Property.Address.Lng,
                    },
                    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(" ", "")),
                    PropertyType      = x.Property.PropertyType.Name,
                    RentalPaymentType = x.Property.TargetRentType.Name,
                    Latitude          = x.Property.Address.Lat,
                    Longitude         = x.Property.Address.Lng,
                });

                var allItems = data.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10);
                switch (model.SortOrder)
                {
                case "Title":
                    data = data.OrderBy(s => s.Model.Title);
                    break;

                case "Title(Desc)":
                    data = data.OrderByDescending(s => s.Model.Title);
                    break;

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

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

                case "Latest Available Date":
                    data = data.OrderByDescending(s => s.Model.AvailableDate);
                    break;

                case "Earliest Available Date":
                    data = data.OrderBy(s => s.Model.AvailableDate);
                    break;

                case "Earliest Listing":
                    data = data.OrderBy(s => s.CreatedOn);
                    break;

                case "Latest Listing":
                    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.AsEnumerable().Where(r => r.Model.Title.ToLower().EndsWith(formatString) ||
                                                         r.PropertyAddress.ToLower().EndsWith(formatString) ||
                                                         ("$" + r.Model.TargetRent.ToString()).EndsWith(formatString) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("MMMM d yyyy").ToLower().EndsWith(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("d MMMM yyyy").ToLower().EndsWith(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("MMM d yyyy").ToLower().EndsWith(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("d MMM yyyy").ToLower().EndsWith(formatString.Replace(",", "")))).AsQueryable();
                        break;

                    case 2:
                        data = data.AsEnumerable().Where(r => r.Model.Title.ToLower().StartsWith(formatString) ||
                                                         r.PropertyAddress.ToLower().StartsWith(formatString) ||
                                                         ("$" + r.Model.TargetRent.ToString()).StartsWith(formatString) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("MMMM d yyyy").ToLower().StartsWith(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("d MMMM yyyy").ToLower().StartsWith(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("MMM d yyyy").ToLower().StartsWith(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("d MMM yyyy").ToLower().StartsWith(formatString.Replace(",", "")))).AsQueryable();
                        break;

                    case 3:
                        data = data.AsEnumerable().Where(r => r.Model.Title.ToLower().Contains(formatString) ||
                                                         r.PropertyAddress.ToLower().Contains(formatString) ||
                                                         ("$" + r.Model.TargetRent.ToString()).Contains(formatString) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("MMMM d yyyy").ToLower().Contains(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("d MMMM yyyy").ToLower().Contains(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("MMM d yyyy").ToLower().Contains(formatString.Replace(",", ""))) ||
                                                         (r.Model.AvailableDate != null && r.Model.AvailableDate.Value.ToString("d MMM yyyy").ToLower().Contains(formatString.Replace(",", "")))).AsQueryable();
                        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());
                    x.IsInWatchlist = db.RentalWatchList.FirstOrDefault(y => y.PersonId == model.UserId && y.RentalListingId == x.Model.Id && y.IsActive) != null;
                });

                var result = new SearchResult {
                    SearchCount = items.Count, Items = count == 0 ? allItems : items
                };
                return(result);
            }
        }
Beispiel #10
0
        public static SearchResult GetAllMarketJobs(MarketJobSearchModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var data               = db.TenantJobRequest.Where(x => x.JobStatusId == 1);
                var ownerJobRequests   = data.Where(x => x.OwnerId == login.Id);
                var ownerJobRequestsId = ownerJobRequests.Select(x => x.Id);
                if (model.IsOwnerView)
                {
                    data = ownerJobRequests;
                }
                var result = data.Select(x => new MarketJobViewModel
                {
                    Model = new MarketJobModel
                    {
                        Id             = x.Id,
                        PropertyId     = x.PropertyId,
                        Title          = x.Title,
                        JobDescription = x.JobDescription,
                        MaxBudget      = x.MaxBudget,
                        MediaFiles     = x.TenantJobRequestMedia.Select(y => new MediaModel
                        {
                            Data        = y.NewFileName,
                            Id          = y.Id,
                            NewFileName = y.NewFileName,
                            OldFileName = y.OldFileName,
                            Status      = "load",
                        }).ToList()
                    },
                    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(" ", ""),
                        Latitude  = x.Property.Address.Lat,
                        Longitude = x.Property.Address.Lng
                    },
                    PropertyAddress = x.Property.Address.Number + " " + x.Property.Address.Street + ", " + x.Property.Address.Suburb + ", " + x.Property.Address.City,
                    IsOwnedByUser   = model.IsOwnerView ? model.IsOwnerView : x.OwnerId == login.Id,
                    IsApplyByUser   = db.JobQuote.Any(y => y.JobRequestId == x.Id && y.ProviderId == login.Id && y.Status.ToLower() == "opening"),
                    NewQuotesCount  = x.JobQuote.Where(y => y.Status.ToLower() == "opening" && !(y.IsViewed ?? false)).Count(),
                    CreatedOn       = x.CreatedOn,
                });
                var allItems = model.IsOwnerView ? result.OrderByDescending(x => x.NewQuotesCount).ToPagedList(model.Page, 10)
                    : result.OrderByDescending(x => x.CreatedOn).ToPagedList(model.Page, 10);
                switch (model.SortOrder)
                {
                case "Title":
                    result = result.OrderBy(s => s.Model.Title);
                    break;

                case "Title(Desc)":
                    result = result.OrderByDescending(s => s.Model.Title);
                    break;

                case "Highest Budget":
                    result = result.OrderByDescending(s => s.Model.MaxBudget);
                    break;

                case "Lowest Budget":
                    result = result.OrderBy(s => s.Model.MaxBudget);
                    break;

                case "Earliest Listing":
                    result = result.OrderBy(s => s.CreatedOn);
                    break;

                case "Latest Listing":
                    result = result.OrderByDescending(s => s.CreatedOn);
                    break;

                case "Highest New Quotes":
                    result = result.OrderByDescending(x => x.NewQuotesCount);
                    break;

                case "Lowest New Quotes":
                    result = result.OrderBy(x => x.NewQuotesCount);
                    break;

                default:
                    result = model.IsOwnerView? result.OrderByDescending(x => x.NewQuotesCount) : result.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:
                        result = result.Where(job => job.Model.MaxBudget.ToString() == formatString ||
                                              job.PropertyAddress.ToLower().EndsWith(formatString) ||
                                              (job.Model.Title ?? "").ToLower().EndsWith(formatString) ||
                                              job.Model.JobDescription.ToLower().EndsWith(formatString));
                        break;

                    case 2:

                        result = result.Where(job => job.Model.MaxBudget.ToString() == formatString ||
                                              job.PropertyAddress.ToLower().StartsWith(formatString) ||
                                              (job.Model.Title ?? "").ToLower().StartsWith(formatString) ||
                                              job.Model.JobDescription.ToLower().StartsWith(formatString));
                        break;

                    case 3:
                        result = result.Where(job => job.Model.MaxBudget.ToString() == formatString ||
                                              job.PropertyAddress.ToLower().Contains(formatString) ||
                                              (job.Model.Title ?? "").ToLower().Contains(formatString) ||
                                              job.Model.JobDescription.ToLower().Contains(formatString));
                        break;
                    }
                }
                var items = result.ToPagedList(model.Page, 10);
                var count = items.Count;
                items = count == 0 ? allItems : items;
                items.ToList().ForEach(x => {
                    x.Model.MediaFiles.ForEach(y => y.InjectMediaModelViewProperties());
                    x.IsInWatchlist = db.JobWatchList.FirstOrDefault(y => y.PersonId == login.Id & y.MarketJobId == x.Model.Id && y.IsActive) != null;
                });
                var searchResult = new SearchResult {
                    SearchCount = items.Count, Items = count == 0 ? allItems : items
                };
                return(searchResult);
            }
        }