Ejemplo n.º 1
0
 public ActionResult Add(AddCategoryViewModel viewModel)
 {
     if (!ModelState.IsValid)
         return View(viewModel);
     var category = new Category
     {
         Name = viewModel.Name,
         Parent = viewModel.Parent
     };
     using (var database = new DatabaseEntities())
     {
         database.AddToCategories(category);
         database.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Ejemplo n.º 2
0
 public ActionResult Add()
 {
     var viewModel = new AddCategoryViewModel();
     int parentId;
     if (Request.QueryString["parent"] != null &&
         int.TryParse(Request.QueryString["parent"], out parentId))
     {
         Category parent;
         using (var database = new DatabaseEntities())
         {
             parent = database.CategoryById(parentId);
         }
         if (parent != null)
         {
             viewModel.Parent = parentId;
             viewModel.ParentName = parent.Name;
         }
     }
     return View(viewModel);
 }