public GetAuthorViewModel GetAll() { var authorEntities = _authorRepository.GetAll(); var authorViews = new GetAuthorViewModel(); authorViews.Authors = Mapper.Map <IEnumerable <Author>, List <GetAuthorViewItem> >(authorEntities); return(authorViews); }
public GetAuthorViewModel Get(long id) { var author = _authorRepository.Get(id); if (author == null) { throw new BusinessLogicException("Author not found"); } var result = new GetAuthorViewModel() { Id = author.Id, Name = author.Name }; return(result); }
public IHttpActionResult GetAuthor(int id) { var author = context.Authors.Find(id); if (author == null) { return(this.BadRequest("Author doesn't exist.")); } var viewAuthor = new GetAuthorViewModel() { Id = author.Id, FirstName = author.FirstName, LastName = author.LastName, Books = author.Books.Select(b => b.Title) }; return(this.Ok(viewAuthor)); }
public GetAuthorViewModel Delete(long id) { var author = _authorRepository.Get(id); if (author == null) { throw new BusinessLogicException("Author not found"); } _authorRepository.Delete(id); _bookRepository.DeleteRangeByAuthorId(id); var result = new GetAuthorViewModel() { Id = author.Id, Name = author.Name }; return(result); }
public IActionResult Get() { GetAuthorViewModel result = _authorService.GetAll(); return(Ok(result)); }