예제 #1
0
        public async Task PutBookBorrow()
        {
            int    BookBorrowId = 200;
            string newComment   = "Returned";

            var updatedBookBorrow = new BookBorrow
            {
                IdUser       = 200,
                IdBookBorrow = BookBorrowId,
                IdBook       = 201,
                BorrowDate   = new DateTime(2020, 3, 19),
                ReturnDate   = new DateTime(2020, 4, 3),
                Comments     = newComment
            };
            var httpResponse = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{BookBorrowId}", new StringContent(
                                                          JsonConvert.SerializeObject(updatedBookBorrow),
                                                          Encoding.UTF8,
                                                          "application/json"
                                                          ));

            httpResponse.EnsureSuccessStatusCode();


            using (var scope = _server.Host.Services.CreateScope())
            {
                var _db = scope.ServiceProvider.GetRequiredService <LibraryContext>();
                Assert.True(_db.BookBorrow.Any(e => e.IdBookBorrow == 200 && e.Comments == newComment));
            }
        }
        public async Task EditBookBorrow_200Ok()
        {
            var editBookBorrow = new BookBorrow()
            {
                IdBookBorrow = 1,
                IdUser       = 2,
                IdBook       = 2,
                Comments     = "działaZedytowane"
            };



            var serializedBookBorrow = JsonConvert.SerializeObject(editBookBorrow);

            var payload = new StringContent(serializedBookBorrow, Encoding.UTF8, "application/json");

            var postResponses = await _client.PutAsync($"{ _client.BaseAddress.AbsoluteUri}api/book-borrows/{1}", payload);

            postResponses.EnsureSuccessStatusCode();



            var httpResponse = await _client.GetAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{1}");

            httpResponse.EnsureSuccessStatusCode();
            var content = await httpResponse.Content.ReadAsStringAsync();

            var bookBorrow = JsonConvert.DeserializeObject <BookBorrow>(content);

            Assert.True(bookBorrow.Comments == "działaZedytowane");
        }
        public async Task PostBookBorrow()
        {
            var newBookBorrow = new BookBorrow
            {
                IdUser       = 1,
                IdBookBorrow = 33,
                IdBook       = 333,
                BorrowDate   = new DateTime(2019, 1, 1),
                ReturnDate   = new DateTime(2020, 2, 2),
                Comments     = "ASNDKWQOJRJOP!JO@JOP"
            };

            var httpResponse = await _client.PostAsync(
                $"{_client.BaseAddress.AbsoluteUri}api/book-borrows",
                new StringContent(
                    JsonConvert.SerializeObject(newBookBorrow),
                    Encoding.UTF8,
                    "application/json"
                    )
                );

            httpResponse.EnsureSuccessStatusCode();
            var content = await httpResponse.Content.ReadAsStringAsync();

            var postBookBorrow = JsonConvert.DeserializeObject <BookBorrow>(content);

            Assert.True(postBookBorrow.IdBook == 333 && postBookBorrow.IdUser == 1);
        }
        public async Task PutBookBorrow()
        {
            int    IdBookBorrow  = 42;
            string commentToTest = "New Changed Comment";

            var updatedBookBorrow = new BookBorrow
            {
                IdUser       = 1,
                IdBookBorrow = IdBookBorrow,
                IdBook       = 666,
                BorrowDate   = new DateTime(2019, 1, 1),
                ReturnDate   = new DateTime(2020, 2, 2),
                Comments     = commentToTest
            };

            var httpResponse = await _client.PutAsync(
                $"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{IdBookBorrow}",
                new StringContent(
                    JsonConvert.SerializeObject(updatedBookBorrow),
                    Encoding.UTF8,
                    "application/json"
                    )
                );

            httpResponse.EnsureSuccessStatusCode();

            using (var scope = _server.Host.Services.CreateScope())
            {
                var _db = scope.ServiceProvider.GetRequiredService <LibraryContext>();

                Assert.True(_db.BookBorrow.Any(bb => bb.IdBookBorrow == 42 && bb.Comments == commentToTest));
            }
        }
예제 #5
0
        public IActionResult OnPost(int id)
        {
            var book = this.Context
                       .Books
                       .Include(x => x.Borrowers)
                       .FirstOrDefault(x => x.Id == id);

            var borrower = this.Context
                           .Borrowers
                           .Include(x => x.BorrowedBooks)
                           .FirstOrDefault(x => x.Id == this.BorrowerId);

            if (book.IsBorrowed || (this.EndDate != null && this.StartDate >= this.EndDate))
            {
                return(RedirectToPage(IndexPage));
            }

            book.IsBorrowed = true;
            book.Status     = BorrowedStatus;

            var bookBorrow = new BookBorrow()
            {
                BookId     = book.Id,
                BorrowerId = borrower.Id,
                StartDate  = this.StartDate,
                EndDate    = this.EndDate
            };

            this.Context.BookBorrows.Add(bookBorrow);

            this.Context.SaveChanges();

            return(RedirectToPage(IndexPage));
        }
예제 #6
0
        public async Task PostBookBorrow()
        {
            var newBorrow = new BookBorrow
            {
                IdUser     = 11,
                IdBook     = 2,
                BorrowDate = DateTime.Now,
                ReturnDate = DateTime.Now.AddDays(1),
                Comments   = "Borrowed"
            };
            var httpResponse = await _client.PostAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows",
                                                       new StringContent(
                                                           JsonConvert.SerializeObject(newBorrow),
                                                           Encoding.UTF8,
                                                           "application/json"
                                                           ));

            httpResponse.EnsureSuccessStatusCode();

            var content = await httpResponse.Content.ReadAsStringAsync();

            var bookBorrow = JsonConvert.DeserializeObject <BookBorrow>(content);

            Assert.True(bookBorrow.IdBook == 2);
        }
예제 #7
0
        public async Task <bool> Testfor_Validate_InvlidBookBorrow()
        {
            //Arrange
            bool res        = false;
            var  bookBorrow = new BookBorrow
            {
                BorrowId = 1,
                FromDate = DateTime.Now,
                Todate   = DateTime.Now
            };

            bookBorrow = null;
            //Act
            service.Setup(repo => repo.BorrowBook(_library.BookId, bookBorrow)).ReturnsAsync(bookBorrow = null);
            var result = await _SchoolServices.BorrowBook(_library.BookId, bookBorrow);

            if (result == null)
            {
                res = true;
            }
            //Asert
            //final result displaying in text file
            await File.AppendAllTextAsync("../../../../output_exception_revised.txt", "Testfor_Validate_InvlidBookBorrow=" + res + "\n");

            return(res);
        }
예제 #8
0
        public async Task PutBookBorrow_200()
        {
            string newComment    = "returned";
            int    idBookToCheck = 132;

            var changedBookBorrowed = new BookBorrow
            {
                IdBookBorrow = idBookToCheck,
                IdBook       = 21,
                IdUser       = 1,
                BorrowDate   = new DateTime(2020, 03, 19),
                ReturnDate   = new DateTime(2020, 04, 02),
                Comments     = newComment
            };


            var httpResponse = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{idBookToCheck}",
                                                      new StringContent(JsonConvert.SerializeObject(changedBookBorrowed),
                                                                        Encoding.UTF8, "application/json"
                                                                        ));

            httpResponse.EnsureSuccessStatusCode();

            using (var scope = _server.Host.Services.CreateScope())
            {
                var _db = scope.ServiceProvider.GetRequiredService <LibraryContext>();
                Assert.True(_db.BookBorrow.Any(e => e.IdBookBorrow == 132 && e.Comments == newComment));
            }
        }
예제 #9
0
        public async Task PostBookBorrow_200()
        {
            var newBookBorrowed = new BookBorrow
            {
                IdBookBorrow = 125,
                IdBook       = 122,
                IdUser       = 1,
                BorrowDate   = new DateTime(2020, 03, 19),
                ReturnDate   = new DateTime(2020, 04, 02),
                Comments     = "borrowed"
            };



            var httpResponse = await _client.PostAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows",
                                                       new StringContent(JsonConvert.SerializeObject(newBookBorrowed),
                                                                         Encoding.UTF8, "application/json"
                                                                         ));

            httpResponse.EnsureSuccessStatusCode();
            var content = await httpResponse.Content.ReadAsStringAsync();

            var borrows = JsonConvert.DeserializeObject <BookBorrow>(content);

            Assert.True(borrows.IdBook == 122);
        }
예제 #10
0
        public async Task <Operate> BorrowBook(long bookId, long userId, DateTime planReturnDate)
        {
            var result = new Operate();

            try
            {
                //if this book has been borrowed
                var bookEntity = await bookInfoAgent.GetById(bookId);

                if (bookEntity.Status == (int)Enums.BookStatus.Borrowed)
                {
                    result.Status  = -1;
                    result.Message = "This book has been borrowed";
                    return(result);
                }

                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    //update status of book info
                    bookEntity.Status = (int)Enums.BookStatus.Borrowed;
                    await bookInfoAgent.AddOrUpdate(bookEntity);

                    /* book borrow
                     * 1. if current user has been borrowed this book, only change status and book borrow date
                     * 2. if current user is first to borrow this book, create new data
                     */
                    var now = DateTime.Now;
                    var bookBorrowEntity = await bookBorrowAgent.GetbyBookIdAndUserId(bookId, userId);

                    if (bookBorrowEntity != null)
                    {
                        bookBorrowEntity.Status         = (int)Enums.BookStatus.Borrowed;
                        bookBorrowEntity.BorrowDate     = now;
                        bookBorrowEntity.PlanReturnDate = planReturnDate;
                        await bookBorrowAgent.AddOrUpdate(bookBorrowEntity);
                    }
                    else
                    {
                        var bookBorrowModel = new BookBorrow
                        {
                            BookId         = bookId,
                            BorrowUserId   = userId,
                            Status         = (int)Enums.BookStatus.Borrowed,
                            BorrowDate     = now,
                            PlanReturnDate = planReturnDate
                        };
                        await bookBorrowAgent.AddOrUpdate(bookBorrowModel);
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Status  = -1;
                result.Message = ex.Message;
                Logger.WriteErrorLog(ex);
            }
            return(result);
        }
예제 #11
0
 /// <summary>
 /// Borrow a book from libray, this methos place a borrow request
 /// </summary>
 /// <param name="BookId"></param>
 /// <param name="bookBorrow"></param>
 /// <returns></returns>
 public async Task <BookBorrow> BorrowBook(int BookId, BookBorrow bookBorrow)
 {
     if (bookBorrow.BookId == BookId)
     {
         _schoolDbContext.BookBorrows.Add(bookBorrow);
         await _schoolDbContext.SaveChangesAsync();
     }
     return(bookBorrow);
 }
        // GET: BookBorrow/Details/5
        public ActionResult Details(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Status = "Yes";
            }
            BookBorrow borrow = _context.Borrow.Find(id);

            return(View(borrow));
        }
        public BookBorrowDetailsForm(string bookBorrowId)
        {
            InitializeComponent();
            var context = new LibraryContext();

            _bookBorrowsRepository = new BookBorrowsRepository(context);

            _bookBorrow = _bookBorrowsRepository.GetBookBorrowById(int.Parse(bookBorrowId));

            FillDetails();
        }
 public ExceptionalTest()
 {
     //Creating New mock Object with value.
     _SchoolServices = new SchoolServices(service.Object);
     _ASServices     = new AdminSchoolServices(Adminservice.Object);
     _notice         = new Notice
     {
         NoticeId   = "5f1025b2587fb74450a61c78",
         Name       = "26 January",
         NoticeDate = new DateTime(2021, 1, 26),
         classList  = ClassList.FIVE,
         Event      = "Republic Day",
         ChiefGuest = "Donald Trump",
         Remarks    = "Happy republic day! Wishing you India, you have a great future and enjoy your everlasting independence. Today we are free because of the hardships faced by our freedom fighters. Let us salute them."
     };
     _student = new Student
     {
         StudentId  = "5f71d29f0341602be6be445f",
         Name       = "Uma Kumar",
         DOB        = new DateTime(1990, 03, 01),
         Phone      = 9631438113,
         FatherName = "Gopal PD Singh",
         classList  = ClassList.TEN,
         Section    = "A"
     };
     _library = new Library
     {
         BookId      = "5f0ec59dce04c32fb4d3160a",
         BookName    = "Deploying And Devloping .Net core",
         Publication = "Microsoft-Press",
         Writer      = "Tim Cook",
         Stock       = 10
     };
     _teacher = new Teacher
     {
         TeacherId   = "5f0ec59dce04c32fb4d3160a",
         Name        = "Santosh Kumar",
         Address     = "South Block 9/11, New Delhi-09",
         Email       = "*****@*****.**",
         PhoneNumber = 9635244510,
         Subject     = "Hindi, Sience, SST",
         Experience  = 6,
         Remark      = ""
     };
     _bookBorrow = new BookBorrow
     {
         //BorrowId = "5f0ec59dce04c32fb4d3160a",
         FromDate = DateTime.Now,
         Todate   = DateTime.Now
     };
 }
예제 #15
0
        public static BookBorrowModel ToModel(this BookBorrow entity)
        {
            var model = new BookBorrowModel()
            {
                Id         = entity.Id,
                BookId     = entity.BookId,
                UserId     = entity.UserId,
                Status     = entity.Status.HasValue ? (UserBorrowStatus)entity.Status.Value : UserBorrowStatus.None,
                BorrowDate = entity.BorrowDate,
                ReturnDate = entity.ReturnDate
            };

            return(model);
        }
예제 #16
0
        public static BookBorrow ToEntity(this BookBorrowModel model)
        {
            var entity = new BookBorrow()
            {
                Id         = model.Id,
                BookId     = model.BookId,
                UserId     = model.UserId,
                Status     = (int)model.Status,
                BorrowDate = model.BorrowDate,
                ReturnDate = model.ReturnDate
            };

            return(entity);
        }
예제 #17
0
        public async Task PutBookBorrow_200Ok()
        {
            var newBorrow = new BookBorrow
            {
                IdUser   = 1,
                IdBook   = 1,
                Comments = "Wypozyczona dla Daniela"
            };
            var serializedBookBorrow = JsonConvert.SerializeObject(newBorrow);
            var payload = new StringContent(serializedBookBorrow, Encoding.UTF8, "application/json");

            var httpResponse = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/1", payload);

            httpResponse.EnsureSuccessStatusCode();
        }
예제 #18
0
        public async Task UpdateBookBorrow_204NoContent()
        {
            //Arrange i Act
            var newBookBorrow = new BookBorrow
            {
                IdUser   = 1,
                IdBook   = 1,
                Comments = "Completelynothing"
            };

            HttpContent c            = new StringContent(JsonConvert.SerializeObject(newBookBorrow), Encoding.UTF8, "application/json");
            var         httpResponse = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/1", c);

            httpResponse.EnsureSuccessStatusCode();
        }
예제 #19
0
        public async Task <Operate> AddOrUpdate(BookBorrow entity)
        {
            var result = new Operate();

            try
            {
                await bookBorrowAgent.AddOrUpdate(entity);
            }
            catch (Exception ex)
            {
                result.Status  = -1;
                result.Message = ex.Message;
                Logger.WriteErrorLog(ex);
            }
            return(result);
        }
예제 #20
0
        public IActionResult OnPost(int id)
        {
            if (string.IsNullOrWhiteSpace(this.Name))
            {
                return(this.OnGet(id));
            }

            var book = this.Context
                       .Books
                       .Include(x => x.Borrowers)
                       .FirstOrDefault(x => x.Id == id);

            var borrower = this.Context
                           .Borrowers
                           .Include(x => x.BorrowedBooks)
                           .FirstOrDefault(x => x.Name == this.Name);

            DateTime?endDate = null;

            if (this.EndDate != null)
            {
                endDate = DateTime.Parse(this.EndDate);
            }

            if (book.IsBorrowed || endDate < DateTime.UtcNow)
            {
                return(RedirectToPage(IndexPage));
            }

            book.IsBorrowed = true;
            book.Status     = BorrowedStatus;

            var bookBorrow = new BookBorrow()
            {
                BookId     = book.Id,
                BorrowerId = borrower.Id,
                StartDate  = DateTime.UtcNow,
                EndDate    = endDate
            };

            this.Context.BookBorrows.Add(bookBorrow);

            this.Context.SaveChanges();

            return(RedirectToPage(IndexPage));
        }
        public ActionResult Return(int id, BookBorrow collection)
        {
            try
            {
                // TODO: Add update logic here
                BookBorrow borrow = _context.Borrow.Find(id);
                borrow.ReturnDate = DateTime.Today.ToString("MM/dd/yyyy");

                _context.Entry(borrow).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        // GET: BookBorrow/Return
        public ActionResult Return(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Status = "Yes";
            }
            DateTime tt = DateTime.Today;

            BookBorrow borrow = _context.Borrow.Find(id);

            TimeSpan D    = tt - borrow.BorrowDate;
            var      days = D.TotalDays;

            ViewBag.Days = days;

            return(View(borrow));
        }
 /// <summary>
 /// Place borrow book order and save info in BookBorrow dbCollection
 /// </summary>
 /// <param name="BookId"></param>
 /// <param name="bookBorrow"></param>
 /// <returns></returns>
 public async Task <BookBorrow> BorrowBook(string BookId, BookBorrow bookBorrow)
 {
     try
     {
         if (BookId == null && bookBorrow == null)
         {
             throw new ArgumentNullException(typeof(BookBorrow).Name + "Object and Id is Null");
         }
         _dbBCollection = _mongoContext.GetCollection <BookBorrow>(typeof(BookBorrow).Name);
         await _dbBCollection.InsertOneAsync(bookBorrow);
     }
     catch (Exception ex)
     {
         throw (ex);
     }
     return(bookBorrow);
 }
예제 #24
0
        public async Task PutBookBorrows_200Ok()
        {
            var updatedBookBorrow = new BookBorrow()
            {
                IdUser   = 1,
                IdBook   = 1,
                Comments = "brak"
            };

            var serializedUser = JsonConvert.SerializeObject(updatedBookBorrow);

            var payload = new StringContent(serializedUser, Encoding.UTF8, "application/json");

            var postResponse = await _client
                               .PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/1", payload);

            postResponse.EnsureSuccessStatusCode();
        }
예제 #25
0
        public async Task UpdateBookBorrow_200Ok()
        {
            var updatedBookBorrow = new BookBorrow
            {
                IdBookBorrow = 1,
                IdUser       = 1,
                IdBook       = 1,
                BorrowDate   = new DateTime(),
                ReturnDate   = new DateTime(),
                Comments     = "jednak ma byc taki komentarz"
            };

            var content       = JsonConvert.SerializeObject(updatedBookBorrow);
            var stringContent = new StringContent(content, Encoding.UTF8, "application/json");
            var response      = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{updatedBookBorrow.IdBookBorrow}", stringContent);

            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);

            using (var scope = _server.Host.Services.CreateScope())
            {
                var _db = scope.ServiceProvider.GetRequiredService <LibraryContext>();
                Assert.True(_db.BookBorrow.Any(info => (
                                                   info.IdBookBorrow == updatedBookBorrow.IdBookBorrow &&
                                                   info.IdUser == updatedBookBorrow.IdUser &&
                                                   info.IdBook == updatedBookBorrow.IdBook &&
                                                   info.BorrowDate == updatedBookBorrow.BorrowDate &&
                                                   info.ReturnDate == updatedBookBorrow.ReturnDate &&
                                                   info.Comments == updatedBookBorrow.Comments
                                                   )
                                               ));
            }

            /* NIEPRAWIDŁOWE BO UŻYWA METODY GET WIĘC JEŻELI ONA MA BŁĘDY TO AUTOMATYCZNIE BŁĄD POJAWI SIĘ I TUTAJ
             *
             * var GetResponse = await _client.GetAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{updatedBookBorrow.IdBookBorrow}");
             * GetResponse.EnsureSuccessStatusCode();
             * var GetResponseContent = await GetResponse.Content.ReadAsStringAsync();
             * var BookBorrowAfterUpdate = JsonConvert.DeserializeObject<BookBorrow>(content);
             * Assert.Equal(updatedBookBorrow.BorrowDate, BookBorrowAfterUpdate.BorrowDate);
             */
        }
예제 #26
0
        public async Task Put_Book_Barrow()
        {
            var newBookBarrow = new BookBorrow()
            {
                IdUser   = 1,
                IdBook   = 1,
                Comments = "Najlepsza"
            };

            var serializedUser = JsonConvert.SerializeObject(newBookBarrow);

            var payload = new StringContent(serializedUser, Encoding.UTF8, "application/json");


            // Act
            var response = await _client.PutAsync($"{ _client.BaseAddress.AbsoluteUri}api/book-borrows/1", payload);

            // Assert
            response.EnsureSuccessStatusCode();
        }
예제 #27
0
        public async Task <IActionResult> Details(Book model)
        {
            var book = await _context.BookEntity.Where(c => c.Id == model.Id).FirstOrDefaultAsync();

            if (book != null)
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        // add borrow rows
                        var bookBorrow = new BookBorrow
                        {
                            BookId     = book.Id,
                            Email      = GetUserEmail(),
                            BorrowTime = DateTime.Now
                        };

                        _context.Add(bookBorrow);
                        await _context.SaveChangesAsync();

                        // remove book quantity
                        book.Quantity = book.Quantity - 1;
                        _context.Update(book);
                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, "Borrow book errors.");
                    }
                }
            }
            else
            {
                _logger.LogCritical($"Cannot get book on borrow submit. Model: {model}");
            }

            return(RedirectToAction(nameof(Index)));
        }
예제 #28
0
        public async Task AddBookBorrow_201Created()
        {
            var newBookBorrow = new BookBorrow
            {
                IdUser     = 2,
                IdBook     = 2,
                BorrowDate = DateTime.Today,
                Comments   = "GSD2389-fhsjk h"
            };


            var           borrow = JsonConvert.SerializeObject(newBookBorrow);
            StringContent borrowStringContent = new StringContent(borrow, Encoding.UTF8, "application/json");
            var           httpResponse        = await _client.PostAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows", borrowStringContent);

            httpResponse.EnsureSuccessStatusCode();
            var content = await httpResponse.Content.ReadAsStringAsync();


            Assert.True(httpResponse.StatusCode == HttpStatusCode.Created);
        }
예제 #29
0
        public async Task PostBookBorrows_200Ok()
        {
            var newBookBorrow = new BookBorrow()
            {
                IdUser   = 2,
                IdBook   = 2,
                Comments = "brak"
            };

            var serializedUser = JsonConvert.SerializeObject(newBookBorrow);

            var payload = new StringContent(serializedUser, Encoding.UTF8, "application/json");

            var postResponse = await _client
                               .PostAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows", payload);

            postResponse.EnsureSuccessStatusCode();
            var com = await postResponse.Content.ReadAsStringAsync();

            Assert.Contains("brak", com);
        }
        public async Task <IActionResult> AddUserAsync([FromQuery] string nationalCode, [FromQuery] string isbn)
        {
            var book = _unitOfWork.Books.Find(b => b.ISBN == isbn).FirstOrDefault();
            var user = _unitOfWork.Users.Find(u => u.NationalCode == nationalCode).FirstOrDefault();

            if (book == null || !book.CanBorrow || user == null)
            {
                return(NotFound());
            }
            var borrow = new BookBorrow
            {
                Book           = book,
                User           = user,
                ReturnDateTime = DateTime.Today.AddDays(14)
            };
            await _unitOfWork.Borrows.AddAsync(borrow);

            await _unitOfWork.Complete();

            return(Ok());
        }