コード例 #1
0
        public ICommandResult Handle(RegisterLoanCommand command)
        {
            if (_friendRepository.GetById(command.FriendId) == null)
            {
                AddNotification("Friend", "Não existe amigo com esse identificador!");
            }

            var game = _gameRepository.GetById(command.GameId);

            if (game == null)
            {
                AddNotification("Game", "Não existe jogo com esse identificador!");
            }

            if (game != null && _loanRepository.ThereIsLoan(game.Id))
            {
                AddNotification("Game", "Esse jogo possui empréstimo pendente!");
            }

            if (Invalid)
            {
                return(new CommandResult(false, "Por favor, verifique os itens", Notifications));
            }

            var loan = new Loan(command.UserId, command.GameId, command.FriendId);

            _loanRepository.Add(loan);
            game.NotAvailableLoan();
            _gameRepository.Update(game);

            return(new CommandResult(true, "Empréstimo realizado com sucesso", loan));
        }
コード例 #2
0
ファイル: LoanService.cs プロジェクト: nmotocic/LMS
        public bool CheckOutBook(int bookId, string username)
        {
            //Is the book borrowed?
            if (IsCheckedOut(bookId))
            {
                Console.WriteLine("Book has been borrowed or reserved!");
                return(false);
            }
            //if not...
            var book = _bookRepository.GetByID(bookId);
            var user = _userRepository.GetByUsername(username);

            UpdateBookStatus(bookId, "Unavaliable");


            var now  = DateTime.Now;
            var loan = new Loan
            {
                Id         = RandomNumber(1000, 10000),
                BookId     = bookId,
                CustomerId = user.Id,
                Book       = book,
                User       = user,
                LoanDate   = now,
                ReturnDate = GetDefaultLoanTime(now)
            };

            _loanRepository.Add(loan);

            return(true);
        }
コード例 #3
0
        //Create an item borrow request--Granted
        public bool AddLoan(Loan loan)
        {
            loan.Status = LoanStatus.OnLoan;
            _loanRepository.Add(loan);

            return(SaveRequest() > 0 ? true : false);
        }
コード例 #4
0
        public async Task <bool> Handle(RegisterNewLoanCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }
            else if (!_gameRepository.IsExistGames(request.GamesId))
            {
                await _Bus.RaiseEvent(new DomainNotification(request.MessageType,
                                                             "Could not create loan. Some informed games does not exist"));

                return(false);
            }
            else if ((_loanGameRepository.NotAvailableGames(request.GamesId).Count) != 0)
            {
                await _Bus.RaiseEvent(new DomainNotification(request.MessageType,
                                                             "Could not create loan. Some informed games are borrowed to someone"));

                return(false);
            }
            else
            {
                var newLoan = _Mapper.Map <Loan>(request);

                newLoan.LoanGames = (IList <LoanGame>)
                                    await _gameRepository.GetLoanGamesById(request.GamesId);

                await _loanRepository.Add(newLoan);

                return(Commit());
            }
        }
コード例 #5
0
        public virtual ActionResult CreateLoan(Loan loan)
        {
            loan.IsActive = true;

            _loanRepository.Add(loan);
            _unitOfWork.Commit();

            return(RedirectToAction("Loan"));
        }
コード例 #6
0
        public async Task <CreateLoanResult> Handle(CreateLoanCommand request, CancellationToken cancellationToken)
        {
            var loan = await CreateLoan(request);

            var result = await loanRepository.Add(loan);

            return(new CreateLoanResult {
                LoanId = result.Id
            });
        }
コード例 #7
0
        public void LoanRepository_Add_ShouldBeOk()
        {
            _book.Id = 1;
            _loan    = ObjectMother.GetLoanSQL(_book);

            _expectedLoan = _repository.Add(_loan);

            _expectedLoan.Should().NotBeNull();
            _expectedLoan.Id.Should().Be(2);
        }
コード例 #8
0
        public async Task <ActionResult <Loan> > PostLoan(Loan loan)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _loanRepository.Add(loan);
            var save = await _loanRepository.SaveAsync(loan);

            return(CreatedAtAction("GetLoan", new { id = loan.LoanId }, loan));
        }
コード例 #9
0
 /// <summary>
 /// Add a loan to the system
 /// </summary>
 /// <param name="entity"></param>
 public async Task <int> Add(LoanDTO entity)
 {
     try
     {
         // call repository method to save loan
         var test = _mapper.Map <LoanDTO, Loan>(entity);
         return(await _repository.Add(test));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #10
0
ファイル: CreateLoanHandler.cs プロジェクト: jonakirke94/GTL
        public Task <CommandResponse> Handle(CreateLoanCommand request, CancellationToken cancellationToken)
        {
            var response = new CommandResponse();

            var isCardActive = _loanHelper.IsLoanerCardActive(request.LoanerCardBarcode);

            if (!isCardActive)
            {
                response.ErrorMessage = "The used loanercard is no longer active";
                return(Task.FromResult(response));
            }

            var activeLoans = _loanRepo.GetNoOfActiveLoans(request.LoanerCardBarcode);

            if (activeLoans > 4 || activeLoans < 0)
            {
                response.ErrorMessage = "Member has reached limit of allowed active loans";
                return(Task.FromResult(response));
            }

            var copy = _copyRepo.GetByBarcode(request.CopyBarcode);

            if (copy.Status != CopyStatus.AVAILABLE)
            {
                response.ErrorMessage = $"The requested copy is not available for loaning Status: {copy.Status}";
                return(Task.FromResult(response));
            }

            var loanToAdd = new Loan
            {
                LibraryName       = request.LibraryName,
                CopyBarcode       = request.CopyBarcode,
                LoanerCardBarcode = request.LoanerCardBarcode,
                LoanDate          = DateTime.Now,
                DueDate           = _loanHelper.GetDueDateByMemberType(request.LoanerCardBarcode, request.LibraryName)
            };


            using (var db = _context.CreateUnitOfWork())
            {
                response.SubjectId = _loanRepo.Add(loanToAdd);
                db.SaveChanges();
            }

            return(Task.FromResult(response));
        }
コード例 #11
0
        public void Execute()
        {
            var arguments = new[] { "Id", "Amount", "Term", "Interest rate" };

            IDialog dialog = uiFactory.CreateDialog();
            var     input  = dialog.ShowDialog(arguments).ToArray();

            string  id           = input[0];
            decimal amount       = Decimal.Parse(input[1]);
            int     term         = Int32.Parse(input[2]);
            double  interestRate = Double.Parse(input[3]);

            Loan loan = factory.createLoan(id, amount, term, interestRate);

            loan.AddObserver(uiFactory.CreateLoanView());

            repository.Add(loan);
        }
コード例 #12
0
        public Loan Add(Loan loan, IEnumerable <Guid> books)
        {
            if (LoanValidator(loan))
            {
                return(loan);
            }

            var client = _clientRepository.GetByKey(loan.ClientKey);

            loan.ClientId = client.Id;
            foreach (var bookKey in books)
            {
                var book = _bookRepository.GetByKey(bookKey);
                loan.BookId = book.Id;
                _loanRepository.Add(loan);
            }

            return(loan);
        }
コード例 #13
0
 public Loan Add(Loan loan)
 {
     loan.Validate();
     return(_repository.Add(loan));
 }
コード例 #14
0
 public LoanEntity CreateLoan(LoanEntity loan)
 {
     return(_loanRepository.Add(loan));
 }
コード例 #15
0
 public IActionResult Create(Loan trainee)
 {
     ViewBag.BranchID = db2.GetAll();
     db.Add(trainee);
     return(RedirectToAction("Index"));
 }
コード例 #16
0
        public Task <int?> CreateLoan(Loan loan)
        {
            var loanEntity = _loanMapper.MapToEntity(loan);

            return(_loanRepository.Add(loanEntity));
        }
コード例 #17
0
 public void SaveLoanConfig(LoanConfig config)
 {
     //saving into the database
     _loan.Add(config);
     _loan.Save(config);
 }