/// <summary> /// Return page for create book. /// </summary> public ActionResult Create() { var bookViewModel = new BookViewModel(); InitializeViewModel(bookViewModel); return View(bookViewModel); }
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"); }
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(); }
public ActionResult Delete(BookViewModel bookViewModel) { this.client.Delete(UrlProvider.WebApiBook + bookViewModel.Id); return RedirectToAction("Index"); }