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 RentalTest() { var profiles = new List <Profile>() { new EntityToViewModelMapping(), new ViewModelToEntityMapping() }; var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfiles(profiles); }); _mapper = mockMapper.CreateMapper(); _rentalMock = new Mock <IRental>(); _gameMock = new Mock <IGame>(); _friendMock = new Mock <IFriend>(); _rentalApplication = new RentalApplication(_rentalMock.Object, _mapper); }
public async Task <bool> Handle(CreateRentalApplicationCommandV2 request, CancellationToken cancellationToken) { //var applicant = new RentalApplicant(request.FirstName, request.LastName, request.ContactTel, request.ContactEmail, // request.ContactSms, request.ContactOthers, request.AnnualIncome, request.NumberOfOccupant, request.WithChildren, request.Status, // request.EmpoyedStatus, request.CreditRating,"equifax", request.ReasonToMove, DateTime.Now, DateTime.Now); //var coApplicant = List <CoApplicant> CoApplicantList = new List <CoApplicant>(); List <ApplicantChild> ChildList = new List <ApplicantChild>(); List <RentalReference> ReferennceList = new List <RentalReference>(); foreach (var coApp in request.CoApplicants) { CoApplicantList.Add(coApp); } foreach (var child in request.ApplicantChildren) { ChildList.Add(child); } foreach (var reference in request.RentalReference) { ReferennceList.Add(reference); } var applicant = new RentalApplicant(request.FirstName, request.LastName, request.ContactTel, request.ContactEmail, request.ContactSms, request.ContactOthers, request.AnnualIncome, request.NumberOfOccupant, request.WithChildren, request.Status, request.CreditRating, request.CreditSource, request.EmpoyedStatus, request.RentalApplicationId, request.ReasonToMove, request.WithCoApplicant, request.WithPets, request.IsSmoking, CoApplicantList, ReferennceList, ChildList, DateTime.Now, DateTime.Now); await _context.AddAsync(applicant); var application = new RentalApplication(request.RentalPropertyId, applicant, request.AppStatus, /*request.NotificaitonType,*/ DateTime.Now, DateTime.Now); await _context.AddAsync(application); application.AddApplicant(applicant); try { await _context.SaveChangesAsync(); // commented out for testing only Log.Information("New Applicatn from {ApplicantName} with Id {ApplicantId} has been created successfully", request.FirstName + " " + request.LastName, applicant.Id); // Sending notification??? by sending integration message to RabbitMQ for notification service to pickup and send notificaiotn string recipient = ""; string subject = "Rental Applicaiton Received"; //string body = "Your application has been successfully submitted!"; // for testing purpose, To be improved //string bodyContent = // "@Dear {name}: " + // "Your application for teancy has been recieved." + // "Please prepare to provide required reference materials for the screening process." + // "Thanks." + // "Property Manager"; //string body = string.Format(bodyContent, request.FirstName + " " + request.LastName); string body = ""; string service = "Marketing Service"; switch (request.NotificationType) { case 1: body = "Dear " + request.FirstName + ": your application has been received. Best regards."; recipient = request.ContactEmail; break; case 2: body = "Dear " + request.FirstName + ": your application has been received. Best regards."; recipient = request.ContactTel; //if (request.ContactSms != null) //{ // recipient = request.ContactSms; //} //else //{ // // throw errror // recipient = request.ContactTel; //} break; default: break; } //EmailNotificationEvent e = new EmailNotificationEvent(new Guid(), recipients, request.NotificaitonType, subject, body, service, DateTime.Now); NotificationEvent e = new NotificationEvent(new Guid(), recipient, request.NotificationType, subject, body, service, DateTime.Now); try { await _messagePublisher.PublishMessageAsync(e.MessageType, e, "notification"); // publishing the message Log.Information("Rental application submissin from {Applicant} has been sent successfully from {service}", request.FirstName + " " + request.LastName, service); } catch (Exception ex) { throw ex; } } catch (Exception ex) { //throw ex; Log.Error(ex, "Error while creating new applicant for {ApplicantName}", request.FirstName + request.LastName); } return(true); //throw new NotImplementedException(); }