Ejemplo n.º 1
0
        public ActionResult Create(int?genreId, int?authorId)
        {
            var model = new BookFullModel
            {
                GenreId  = genreId.HasValue ? genreId.Value : 0,
                AuthorId = authorId.HasValue ? authorId.Value : 0,
            };

            FillDicts();

            return(View("CreateEdit", new AddEditBookModel
            {
                Action = "Create",
                Book = model
            }));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetById(int id)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(() =>
            {
                BookstoreContext context = new BookstoreContext();
                var bookEntity           = context.Books.Include("Authors")
                                           .SingleOrDefault(b => b.Id == id);

                if (bookEntity == null)
                {
                    throw new ServerErrorException("Book does not exist");
                }

                var bookModel = new BookFullModel()
                {
                    Id          = bookEntity.Id,
                    CoverUrl    = bookEntity.CoverUrl,
                    PublishDate = bookEntity.PublishDate,
                    Title       = bookEntity.Title,
                    Authors     = new HashSet <AuthorModel>()
                };

                foreach (var author in bookEntity.Authors)
                {
                    bookModel.Authors.Add(new AuthorModel()
                    {
                        Id        = author.Id,
                        FirstName = author.FirstName,
                        LastName  = author.LastName,
                        BirthDate = author.BirthDate
                    });
                }

                return(Request.CreateResponse(HttpStatusCode.OK, bookModel));
            });

            return(responseMsg);
        }