public IHttpActionResult Get(Guid id) { var publisher = _publisherRepository.Find(id); if (publisher == null) { return(NotFound()); } var publisherViewModel = Mapper.Map <PublisherReadModel>(publisher); return(Ok(publisherViewModel)); }
public async Task <IActionResult> GetPublishers([FromRoute] int id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Publishers publishers = await _publisherRepository.Find(id); if (publishers == null) { return(NotFound()); } return(Ok(publishers)); } catch (Exception ex) { return(new StatusCodeResult(500)); } }
private void AddPublisher(Comic comic, IPublisherRepository publisherRepository, string publisherStr) { if (string.IsNullOrEmpty(publisherStr)) return; string[] publishers = publisherStr.Split(','); foreach (string publisher in publishers) { string publisherTrim = publisher.Trim(); Publisher publisherDb = publisherRepository.Find(g => g.PublisherName.Equals(publisherTrim)).FirstOrDefault(); if (publisherDb == null) { publisherDb = new Publisher { PublisherName = publisherTrim, Comics = new List<Comic>() }; publisherDb.Comics.Add(comic); publisherRepository.Add(publisherDb); } else { if (publisherDb.Comics == null) publisherDb.Comics = new List<Comic>(); if (publisherDb.Comics.Any(c => c.ComicUrl.Equals(comic.ComicUrl))) continue; publisherDb.Comics.Add(comic); publisherRepository.Edit(publisherDb); } if (comic.Publishers == null) comic.Publishers = new List<Publisher>(); if (!comic.Publishers.Any(g => g.PublisherName.Equals(publisherTrim))) { comic.Publishers.Add(publisherDb); } publisherRepository.Save(); } }