public IActionResult AddComicToCollection(CreateComicCollectionDto input) { try { var dto = _service.AddComicToCollection(input); return(Ok(dto)); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public ComicCollectionDto AddComicToCollection(CreateComicCollectionDto input) { if (_comicCollectionRepository.GetAll().Any(x => x.CollectionId == input.CollectionId && x.ComicId == input.ComicId)) { throw new AppException(" Already in collection"); } var comicCollection = new ComicCollection() { CollectionId = input.CollectionId, ComicId = input.ComicId }; _comicCollectionRepository.Add(comicCollection); _comicCollectionRepository.SaveChanges(); var comicCollectionDto = _mapper.Map <ComicCollectionDto>(comicCollection); return(comicCollectionDto); }