public IActionResult Put(int id, CreatedBookDTO createdBookDTO, [FromServices] ApplicationBook app) { try { return(Ok(app.Updated(id, createdBookDTO))); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult <Book> Created(CreatedBookDTO createdBookDTO, [FromServices] ApplicationBook app) { try { return(Ok(app.Created(createdBookDTO))); } catch (Exception ex) { return(BadRequest(ex)); } }
public Domain.Book Created(CreatedBookDTO createdBookDTO) { try { _bookRepository.Begin(); string slug = _generateSlug.generate(createdBookDTO.Name); if (_bookRepository.CheckSlugCreated(slug)) { throw new Exception("Livro já cadastrado com esse nome!"); } Domain.Book _bk = new Domain.Book(); _bk.Photo = this.uploadPhoto(createdBookDTO.Photo, slug); _bk.Author = createdBookDTO.Author; _bk.Slug = slug; _bk.DescriptionLong = createdBookDTO.DescriptionLong; _bk.DescriptionShort = createdBookDTO.DescriptionShort; _bk.Language = createdBookDTO.Language; _bk.Name = createdBookDTO.Name; _bk.Price = createdBookDTO.Price; _bk.Publishing = createdBookDTO.Publishing; _bk.QuantityPages = createdBookDTO.QuantityPages; _bk.Weight = createdBookDTO.Weight; _bk.Year = createdBookDTO.Year; _bk.CreatdAt = DateTime.Now; _bk = _bookRepository.Save(_bk); _bookRepository.Commit(); return(_bk); } catch (Exception ex) { _bookRepository.RollBack(); throw ex; } }
public Domain.Book Updated(int id, CreatedBookDTO createdBookDTO) { _bookRepository.Begin(); try { Domain.Book _bk = _bookRepository.Get(new Object[] { id }); string slug = _generateSlug.generate(createdBookDTO.Name); if (createdBookDTO.Photo != null) { _bk.Photo = uploadPhoto(createdBookDTO.Photo, slug); } _bk.Slug = slug; _bk.Author = createdBookDTO.Author; _bk.DescriptionLong = createdBookDTO.DescriptionLong; _bk.DescriptionShort = createdBookDTO.DescriptionShort; _bk.Language = createdBookDTO.Language; _bk.Name = createdBookDTO.Name; _bk.Price = createdBookDTO.Price; _bk.Publishing = createdBookDTO.Publishing; _bk.QuantityPages = createdBookDTO.QuantityPages; _bk.Weight = createdBookDTO.Weight; _bk.Year = createdBookDTO.Year; _bookRepository.Save(_bk); _bookRepository.Commit(); return(_bk); } catch (Exception ex) { _bookRepository.RollBack(); throw ex; } }