public IActionResult Post([FromBody] PublisherModel newPublisher)
        {
            var publisher = _publisherService.Add(newPublisher.ToDomainModel());

            if (publisher == null)
            {
                return(BadRequest());
            }
            return(CreatedAtAction("Get", new { Id = newPublisher.Id }, newPublisher));
        }
Esempio n. 2
0
        public IActionResult Put(int id, [FromBody] PublisherModel updatedPublisher)
        {
            var publisher = _publisherService.Update(updatedPublisher.ToDomainModel());

            if (publisher == null)
            {
                return(NotFound());
            }
            return(Ok(publisher));
        }
        public IActionResult Put(int id, [FromBody] PublisherModel updatedPublisher)
        {
            // TODO: convert updatedAuthor to a domain model
            var publisher = _publisherService.Update(updatedPublisher.ToDomainModel());

            if (publisher == null)
            {
                return(NotFound());
            }
            return(Ok(publisher));
        }
 public IActionResult Post([FromBody] PublisherModel newPublisher)
 {
     try
     {
         _publisherService.Add(newPublisher.ToDomainModel());
     }
     catch (System.Exception ex)
     {
         ModelState.AddModelError("AddPublisher", ex.GetBaseException().Message);
         return(BadRequest(ModelState));
     }
     return(CreatedAtAction("Get", new { Id = newPublisher.Id }, newPublisher));
 }
        public IActionResult Post([FromBody] PublisherModel newPublisher)
        {
            try {
                // TODO: convert apimodel to domain model
                // add the new book
                _publisherService.Add(newPublisher.ToDomainModel());
                //UNSURE
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddPublisher", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            return(CreatedAtAction("Get", new { Id = newPublisher.Id }, newPublisher));
        }
Esempio n. 6
0
        public IActionResult Post([FromBody] PublisherModel newPublisher)
        {
            try
            {
                // add the new publisher
                _publisherService.Add(newPublisher.ToDomainModel());
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddPublisher", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            // return a 201 Created status. This will also add a "location" header
            // with the URI of the new publisher. E.g., /api/publishers/99, if the new is 99
            return(CreatedAtAction("Get", new { Id = newPublisher.Id }, newPublisher));
        }
Esempio n. 7
0
        public IActionResult Post([FromBody] PublisherModel myNewPublisher)
        {
            //var author = _authorService.Add(myNewAuthor);
            //if (author == null) return BadRequest();
            //return CreatedAtAction("Get", new { Id = myNewAuthor.Id }, myNewAuthor);

            try
            {
                // TODO: convert the newAuthor to a domain model
                // add the new author
                _publisherService.Add(myNewPublisher.ToDomainModel());
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddPublisher", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            // return a 201 Created status. This will also add a "location" header
            // with the URI of the new author. E.g., /api/authors/99, if the new is 99
            return(CreatedAtAction("Get", new { Id = myNewPublisher.Id }, myNewPublisher));
        }