public ActionResult NewOrder(PersonBookDto order) { if (ModelState.IsValid) { repo.Orders.Create(order); repo.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index", order)); }
// GET: Reader public ActionResult Index(PersonBookDto item = null) { var persons = repo.Persons.Get().Select(s => new SelectListItem { Text = s.FullName, Value = s.Id.ToString() }).ToList(); var books = repo.Books.GetFree().Select(s => new SelectListItem { Text = s.Title, Value = s.Id.ToString() }).ToList(); ViewBag.Data = GetOrderData(); ViewBag.Orders = repo.Orders.Get().OrderByDescending(o => o.Id).Take(10).ToList(); if (item == null) { item = new PersonBookDto(); } return(View(item)); }
public void Create(PersonBookDto order) { var newOrder = Mapper.Map <PersonBookDto, PersonBook>(order); db.PersonBooks.Add(newOrder); }