예제 #1
0
        /// <summary>
        /// Return page for create book.
        /// </summary>
        public ActionResult Create()
        {
            var bookViewModel = new BookViewModel();

            InitializeViewModel(bookViewModel);

            return View(bookViewModel);
        }
예제 #2
0
        public ActionResult Create(BookViewModel bookViewModel)
        {
            if (!ModelState.IsValid)
            {
                InitializeViewModel(bookViewModel);

                return this.View(bookViewModel);
            }

            var bookDto = Mapper.Map<BookViewModel, BookDto>(bookViewModel);
            this.client.Create(UrlProvider.WebApiBook, bookDto);

            return RedirectToAction("Index");
        }
예제 #3
0
        private void InitializeViewModel(BookViewModel bookViewModel)
        {
            var categoriesDto = this.client.Get<IEnumerable<CategoryDto>>(UrlProvider.WebApiCategory);
            var categoriesViewModel = Mapper.Map<IEnumerable<CategoryDto>, IEnumerable<CategoryViewModel>>(categoriesDto);

            bookViewModel.AllCategories = categoriesViewModel
                .Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() })
                .ToList();
        }
예제 #4
0
        public ActionResult Delete(BookViewModel bookViewModel)
        {
            this.client.Delete(UrlProvider.WebApiBook + bookViewModel.Id);

            return RedirectToAction("Index");
        }