public async Task <IActionResult> Edit(int?id) { if (id is null) { return(NotFound()); } var book = Mapper.Map <BookDTO>(await BookGetService.GetAsync(new BookIdentityModel((int)id))); if (book is null) { return(NotFound()); } return(View(book)); }
public async Task ValidateAsync_BookExists_DoesNothing() { // Arrange var bookContainer = new Mock <IBookContainer>(); var book = new Book(); var bookDataAccess = new Mock <IBookDataAccess>(); bookDataAccess.Setup(x => x.GetByAsync(bookContainer.Object)).ReturnsAsync(book); var bookGetService = new BookGetService(bookDataAccess.Object); // Act var action = new Func <Task>(() => bookGetService.ValidateAsync(bookContainer.Object)); // Assert await action.Should().NotThrowAsync <Exception>(); }
public async Task ValidateAsync_BookNotExists_ThrowsError() { // Arrange var fixture = new Fixture(); var id = fixture.Create <int>(); var bookContainer = new Mock <IBookContainer>(); bookContainer.Setup(x => x.BookId).Returns(id); var book = new Book(); var bookDataAccess = new Mock <IBookDataAccess>(); bookDataAccess.Setup(x => x.GetByAsync(bookContainer.Object)).ReturnsAsync((Book)null); var bookGetService = new BookGetService(bookDataAccess.Object); // Act var action = new Func <Task>(() => bookGetService.ValidateAsync(bookContainer.Object)); // Assert await action.Should().ThrowAsync <InvalidOperationException>($"Book not found by id {id}"); }
public async Task <IActionResult> Index() { var list = Mapper.Map <IEnumerable <BookDTO> >(await BookGetService.GetAsync()); return(View(list)); }
public async Task <IActionResult> Create(OrderCreateDTO orderCreate) { try { var order = Mapper.Map <OrderDTO>( await OrderCreateService.CreateAsync(Mapper.Map <OrderUpdateModel>(orderCreate))); return(Redirect($"/orders/{order.Id}")); } catch { ViewData["BookId"] = new SelectList(Mapper.Map <IEnumerable <BookDTO> >(await BookGetService.GetAsync()), "Id", "Title"); ViewData["CustomerId"] = new SelectList(Mapper.Map <IEnumerable <CustomerDTO> >(await CustomerGetService.GetAsync()), "Id", "FullName"); return(View()); } }
public async Task <IActionResult> Create() { ViewData["BookId"] = new SelectList(Mapper.Map <IEnumerable <BookDTO> >(await BookGetService.GetAsync()), "Id", "Title"); ViewData["CustomerId"] = new SelectList(Mapper.Map <IEnumerable <CustomerDTO> >(await CustomerGetService.GetAsync()), "Id", "FullName"); return(View()); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var order = Mapper.Map <OrderDTO>(await OrderGetService.GetAsync(new OrderIndentityModel((int)id))); if (order == null) { return(NotFound()); } var updateDto = new OrderUpdateDTO { Id = order.Id, Arrived = order.Arrived, CustomerId = order.Customer.Id, BookId = order.Book.Id, Date = order.Date }; ViewData["BookId"] = new SelectList(Mapper.Map <IEnumerable <BookDTO> >(await BookGetService.GetAsync()), "Id", "Title", updateDto.BookId); ViewData["CustomerId"] = new SelectList(Mapper.Map <IEnumerable <CustomerDTO> >(await CustomerGetService.GetAsync()), "Id", "FullName", updateDto.CustomerId); return(View(updateDto)); }