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 <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 }); } } }