public ActionResult _AjaxRentBook(RentBookDTO dto) { var bookInfo = ApiRequest.Get <EditBookDTO>($"{_apiGatewayUrl}/api/books/{dto.BookId}"); var bookInventoryId = bookInfo.BookInventories.Where(p => p.Status == 1).FirstOrDefault()?.BookInventoryId; if (bookInventoryId.HasValue) { var commandId = ApiRequest.Post <Guid>($"{_apiGatewayUrl}/api/customers/{dto.CustomerId}/books", new { BookId = bookInventoryId, BookName = bookInfo.BookName, ISBN = bookInfo.ISBN, CustomerId = dto.CustomerId, Name = new { FirstName = "Lily", MiddleName = string.Empty, LastName = "Jiang" } }); return(Json(new { result = true, commandId = commandId })); } else { return(Json(new { result = false, errorMessage = "Book has been rented, please try again." })); } }
public void RentBook(RentBookDTO dto) { var sql = "INSERT INTO rent_history(RentId, BookId, BookName, ISBN, RentDate, DateIssued) VALUES(@rentId, @bookId, @bookName, @isbn, @rentDate, @dateIssued)"; _dbHelper.ExecuteNonQuery(sql, new List <MySqlParameter> { new MySqlParameter { ParameterName = "@rentId", MySqlDbType = MySqlDbType.Guid, Value = Guid.NewGuid() }, new MySqlParameter { ParameterName = "@bookId", MySqlDbType = MySqlDbType.Guid, Value = dto.BookId }, new MySqlParameter { ParameterName = "@bookName", MySqlDbType = MySqlDbType.VarChar, Value = dto.BookName }, new MySqlParameter { ParameterName = "@isbn", MySqlDbType = MySqlDbType.VarChar, Value = dto.ISBN }, new MySqlParameter { ParameterName = "@rentDate", MySqlDbType = MySqlDbType.Date, Value = dto.RentDate }, new MySqlParameter { ParameterName = "@dateIssued", MySqlDbType = MySqlDbType.Date, Value = dto.DateIssued } }.ToArray()); }
public IActionResult Rent([FromBody] RentBookDTO rentBookDTO) { var timeSpan = TimeSpan.FromDays(rentBookDTO.RentDuration); var rentBook = rentBookRepositoryService.Rent(rentBookDTO.BookID, rentBookDTO.UserID, timeSpan); if (rentBook == null) { return(BadRequest("Book is not avaiable for rent.")); } return(Ok(rentBook)); }
public Guid Rent(int customerId, [FromBody] RentBookDTO dto) { var command = new RentBookCommand { BookId = dto.BookId, BookName = dto.BookName, ISBN = dto.ISBN, Name = dto.Name, CustomerId = dto.CustomerId }; _commandPublisher.Publish(command); return(command.CommandUniqueId); }
public void RentBook(RentBookDTO dto) { using (var connection = _dbConnectionFactory.GetConnection()) { var sql = @"INSERT INTO rent_history(RentId, BookId, BookName, ISBN, RentDate, DateIssued) VALUES(@rentId, @bookId, @bookName, @isbn, @rentDate, @dateIssued)"; connection.Execute(sql, new { rentId = Guid.NewGuid(), bookId = dto.BookId, bookName = dto.BookName, isbn = dto.ISBN, rentDate = dto.RentDate, dateIssued = dto.DateIssued }); } }