public static ServiceResponseResult EditMarketJobQuote(JobQuoteModel quoteModel, Login login, HttpFileCollectionBase files) { var result = new ServiceResponseResult { IsSuccess = false }; using (var db = new KeysEntities()) { var editJobQuote = db.JobQuote.Where(x => x.Id == quoteModel.Id).FirstOrDefault(); editJobQuote.Id = quoteModel.Id; editJobQuote.Note = quoteModel.Note; editJobQuote.UpdatedOn = DateTime.Now; if (quoteModel.FilesRemoved != null) { quoteModel.FilesRemoved.ToList().ForEach(x => { var media = db.JobQuoteMedia.FirstOrDefault(y => y.Id == x); if (media != null) { db.JobQuoteMedia.Remove(media); MediaService.RemoveMediaFile(media.FileName); } }); } var mediaFiles = MediaService.SaveFiles(files, 5 - editJobQuote.JobQuoteMedia.Count, AllowedFileType.AllFiles).NewObject as List <MediaModel>; if (mediaFiles != null) { mediaFiles.ForEach(x => editJobQuote.JobQuoteMedia.Add(new JobQuoteMedia { FileName = x.NewFileName, IsActive = true })); } try { db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } } }
public static ServiceResponseResult EditInspection(InspectionModel model, Login login, HttpFileCollectionBase files) { using (var db = new KeysEntities()) { var editInspection = db.Inspection.Where(x => x.Id == model.Id).First(); if (editInspection != null) { editInspection.IsUpdated = true; editInspection.PercentDone = model.PercentDone; editInspection.Message = model.Message; editInspection.UpdatedBy = login.Id; editInspection.UpdatedOn = DateTime.UtcNow; if (model.FilesRemoved.Count > 0) { foreach (var file in model.FilesRemoved) { var removeFile = db.InspectionMedia.Find(file); db.InspectionMedia.Remove(removeFile); MediaService.RemoveMediaFile(removeFile.NewFileName); } } var fileList = MediaService.SaveFiles(files, 5 - editInspection.InspectionMedia.Count, AllowedFileType.AllFiles).NewObject as List <MediaModel>; if (fileList != null) { fileList.ForEach(x => editInspection.InspectionMedia.Add(new InspectionMedia { NewFileName = x.NewFileName, InspectionId = editInspection.Id, OldFileName = x.OldFileName, IsActive = true })); } } ; try { db.SaveChanges(); var mediaFiles = editInspection.InspectionMedia.Select(x => MediaService.GenerateViewProperties(new MediaModel { NewFileName = x.NewFileName, OldFileName = x.OldFileName })).ToList(); mediaFiles = mediaFiles ?? new List <MediaModel>(); return(new ServiceResponseResult { IsSuccess = true, NewObject = mediaFiles }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = true, ErrorMessage = _error }); } } }
public static ServiceResponseResult AddInspection(InspectionModel model, Login login, HttpFileCollectionBase files) { using (var db = new KeysEntities()) { var request = db.PropertyRequest.Where(x => x.Id == model.RequestId).FirstOrDefault(); if (request.RequestTypeId == 3) { var replyRequest = new Inspection { RequestId = model.RequestId, Message = model.Message, CreatedBy = login.Id, CreatedOn = DateTime.UtcNow, UpdatedBy = login.Id, UpdatedOn = DateTime.UtcNow, IsActive = true, PropertyId = model.PropertyId, StatusId = 1, PercentDone = model.PercentDone, OwnerUpdate = false, IsViewed = false, IsUpdated = false }; db.Inspection.Add(replyRequest); var fileList = MediaService.SaveFiles(files, 5, AllowedFileType.AllFiles).NewObject as List <MediaModel>; if (fileList != null) { fileList.ForEach(x => replyRequest.InspectionMedia.Add(new InspectionMedia { NewFileName = x.NewFileName, InspectionId = replyRequest.Id, OldFileName = x.OldFileName, IsActive = true })); } } request.RequestStatusId = 2; try { db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = true, ErrorMessage = _error }); } } }
public static ServiceResponseResult AddRentallApllication(RentalApplicationModel model, Login login, HttpFileCollectionBase files = null) { using (var db = new KeysEntities()) { var result = new ServiceResponseResult { IsSuccess = false }; if (!TenantService.IsLoginATenant(login)) { var errorMsg = "Account not tenant!"; result.ErrorMessage = errorMsg; return(result); } var rentalApp = new RentalApplication { RentalListingId = model.RentalListingId, PersonId = login.Id, TenantsCount = model.TenantsCount, ApplicationStatusId = 1, Note = model.Note, CreatedBy = login.Email, CreatedOn = DateTime.UtcNow, UpdatedBy = login.Email, UpdatedOn = DateTime.UtcNow, IsActive = true, }; var mediaFiles = MediaService.SaveFiles(files, 5, AllowedFileType.AllFiles).NewObject as List <MediaModel>; mediaFiles.ForEach(x => rentalApp.RentalApplicationMedia.Add(new RentalApplicationMedia { NewFileName = x.NewFileName, OldFileName = x.OldFileName, })); try { db.RentalApplication.Add(rentalApp); db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } } }
public static ServiceResponseResult AddTenantJobRequest(MarketJobModel model, Login login, HttpFileCollectionBase files = null) { using (var db = new KeysEntities()) { try { var request = db.PropertyRequest.Where(x => x.Id == model.RequestId).FirstOrDefault(); if (request == null) { return new ServiceResponseResult { IsSuccess = false, ErrorMessage = "No record found!" } } ; request.RequestStatusId = (int)JobRequestStatus.Accepted; request.IsUpdated = true; //var tenant = TenantService.GetTenantByLoginId(login.Id); var jobRequest = new TenantJobRequest { PropertyId = model.PropertyId, OwnerId = login.Id, JobDescription = model.JobDescription, JobStatusId = 1, //Bug #2031 (Part 3) MaxBudget = model.MaxBudget, CreatedOn = DateTime.UtcNow, CreatedBy = login.Email, UpdatedOn = DateTime.UtcNow, UpdatedBy = login.Email, Title = model.Title }; db.TenantJobRequest.Add(jobRequest); //foreach (int fileId in model.FilesCopy) //{ // var propertyRequestMedia1 = db.PropertyRequestMedia.Where(x => x.Id == fileId).FirstOrDefault(); // var newMarketJob = new TenantJobRequestMedia(); // newMarketJob.TenantJobRequestId = jobRequest.Id; // newMarketJob.NewFileName = propertyRequestMedia1.NewFileName; // newMarketJob.OldFileName = propertyRequestMedia1.OldFileName; // newMarketJob.EntityGuid = new Guid(); // db.TenantJobRequestMedia.Add(newMarketJob); //} var mediaFiles = MediaService.SaveFiles(files, 5, AllowedFileType.Images).NewObject as List <MediaModel>; mediaFiles.ForEach(x => jobRequest.TenantJobRequestMedia.Add(new TenantJobRequestMedia { NewFileName = x.NewFileName, OldFileName = x.OldFileName, })); db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } } }
public static ServiceResponseResult <List <MediaModel> > EditRentalListing(RentListingModel model, HttpFileCollectionBase files, Login user) { using (var db = new KeysEntities()) { var foundProp = db.OwnerProperty.FirstOrDefault(x => x.PropertyId == model.PropertyId && x.OwnerId == user.Id); if (foundProp == null) { return(new ServiceResponseResult <List <MediaModel> > { IsSuccess = false, ErrorMessage = "Can not find property." }); } var oldRentalListing = db.RentalListing.Find(model.Id); oldRentalListing.Description = model.Description; oldRentalListing.Title = model.Title; oldRentalListing.MovingCost = model.MovingCost; oldRentalListing.TargetRent = model.TargetRent; oldRentalListing.AvailableDate = model.AvailableDate; oldRentalListing.Furnishing = model.Furnishing; oldRentalListing.IdealTenant = model.IdealTenant; oldRentalListing.OccupantCount = model.OccupantCount; oldRentalListing.PetsAllowed = model.PetsAllowed; oldRentalListing.UpdatedBy = user.Email; oldRentalListing.UpdatedOn = DateTime.UtcNow; if (model.FilesRemoved != null) { model.FilesRemoved.ToList().ForEach(x => { var media = oldRentalListing.RentalListingMedia.FirstOrDefault(y => y.Id == x); if (media != null) { db.RentalListingMedia.Remove(media); MediaService.RemoveMediaFile(media.NewFileName); } }); } var fileList = MediaService.SaveMediaFiles(files, 5, null).NewObject as List <MediaModel>; if (fileList != null) { fileList.ForEach(x => oldRentalListing.RentalListingMedia.Add(new RentalListingMedia { NewFileName = x.NewFileName, OldFileName = x.OldFileName })); } try { db.SaveChanges(); var medias = oldRentalListing.RentalListingMedia .Select(x => MediaService.GenerateViewProperties(new MediaModel { Id = x.Id, NewFileName = x.NewFileName, OldFileName = x.OldFileName })).ToList(); return(new ServiceResponseResult <List <MediaModel> > { IsSuccess = true, Result = medias }); } catch (Exception ex) { return(new ServiceResponseResult <List <MediaModel> > { IsSuccess = true, ErrorMessage = _error }); } } }
public static ServiceResponseResult EditRentallApllication(RentalApplicationModel model, Login login, HttpFileCollectionBase files = null) { using (var db = new KeysEntities()) { var result = new ServiceResponseResult { IsSuccess = false }; if (!TenantService.IsLoginATenant(login)) { var errorMsg = "Account not tenant!"; result.ErrorMessage = errorMsg; return(result); } var foundRentalApplication = db.RentalApplication.Where(x => x.Id == model.Id).FirstOrDefault(); if (foundRentalApplication == null) { var errorMsg = "Cannot locate the Rental application"; result.ErrorMessage = errorMsg; return(result); } else { foundRentalApplication.RentalListingId = model.RentalListingId; foundRentalApplication.PersonId = login.Id; foundRentalApplication.TenantsCount = model.TenantsCount; foundRentalApplication.Note = model.Note; foundRentalApplication.ApplicationStatusId = 1; foundRentalApplication.CreatedBy = login.Email; foundRentalApplication.CreatedOn = DateTime.UtcNow; foundRentalApplication.UpdatedBy = login.Email; foundRentalApplication.UpdatedOn = DateTime.UtcNow; foundRentalApplication.IsActive = true; model.FilesRemoved.ForEach(x => { var media = db.RentalApplicationMedia.FirstOrDefault(y => y.Id == x); if (media != null) { db.RentalApplicationMedia.Remove(media); MediaService.RemoveMediaFile(media.NewFileName); } }); var mediaFiles = MediaService.SaveFiles(files, 5 - foundRentalApplication.RentalApplicationMedia.Count, AllowedFileType.AllFiles).NewObject as List <MediaModel>; if (mediaFiles != null) { mediaFiles.ForEach(x => foundRentalApplication.RentalApplicationMedia.Add(new RentalApplicationMedia { NewFileName = x.NewFileName, OldFileName = x.OldFileName, })); } }; try { db.SaveChanges(); var mFiles = new List <MediaModel>(); var medias = foundRentalApplication.RentalApplicationMedia .Select(x => MediaService.GenerateViewProperties(new MediaModel { Id = x.Id, NewFileName = x.NewFileName, OldFileName = x.OldFileName })).ToList(); return(new ServiceResponseResult { IsSuccess = true, NewObject = mFiles }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } } }
public static ServiceResponseResult AddJob(JobModel model, HttpFileCollectionBase files, Login login) { var result = new ServiceResponseResult { IsSuccess = false }; using (var db = new KeysEntities()) { var newJob = new Job(); var foundMarketJob = db.TenantJobRequest.Where(x => x.Id == model.Id).First(); if (foundMarketJob == null) { var errorMsg = "Cannot locate the Job in the Market Place"; result.ErrorMessage = errorMsg; return(result); } else { foundMarketJob.JobStatusId = 3; newJob.JobDescription = model.JobDescription; newJob.PropertyId = model.PropertyId; newJob.JobStatusId = 2; // should be pending newJob.CreatedBy = login.Email; newJob.CreatedOn = DateTime.UtcNow; newJob.UpdatedOn = DateTime.UtcNow; newJob.UpdatedBy = login.Email; newJob.PaymentAmount = 0; newJob.OwnerId = login.Id; newJob.JobRequestId = model.Id; newJob.PaymentAmount = 0; db.Job.Add(newJob); }; var mediaFiles = MediaService.SaveFiles(files, 5, AllowedFileType.AllFiles).NewObject as List <MediaModel>; mediaFiles.ForEach(x => { newJob.JobMedia.Add(new JobMedia { NewFileName = x.NewFileName, OldFileName = x.OldFileName }); }); try { db.SaveChanges(); //var jobRequestMedia = db.TenantJobRequestMedia.Where(x => x.TenantJobRequestId == model.Id).ToList(); //foreach (var mediaFile in jobRequestMedia) //{ // var newJobMedia = new JobMedia(); // newJobMedia.JobId = newJob.Id; // newJobMedia.NewFileName = mediaFile.NewFileName; // newJobMedia.OldFileName = mediaFile.OldFileName; // newJobMedia.PropertyId = model.PropertyId; // newJobMedia.IsActive = true; // db.JobMedia.Add(newJobMedia); // db.SaveChanges(); //} return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } } }
public static ServiceResponseResult AddJobQuote(QuoteModel model, Login login, HttpFileCollectionBase files = null) { using (var db = new KeysEntities()) { var _currentJobId = model.JobRequestId; var _currentJobMaxBudget = db.TenantJobRequest.SingleOrDefault(j => j.Id == _currentJobId).MaxBudget; if (_currentJobMaxBudget != null && _currentJobMaxBudget < model.Amount) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = "Sorry, you quote is larger than Max Budget of this Job." }); } if (model.Id == -1) { var jobQuote = new JobQuote(); var mf = MediaService.SaveMediaFiles(files, 5); if (mf.IsSuccess) { var mediaFiles = mf.NewObject as List <MediaModel>; if (mediaFiles != null) { mediaFiles.ForEach(x => jobQuote.JobQuoteMedia.Add(new JobQuoteMedia { FileName = x.NewFileName, IsActive = true })); } } // Bug Fix #2031 jobQuote.JobRequestId = model.JobRequestId; jobQuote.ProviderId = login.Id; jobQuote.Status = "opening".ToLower(); jobQuote.Amount = model.Amount; jobQuote.CreatedBy = login.Email; jobQuote.UpdatedBy = login.Email; jobQuote.CreatedOn = DateTime.UtcNow; jobQuote.UpdatedOn = DateTime.UtcNow; jobQuote.Note = model.Note; jobQuote.IsViewed = false; db.JobQuote.Add(jobQuote); } else { var jobQuote = db.JobQuote.Find(model.Id); var marketJob = db.TenantJobRequest.Find(model.JobRequestId); if (jobQuote != null && marketJob != null) { jobQuote.Amount = model.Amount; jobQuote.UpdatedBy = login.Email; jobQuote.UpdatedOn = DateTime.UtcNow; } } try { db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } } }
public static ServiceResponseResult AddNewCompany(CompanyViewModel model, Login login, HttpFileCollectionBase files) { using (var db = new KeysEntities()) { var foundSp = db.ServiceProvider.FirstOrDefault(x => x.Id == login.Id); if (foundSp == null) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = "Can not find account!" }); } var physicalAddress = new Address { CountryId = 1, CreatedBy = login.Email, CreatedOn = DateTime.Now, UpdatedBy = login.Email, UpdatedOn = DateTime.Now, Number = model.PhysicalAddress.Number, Street = model.PhysicalAddress.Street, City = model.PhysicalAddress.City, Suburb = model.PhysicalAddress.Suburb, PostCode = model.PhysicalAddress.PostCode, Lat = model.PhysicalAddress.Latitude, Lng = model.PhysicalAddress.Longitude, IsActive = true }; try { db.Address.Add(physicalAddress); db.SaveChanges(); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } var serviceProvider = new Company { IsActive = true, Name = model.Name, Website = model.Website, PhoneNumber = model.PhoneNumber, UpdatedBy = login.Email, CreatedOn = DateTime.Now, CreatedBy = login.Email, UpdatedOn = DateTime.Now, PhysicalAddressId = physicalAddress.AddressId, }; if (model.IsShipSame) { serviceProvider.BillingAddressId = physicalAddress.AddressId; } else { var billingAddress = new Address { CountryId = 1, CreatedBy = login.Email, CreatedOn = DateTime.Now, UpdatedBy = login.Email, UpdatedOn = DateTime.Now, Number = model.BillingAddress.Number, Street = model.BillingAddress.Street, City = model.BillingAddress.City, Suburb = model.BillingAddress.Suburb, PostCode = model.BillingAddress.PostCode, Lat = model.PhysicalAddress.Latitude, Lng = model.PhysicalAddress.Longitude, IsActive = true }; try { db.Address.Add(billingAddress); db.SaveChanges(); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } serviceProvider.BillingAddressId = billingAddress.AddressId; } var saveResult = MediaService.SaveMediaFiles(files, 1); if (saveResult.IsSuccess) { var newOb = saveResult.NewObject as List <MediaModel>; serviceProvider.ProfilePhoto = newOb.FirstOrDefault().NewFileName; } foundSp.Company = serviceProvider; try { db.Company.Add(serviceProvider); foundSp.Company = serviceProvider; foundSp.IsProfileComplete = true; db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = false, ErrorMessage = _error }); } } }
public static ServiceResponseResult EditProperty(PropertyModel model, HttpFileCollectionBase files, Login user) { //List<String> dlist = new List<String>(); using (var db = new KeysEntities()) { var property = db.Property.Where(p => p.Id == model.Id).First(); property.Name = model.Name; property.Description = model.Description; property.Bedroom = model.Bedroom; property.Bathroom = model.Bathroom; property.FloorArea = model.FloorArea; property.LandSqm = model.LandSqm; property.ParkingSpace = model.ParkingSpace; property.PropertyTypeId = model.PropertyTypeId; property.IsActive = true; property.YearBuilt = model.YearBuilt; property.TargetRent = model.TargetRent; property.Address.Number = model.Address.Number.Replace(" ", ""); property.Address.Street = model.Address.Street.Trim(); property.Address.City = model.Address.City.Trim(); property.Address.Suburb = model.Address.Suburb; property.Address.PostCode = model.Address.PostCode.Replace(" ", ""); property.IsOwnerOccupied = model.IsOwnerOccupied; property.TargetRent = model.TargetRent; property.UpdatedBy = user.Email; property.UpdatedOn = DateTime.UtcNow; property.TargetRentTypeId = model.TargetRentTypeId; if (model.FilesRemoved != null) { model.FilesRemoved.ToList().ForEach(x => { var media = property.PropertyMedia.FirstOrDefault(y => y.Id == x); if (media != null) { db.PropertyMedia.Remove(media); MediaService.RemoveMediaFile(media.NewFileName); } }); } var fileList = MediaService.SaveFiles(files, 5 - property.PropertyMedia.Count(), AllowedFileType.Images).NewObject as List <MediaModel>; if (fileList != null) { fileList.ForEach(x => property.PropertyMedia.Add(new PropertyMedia { NewFileName = x.NewFileName, OldFileName = x.OldFileName })); } try { db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception ex) { return(new ServiceResponseResult { IsSuccess = true, ErrorMessage = "error" }); } } }
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 }); } }