Esempio n. 1
0
        public GetAuthorViewModel GetAll()
        {
            var authorEntities = _authorRepository.GetAll();
            var authorViews    = new GetAuthorViewModel();

            authorViews.Authors = Mapper.Map <IEnumerable <Author>, List <GetAuthorViewItem> >(authorEntities);
            return(authorViews);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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));
        }