public async Task <IActionResult> Create(BorrowerModel borrower) { if (ModelState.IsValid) { try { _context.Add(borrower); await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest(new { error = "There was an error creating this borrower" })); } } return(Ok(borrower)); }
public async Task <IActionResult> Create(NoteModel property) { if (ModelState.IsValid) { try { _context.Add(property); await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest(new { error = "There was an error creating this property" })); } } return(Ok(property)); }
public async Task <IActionResult> Create(TrusteeModel trustee) { if (ModelState.IsValid) { try { _context.Add(trustee); await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest(new { error = "There was an error creating this trustee" })); } } return(Ok(trustee)); }
public async Task <IActionResult> Create(FinanceChargeModel finCharge) { if (ModelState.IsValid) { try { _context.Add(finCharge); await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest(new { error = "There was an error creating this financecharge" })); } } return(Ok(finCharge)); }
public async Task <IActionResult> Create(BrokerServicingModel brokerservicing) { if (ModelState.IsValid) { try { _context.Add(brokerservicing); await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest(new { error = "There was an error creating this brokerservicing" })); } } return(Ok(brokerservicing)); }
public async Task <IActionResult> Create(EscrowModel escrow) { if (ModelState.IsValid) { try { _context.Add(escrow); await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest(new { error = "There was an error creating this deduction" })); } } return(Ok(escrow)); }
public async Task <IActionResult> Create([Bind("Username,FName,LName,IsAdmin,Password")] UserModel user) { // Validate password format and length if (user.Password.Length < minimumPasswordLength) { return(BadRequest(new { error = "Password must be at least 6 characters long" })); } if (ModelState.IsValid) { try { _context.Add(user); await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest(new { error = "There was an error creating your account. Please contact support." })); } return(RedirectToAction(nameof(Index))); } return(Ok(user)); }
public async Task <Response> Handle(PayLoanCommand request, CancellationToken cancellationToken) { var loan = await _context.Loans.Where(l => l.Id == request.LoanId).FirstOrDefaultAsync(); if (loan == null) { return(new Response().AddError($"Loan with Id {request.LoanId} doesnt exist")); } if (loan.IsPaid) { return(new Response().AddError($"Loan with Id {request.LoanId} has been already paid")); } loan.IsPaid = true; await _context.SaveChangesAsync(); return(new Response()); }
public async Task <Response> Handle(CreateUserCommand request, CancellationToken cancellationToken) { User user = await _context.Users.Where(d => string.Equals(d.EmailAddress, request.EmailAddress, StringComparison.OrdinalIgnoreCase)) .FirstOrDefaultAsync(); if (user != null) { return(new Response().AddError($"Email {request.EmailAddress} already exists")); } user = new User(); user.EmailAddress = request.EmailAddress; user.FirstName = request.FirstName; user.IsBorrower = request.IsBorrower; user.IsLender = request.IsLender; user.LastName = request.LastName; _context.Users.Add(user); await _context.SaveChangesAsync(); return(new Response()); }
public async Task <Response> Handle(AddLoanCommand request, CancellationToken cancellationToken) { if (request.LenderId == request.BorrowerId) { return(new Response().AddError("Borrower and Lender Id must not be the same")); } var loanType = await _context.LoanTypes.Where(l => l.Id == request.LoanTypeId).FirstOrDefaultAsync(); if (loanType == null) { return(new Response().AddError("Loan type doesnt exists")); } var lender = await _context.Users.Where(l => l.Id == request.LenderId && l.IsLender).FirstOrDefaultAsync(); if (lender == null) { return(new Response().AddError($"User with Id {request.LenderId} doesnt exist")); } var borrower = await _context.Users.Where(b => b.Id == request.BorrowerId && b.IsBorrower).FirstOrDefaultAsync(); if (borrower == null) { return(new Response().AddError($"User with Id {request.BorrowerId} doesnt exist")); } var loan = new Loan(); loan.Borrower = borrower; loan.IsPaid = false; loan.Lender = lender; loan.LoanType = loanType; loan.LoanValue = request.LoanValue; _context.Loans.Add(loan); await _context.SaveChangesAsync(cancellationToken); return(new Response()); }