public async Task CreateBorrow(List <Borrow> borrows) { foreach (var borrow in borrows) { await _service.Add(borrow); await _bookService.UpdateSingle(borrow.BookId, "BookState", "1"); } var reservations = new List <Reservation>(); foreach (var borrow in borrows) { var data = await _reservationService.QueryAll(new Dictionary <string, string>() { { "StudentId", borrow.StudentId.ToString() }, { "BookId", borrow.BookId.ToString() }, { "IsRemove", "0" } }); reservations.AddRange(data); } foreach (var reservation in reservations) { await _reservationService.Delete(reservation.Id); } }
public async Task HandleAsync(BorrowBook command) { await _borrowService.Add(command.userId, command.bookId); var book = await _bookRepository.Get(command.bookId); await _bookService.Update(book, book.Stock - 1); }
public async Task <IActionResult> CreateBorrow([FromBody] BorrowDto borrow) { if (borrow == null) { return(BadRequest()); } await _borrowService.Add(borrow); return(Created("Created new borrow.", borrow)); }
public HttpResponseMessage Post([FromBody] BorrowDTO borrow) { if (borrow == null) { throw new ModelValidationResultsException(string.Format(ValidationConstants.SRequiredProperty, "borrow")); } if (borrow.BookID == 0 || borrow.StudentID == 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } _borrowService.Add(borrow); return(Request.CreateResponse(HttpStatusCode.Created)); }