Ejemplo n.º 1
0
        public async Task <IActionResult> PutBookContract([FromRoute] int id, [FromBody] BookContract bookContract)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bookContract.Id)
            {
                return(BadRequest());
            }

            _context.Entry(bookContract).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookContractExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <bool> CreateBook(BookContract request)
        {
            Autor autor = await _autorRepository.GetByIdAsync(request.AutorId);

            if (autor == null)
            {
                throw new Exception("El autor no está registrado");
            }

            Editorial editorial = await _editorialRepository.GetByIdAsync(request.EditorialId);

            if (editorial == null)
            {
                throw new Exception("La editorial no está registrada");
            }

            if (editorial.MaxBook != -1)
            {
                int count = _editorialRepository.GetCountForEditorial(editorial.Id);
                if (count == editorial.MaxBook)
                {
                    throw new Exception("No es posible registrar el libro, se alcanzó el máximo permitido.");
                }
            }

            Book book = _mapper.Map <Book>(request);
            await _bookRepository.CreateAsync(book);

            return(true);
        }
Ejemplo n.º 3
0
 public bool AddBook(BookContract book)
 {
     using (BookBorrowContext context = new BookBorrowContext())
     {
         book.IsDel = false;
         book.BookStatus = BookStatus.Avalable;
         context.Book.Add(book);
         int effect = context.SaveChanges();
         return effect == 1;
     }
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> PostBookContract([FromBody] BookContract bookContract)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.BookContracts.Add(bookContract);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBookContract", new { id = bookContract.Id }, bookContract));
        }
Ejemplo n.º 5
0
        public async Task <Response <bool> > CreateBook(BookContract request)
        {
            Response <bool> response = new Response <bool>();

            try
            {
                response.Data = await _bookService.CreateBook(request);
            }
            catch (Exception ex)
            {
                response.Header.Code    = 500;
                response.Header.Message = ex.Message;
            }

            return(response);
        }
Ejemplo n.º 6
0
 public ActionResult Create(BookContract book)
 {
     service.AddBook(book);
     return View();
 }
Ejemplo n.º 7
0
 public ActionResult Create()
 {
     string serialId = service.GetNextMaxBookSerialId();
     BookContract book = new BookContract { SerialId = serialId };
     return View(book);
 }
Ejemplo n.º 8
0
 public CartAdapter()
 {
     _contract = new BookContract();
 }