public ResultDTO CloseLending(string barcode) { int returnTime = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(); Hardbook hardbook = bookRepository.GetHardbook(barcode); BookLending lending = lendingRepository.GetLendingByHardbookId(hardbook.Id); BookReservation reservation = reservationRepository.GetReservationWithId(lending.Id); reservation.Status = "Returned"; hardbook.CanBorrowed = true; lending.ReturnDate = returnTime; bookRepository.UpdateHardbook(hardbook); reservationRepository.UpdateReservations(reservation); lendingRepository.UpdateLending(lending); string message; if (lending.DueDate > returnTime) { message = "Trả đúng hạn"; } else { TimeSpan t = TimeSpan.FromSeconds(returnTime - lending.DueDate); message = "Trả muộn " + t.Days + " ngày, " + t.Hours + " giờ, " + t.Minutes + " phút"; } return(new ResultDTO() { Success = true, Message = message }); }
public void UpdateHardbook(Hardbook hardbook) { try { DbContext.Hardbook.Update(hardbook); DbContext.SaveChanges(); } catch (Exception) { } }
public ResultDTO AssignHardbook(Guid accountId, string barcode) { Hardbook hardbook = bookRepository.GetHardbook(barcode); BookReservation reservation = reservationRepository.ListReservationsByAccountId(accountId).FirstOrDefault(x => x.BookId == hardbook.BookId); hardbook.CanBorrowed = false; reservation.Status = "Borrowing"; reservationRepository.UpdateReservations(reservation); bookRepository.UpdateHardbook(hardbook); lendingRepository.AddLending(new BookLending() { Id = reservation.Id, HardbookId = hardbook.Id, BorrowedDate = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(), DueDate = (int)DateTimeOffset.UtcNow.AddMonths(1).ToUnixTimeSeconds() }); return(new ResultDTO() { Success = true, Message = "" }); }