Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("BookId,LoanId,DeleteFlag,LoanDate,LoanReturnDate")] BookLoan bookLoan)
        {
            int CountOfBooks = context.GetBookById(bookLoan.BookId).BookAmount;

            if (CountOfBooks > 0)
            {
                bookLoan.LoanDate = DateTime.Now;
                if (ModelState.IsValid)
                {
                    context.Create(bookLoan);
                    return(RedirectToAction(nameof(Index)));
                }
                var books = context.GetAllBooks();
                var loans = context.GetAllLoans();
                ViewData["BookId"] = new SelectList(books, "BookId", "BookName", bookLoan.BookId);
                ViewData["LoanId"] = new SelectList(loans, "LoanId", "LoanPFname", bookLoan.LoanId);
                return(View(bookLoan));
            }
            else
            {
                TempData["AmountError"] = "The Amount of this book doesn't allow this operation";
                var books = context.GetAllBooks();
                var loans = context.GetAllLoans();
                ViewData["BookId"] = new SelectList(books, "BookId", "BookName", bookLoan.BookId);
                ViewData["LoanId"] = new SelectList(loans, "LoanId", "LoanPFname", bookLoan.LoanId);
                return(View(bookLoan));
            }
        }
Exemplo n.º 2
0
        public IActionResult Create(LoanModel model)
        {
            try
            {
                LoanSelectLists();
                model.EmployeeId  = GetEmployeeId().Result;
                model.CustomerId  = GetCustomerId(model.CustomerId);
                model.Reference   = _generator.DateCodeString() + _generator.RandomNumber(1111111, 9999999);
                model.DateCreated = DateTime.UtcNow;
                if (ModelState.IsValid)
                {
                    var request = _loanService.Create(model);
                    if (request.Successful)
                    {
                        return(RedirectToAction("Index", "Loans"));
                    }

                    if (request.ResultType == ResultType.PendingTransaction)
                    {
                        TempData["Error"] = "This custormer has a serving loan";
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + " " + ex.InnerException);
            }

            return(View(model));
        }
Exemplo n.º 3
0
        private async Task CreateLoan(Reservation reservation)
        {
            reservation.Reason.Status = ReservationStatus.Approved;
            await reservationRepository.Update(reservation);

            var loan = new Loan(reservation);
            await loanService.Create(loan);
        }
Exemplo n.º 4
0
        public async Task <Guid> Create([FromBody] LoanDTO loan)//לבדוק שהמיפוי אכן עובד ולראות אם לקבל יד
        {
            LoanModel loanModel = _mapper.Map <LoanModel>(loan);
            Guid      loanId    = await _loansService.Create(loanModel);

            CheckLoanValid loanToCheck = new CheckLoanValid();
            LoanDetails    loanDetails = _mapper.Map <LoanDetails>(loanModel);

            loanDetails.LoanId      = loanId;
            loanToCheck.LoanDetails = loanDetails;
            await _messageSession.Send(loanToCheck)
            .ConfigureAwait(false);    //del api

            return(loanId);
        }
Exemplo n.º 5
0
        public LoanViewModel Create(LoanViewModel viewModel)
        {
            Loan createdLoan;

            using (var unitOfWork = _unitOfWorkFactory
                                    .StartUnitOfWork(true))
            {
                try
                {
                    createdLoan = _mapper.Map <Loan>(viewModel);

                    createdLoan.Friend = _findableFriend
                                         .FindById(createdLoan.FriendId);

                    createdLoan.BorrowedGame = _gameService
                                               .FindById(createdLoan.GameId);

                    createdLoan = _loanService
                                  .Create(createdLoan);

                    if (createdLoan == null)
                    {
                        unitOfWork.Rollback();
                        return(null);
                    }

                    unitOfWork.Save();
                    unitOfWork.Commit();
                }
                catch (Exception e)
                {
                    unitOfWork.Rollback();
                    return(null);
                }
            }

            return(_mapper.Map <LoanViewModel>(createdLoan));
        }
Exemplo n.º 6
0
 public async Task CreateLoan(Loan loan)
 {
     await _loanService.Create(loan);
 }
Exemplo n.º 7
0
 public IHttpActionResult Loan(LoanCreate request)
 {
     _loanService.Create(request);
     return(Ok());
 }