public IActionResult CreateBook(CreateBookRequest request) { var command = mapper.Map <CreateBookCommand>(request); command.CreatedBy = CurrentAccountId; return(HandleCommandResult(appExecutor.Dispatch(command))); }
public static Book ConvertToBook(this CreateBookRequest createRequest) { Book book = new Book(); book.Title = createRequest.Title; book.ISBN = createRequest.ISBN; book.Description = createRequest.Description; book.Genre = new Genre() { GenreId = createRequest.GenreId }; book.Language = new Language() { LanguageId = createRequest.LanguageId }; book.Authors = new List <Author>(); foreach (int id in createRequest.AuthorIds) { book.Authors.Add(new Author() { AuthorId = id }); } return(book); }
public IActionResult Post([FromBody] CreateBookRequest newBook) { var existingBook = _repository.GetByISBN(newBook.ISBN); if (existingBook != null) { existingBook.StockAmount++; _repository.Update(existingBook); return(Ok(existingBook)); } ; var book = new Book { Title = newBook.Title, Description = newBook.Description, ISBN = newBook.ISBN, Thumbnail = newBook.Thumbnail, StockAmount = newBook.StockAmount, Price = newBook.Price, Author = _repository.GetAuthorById(newBook.AuthorId), }; _repository.Add(book); return(CreatedAtRoute("", new { id = book.Id }, newBook)); }
public async Task <BaseResponse <bool> > Handle(CreateBookRequest request, CancellationToken cancellationToken) { BaseResponse <Boolean> response = new BaseResponse <bool>(); try { Book book = new Book() { CategoryId = request.CategoryId, Description = request.Description, ImageUrl = request.ImageUrl, Name = request.Name, Price = request.Price }; var book2 = (await _repository.Create(book)); await _bus.Publish(book2.Adapt <BookCreatedEvent>(), cancellationToken); response.Data = true; } catch (Exception e) { Console.WriteLine(e); response.Errors.Add(e.Message + "*********InnerException**********" + e.InnerException); } return(response); }
public async Task <ActionResult> CreateAsync([FromForm] CreateBookRequest book) { //Convert to the model var bookEntity = _mapper.Map <BookEntity>(book); if (book.CoverImage != null) { // Saving Image on Server var coverImage = book.CoverImage; var serverFileName = bookEntity.CoverImageFileName; var path = Path.Combine(_env.WebRootPath + "\\Images\\", serverFileName); if (coverImage.Length > 0) { using var fileStream = new FileStream(path, FileMode.Create); await coverImage.CopyToAsync(fileStream); } } _context.Books.Add(bookEntity); await _context.SaveChangesAsync(); var bookResponse = _mapper.Map <BookResponse>(bookEntity); return(CreatedAtRoute("GetByIdAsync", new { id = bookEntity.Id }, bookResponse)); }
public ResponseBase UpdateBook(CreateBookRequest request) { var response = new ResponseBase(); try { var book = _bookRepository.GetById(request.Create.Id); book.BookCategoryId = request.Create.BookCategoryId; book.CoverPage = request.Create.CoverPage; book.CreationDate = DateTime.Now; book.Description = request.Create.Description; book.IsActive = request.Create.IsActive; book.IsbnNumber = request.Create.IsbnNumber; book.Price = request.Create.Price; book.PublishedDate = request.Create.PublishedDate; book.Remarks = request.Create.Remarks; book.TitleB = request.Create.TitleB; book.TitleE = request.Create.TitleE; book.TotalPage = request.Create.TotalPage; _bookRepository.Update(book); _bookUnitOfWork.Commit(); response.TransactionMessage = "Data Updated Successfully"; response.TransactionStatus = true; } catch (InvalidBookException ex) { response.TransactionMessage = "Failed to Update Data"; response.TransactionStatus = false; LoggingFactory.GetLogger().Log(ex.Message.ToString()); } return(response); }
public void Book_Update_Testing() { var facade = new Mock <IBookFacade>(); var createRequest = new CreateBookRequest { Create = { Id = 0, IsActive = 1, IsbnNumber = "12345", Price = 566, PublishedDate = DateTime.Now, Remarks = "Remarks", TitleB = "Book Bengali", TitleE = "Book English", TotalPage = 150, BookCategoryId = 1, Description = "desc" } }; var success = new ResponseBase { TransactionMessage = "Data Modified Successfully", TransactionStatus = true }; facade.Setup(x => x.UpdateBook(createRequest)).Returns(success); }
public ActionResult <CreateBookService> Post(CreateBookRequest request) { CreateBookService _service = new CreateBookService(_unitOfWork); CreateBookResponse response = _service.CreateBook(request); return(Ok(response)); }
public async Task <IActionResult> Create([FromBody] CreateBookRequest req) { _logger.LogInformation("Requisitando criaĆ§Ć£o de livro..."); _logger.LogInformation("Dados da requisiĆ§Ć£o: {req}", JsonConvert.SerializeObject(req)); var newBook = _mapper.Map <Book>(req); var result = await _bookService .AddBookAsync(newBook) .ConfigureAwait(false); if (!result) { _logger.LogWarning("Erro ao tentar inserir livro. " + "AplicaĆ§Ć£o encerrou a requisiĆ§Ć£o com o status {statusCode}", HttpStatusCode.BadRequest); return(BadRequest()); } var uri = _uriService .GetBookUri(newBook.BookId.ToString()); _logger.LogInformation("Novo livro inserido!"); return(Created(uri, _mapper.Map <BookResponse>(newBook))); }
public async Task <IHttpActionResult> Create([FromBody] CreateBookRequest createBookRequest) { if (!ModelState.IsValid) { return(BadRequest()); } var author = await _repoWrapper.Author.CreateAsync(new Author() { FirstName = createBookRequest.AuthorName, LastName = createBookRequest.AuthorLastName }); if (author == null) { return(BadRequest("No Authors was inputed")); } var category = await _repoWrapper.Category.GetCategoryByName(createBookRequest.Category); if (category == null) { return(BadRequest("No Category could be found with that name!")); } var book = new IBooks { Title = createBookRequest.Title, Descriptions = createBookRequest.Descriptions, Published = createBookRequest.Published, PageCount = createBookRequest.PageCount, ISBN = _repoWrapper.Book.CreateISBN(), AuthorId = author.Id, CategoryId = category.Id }; var created = await _repoWrapper.Book.CreateAsync(book); if (!created) { return(BadRequest("Something went wrong when creating a new book")); } var response = new BookResponse { Id = book.Id, ISBN = book.ISBN, Descriptions = book.Descriptions, Published = book.Published, PageCount = book.PageCount, Title = book.Title, Author = $"{author.FirstName} {author.LastName}", Category = category.Name }; return(Json(response)); }
public async Task <IActionResult> AddBookAsync([FromBody] CreateBookRequest BookRequest) { (bool succeed, string message, CreateBookResponse BookResponse) = await Mediator.Send(BookRequest); if (succeed) { return(Ok(BookResponse.ToResponse())); } return(BadRequest(message.ToResponse(false, message))); }
public async Task CreateNewTitle([FromBody] CreateBookRequest request) { var book = new Book() { Id = Guid.NewGuid(), Title = request.Title }; await _bookMapperSession.AddAsync(book); }
public IActionResult CreateBook([FromBody] CreateBookRequest request) { Book book = new Book(); book.Name = request.Name; book.AuthorId = request.AuthorId; book.TypeId = request.TypeId; book.IsActive = true; _bookService.Add(book); return(Ok()); }
public async Task <IActionResult> Post(Guid id, [FromBody] CreateBookRequest request) { if (id == Guid.Empty || !ModelState.IsValid) { return(BadRequest()); } var command = new AddBook(request.ToBook(id), UserId); await Mediator.Send(command); return(Ok()); }
public async Task <ActionResult <Book> > PostBook(CreateBookRequest request) { var book = new Book { Name = request.Name, CatalogId = request.CatalogId }; await _context.Books.AddAsync(book); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBook", new { id = book.Id }, book)); }
public async Task <bool> Handle(CreateBookRequest message, IOutputPort <CreateBookResponse> outputPort) { Book book = new Book { Name = message.Name, Text = message.Text, Price = message.Price }; await _bookRepository.Add(book); outputPort.Handle(new CreateBookResponse(book)); return(true); }
public Guid CreateBook(CreateBookRequest request) { if (!new CreateBookRequestValidator().Validate(request).IsValid) { throw new Exception("CreateBook validation error"); } Persistence.BeginTransaction(); var book = new Book(request); Persistence.Create(book); Persistence.Commit(); return(book.Id); }
public IActionResult Create([FromBody] CreateBookRequest command) { try { var response = _mediator.Send(command); return(new ObjectResult("Livro adicionado com sucesso!") { StatusCode = StatusCodes.Status201Created });; } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IEnumerable <BookDto> > Create([FromBody] CreateBookRequest newBook) { var book = new BookDto() { NoVolumen = newBook.NoVolumen, Descripcion = newBook.Descripcion }; await bookService.Create(book); var result = new List <BookDto>(); result.Add(book); return(result); }
public ActionResult Create(BookSinglePageViewModel model) { CreateBookRequest request = model.BookViewModel.ConvertToCreateBookRequest(); CreateBookResponse response = _bookService.CreateBook(request); if (response.Success) { return(RedirectToAction("Index")); } else { model.Success = false; model.Message = response.Message; return(View(model)); } }
public CreateBookResponse CreateBook(CreateBookRequest request) { CreateBookResponse response = new CreateBookResponse(); try { Book book = request.ConvertToBook(); _bookRepository.Create(book); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public virtual async Task <IActionResult> AddBook([FromBody] CreateBookRequest createBookRequest) { var user = await _userService.GetUserInfo(RequestContextProvider.Context.UserName); var book = Mapper.Map <CreateBookResponse>(await _bookService.CreateAsync(Mapper.Map <Book>(createBookRequest))); await _bookUSerSubscriptionService.CreateAsync(new UserBook { BookId = book.Id, UserId = user.Id, OnSale = createBookRequest.OnSale, SubscriptionId = null }); return(Ok(book)); }
public static CreateBookRequest ConvertToCreateBookRequest(this BookViewModel model) { CreateBookRequest request = new CreateBookRequest(); request.Title = model.Title; request.ISBN = model.ISBN; request.Description = model.Description; request.GenreId = Convert.ToInt32(model.Genre.GenreId); request.LanguageId = Convert.ToInt32(model.Language.LanguageId); request.AuthorIds = new List <int>(); foreach (int id in model.AuthorIds) { request.AuthorIds.Add(id); } return(request); }
public IHttpActionResult AddNewBook(CreateBookRequest request) { var response = new CreateBookResponse(); var dtoInput = AutoMapper.Mapper.Map <CreateNewBookInput>(request); try { _bookBLL.AddNewBook(dtoInput); } catch (Exception ex) { response.Messages = ex.Message; response.Success = false; } return(Ok(response)); }
public CreateBookResponse CreateBook(CreateBookRequest request) { var response = new CreateBookResponse(); var entity = CommonLogic.SetMapping <CreateBookRequest, Book>(request); try { //----------------------using EF----------------- _context.Add(entity); _context.SaveChanges(); response.IsSuccess = true; } catch { throw new Exception(); } return(response); }
public void EnviarSolicitudLibro() { CreateBookService _bookService = new CreateBookService(new UnitOfWork(_context)); var bookRequest = new CreateBookRequest { DocumentTeacher = "1035", Title = "DDD", NumberOfAuthors = 2, Credit = true, BookType = "Libro de ensayo", Editorial = "Norma", Isbn = "asaa", Languaje = "EspaƱol", PublicationDate = DateTime.Now }; _bookService.CreateBook(bookRequest); Book book = _bookService.Consult(bookRequest.Title); SendRequestService _sendRequestService = new SendRequestService(new UnitOfWork(_context)); var propertiesRequest = new SendRequestProperties { TitleProductivity = "DDD" }; var responseRequest = _sendRequestService.SendProductivity(propertiesRequest); Assert.AreEqual("La solicitud de la productividad Realidad Aumentada fue enviada con exito, su puntaje estimado es 15.", responseRequest.Menssage); }
public async Task <CreateBookResult> CreateBook(CreateBookRequest request) { try { DynamicParameters parameters = new DynamicParameters(); parameters.Add("@BookName", request.BookName); parameters.Add("@Author", request.Author); parameters.Add("@BookRow ", request.BookRow); return(await SqlMapper.QueryFirstOrDefaultAsync <CreateBookResult>(cnn : connect, sql : "sp_CreateBook", param : parameters, commandType : CommandType.StoredProcedure)); } catch (Exception ex) { throw; } }
private async Task <PutItemResponse> Createbook(CreateBookRequest bookRequest) { var dynamoDbClient = InitDynamoDbClient(); var id = GenerateUniqueId(); var request = new PutItemRequest { TableName = "Book", Item = new Dictionary <string, AttributeValue> { { "Id", new AttributeValue { N = id.ToString() } }, { "Author", new AttributeValue { S = bookRequest.Author } }, { "Pages", new AttributeValue { N = bookRequest.Pages.ToString() } }, { "Title", new AttributeValue { S = bookRequest.Title } }, { "Publisher", new AttributeValue { S = bookRequest.Publisher } } } }; return(await dynamoDbClient.PutItemAsync(request)); }
public async Task Create_ValidObjectPassed_ReturnsCreatedResponse() { //Arrange var cbr = new CreateBookRequest { Title = "Art of Unit Testing", Author = "Roy Osherove", Description = "The Art of Unit Testing is a 2009 book by Roy Osherove which " + "covers unit test writing for software.", Price = 100, CoverImage = null }; //Act var actionResult = await _bookController.CreateAsync(cbr); //Assert Assert.IsType <CreatedAtRouteResult>(actionResult); }
public IActionResult CreateBook([FromBody] CreateBookRequest bookRequest) { if (!ModelState.IsValid) { return(BadRequest("Not a valid book requst!")); } // turn book that's come through into an entity Book. In a future iteration you could make DTOs (service layer models/view models) that come in and use AutoMapper to map // that DTO to an entity model var newBook = new Book() { Author = bookRequest.Author, Title = bookRequest.Title, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }; _bookService.AddBook(newBook); return(Ok($"New book '{newBook.Title}' successfully added")); }