public static ServiceResponseResult EditMarketJob(MarketJobModel model, Login login, HttpFileCollectionBase files = null) { var result = new ServiceResponseResult { IsSuccess = false }; using (var db = new KeysEntities()) { var files1 = model.MediaFiles; var editMarketJob = db.TenantJobRequest.Where(x => x.Id == model.Id).FirstOrDefault(); if (editMarketJob == null) { var errorMsg = "Cannot locate the Job in the Market Place"; result.ErrorMessage = errorMsg; return(result); } else { editMarketJob.JobDescription = model.JobDescription; editMarketJob.MaxBudget = model.MaxBudget; if (model.FilesRemoved != null) { model.FilesRemoved.ToList().ForEach(x => { var media = db.TenantJobRequestMedia.FirstOrDefault(y => y.Id == x); if (media != null) { db.TenantJobRequestMedia.Remove(media); MediaService.RemoveMediaFile(media.NewFileName); } }); } var fileList = MediaService.SaveFiles(files, 5 - editMarketJob.TenantJobRequestMedia.Count(), AllowedFileType.Images).NewObject as List <MediaModel>; if (fileList != null) { fileList.ForEach(x => editMarketJob.TenantJobRequestMedia.Add(new TenantJobRequestMedia { NewFileName = x.NewFileName, OldFileName = x.OldFileName })); } } try { db.SaveChanges(); return(new ServiceResponseResult { IsSuccess = true }); } catch (Exception) { 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 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 <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 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" }); } } }