Esempio n. 1
0
        public void ReturnBook(ReturnBookDTO dto)
        {
            using (var connection = _dbConnectionFactory.GetConnection())
            {
                var sql = "UPDATE rent_history SET ReturnDate=@returnDate WHERE RentId=@rentId";

                connection.Execute(sql, new { rentId = dto.RentId, returnDate = dto.ReturnDate });
            }
        }
Esempio n. 2
0
        public void ChangeNote(ReturnBookDTO item)
        {
            var note = _libraryWorks.Where(x => x.BookId == item.BookId)
                       .Where(x => x.ClientId == item.ClientId)
                       .Where(x => x.ActualDateReturn == null).First();

            note.ActualDateReturn = item.Date;

            _context.LibraryWorks.Update(note);
            _context.Save();
        }
Esempio n. 3
0
        public async Task <ActionResult <IEnumerable <AddBook> > > Renew(ReturnBookDTO request)
        {
            foreach (var item in request.Id)
            {
                var library_item = await _context.Library.SingleOrDefaultAsync(x => x.Id == item);

                library_item.Renewed = library_item.Renewed + 1;
                await _context.SaveChangesAsync();
            }

            return(CreatedAtAction("GetLibraryBooks", request));
        }
Esempio n. 4
0
        public async Task <ActionResult <IEnumerable <LoanBookDTO> > > ReturnBook(ReturnBookDTO request)
        {
            foreach (var item in request.Id)
            {
                var library_item = await _context.Library.SingleOrDefaultAsync(x => x.Id == item);

                library_item.Return_date = DateTime.UtcNow;
                await _context.SaveChangesAsync();
            }

            return(CreatedAtAction("GetLibraryBooks", request));
        }
Esempio n. 5
0
        public void ReturnBook(ReturnBookDTO dto)
        {
            var sql = "UPDATE rent_history SET ReturnDate=@returnDate WHERE RentId=@rentId";

            _dbHelper.ExecuteNonQuery(sql,
                                      new List <MySqlParameter> {
                new MySqlParameter {
                    ParameterName = "@rentId", MySqlDbType = MySqlDbType.Guid, Value = dto.RentId
                },
                new MySqlParameter {
                    ParameterName = "@dateIssued", MySqlDbType = MySqlDbType.Date, Value = dto.ReturnDate
                }
            }.ToArray());
        }
Esempio n. 6
0
        public async Task <IActionResult> ReturnBook([FromBody] ReturnBookDTO form)
        {
            try
            {
                await libraryRecordFacade.ReturnBookAsync(form);

                Response.StatusCode = (int)HttpStatusCode.OK;
                return(Json(new { responseText = "Your form successfuly sent!" }));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { responseText = ex.Message }));
            }
        }
Esempio n. 7
0
        public IEnumerable <ReturnBookDTO> GetBorrowedBooks()
        {
            List <ReturnBookDTO> returnBookDTOs = new List <ReturnBookDTO>();
            var bookCopies = _BookCopyService.GetBorrowedBooks();

            foreach (var bookCopy in bookCopies)
            {
                var bookInfo  = _BookInfoService.BookInfoOf(bookCopy);
                var lastTrans = _BookTransactionInfoRepository.GetLastBookTransaction(bookCopy.Id);

                //If no borrow transaction was found, then its a possible error.
                if (lastTrans != null)
                {
                    var requiredFee = ComputeNecessaryFee(bookCopy, lastTrans);
                    var user        = _LibraryUserService.FindById(lastTrans.LibraryUserId);

                    var newReturnBookDTO = new ReturnBookDTO();
                    newReturnBookDTO.LibraryUser = user;
                    newReturnBookDTO.BookInfo    = bookInfo;
                    newReturnBookDTO.RequiredFee = requiredFee;
                    newReturnBookDTO.BookCopy    = bookCopy;

                    if (user.LibraryUserType == LibraryUser.UserType.Student)
                    {
                        newReturnBookDTO.TransactionInfo = new JustReturnBookTransaction(bookCopy, lastTrans);
                    }
                    else if (user.LibraryUserType == LibraryUser.UserType.Instructor || user.LibraryUserType == LibraryUser.UserType.Employee)
                    {
                        newReturnBookDTO.TransactionInfo = new ReturnBookIgnorePaymentTransaction(bookCopy, lastTrans);
                    }

                    returnBookDTOs.Add(newReturnBookDTO);
                }
                else
                {
                    Debug.WriteLine("Possible error. A book was borrowed but no transaction info was found.");
                }
            }
            return(returnBookDTOs);
        }
Esempio n. 8
0
 public async Task ReturnBookAsync(ReturnBookDTO returnBookDTO)
 {
     await libraryRecordRepository.ModifyAsync(record => { record.ReturnBook(new BookId(returnBookDTO.bookId), new BookAmount(Convert.ToInt32(returnBookDTO.bookAmount))); }, new LibraryRecordId(returnBookDTO.libraryRecordId));
 }