public static Login GetExistingTenant(string email) { using (var db = new KeysEntities()) { Login login = db.Login.FirstOrDefault(x => x.Email == email); if (TenantService.IsLoginATenant(login)) { return(login); } return(null); } }
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 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 }); } } }