Ejemplo n.º 1
0
 public CategoryViewModel UpdateCategory(CategoryViewModel model)
 {
     var category = context.Categories.Find(model.Id);
     Mapper.Map(model, category);
     var parent = context.Categories.Find(model.ParentId);
     category.Parent = parent;
     context.SaveChanges();
     return Mapper.Map<CategoryViewModel>(category);
 }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, CategoryViewModel model)
        {
            var categories = categoryService.GetCategories().Where(c => c.Id != id).ToList();
            ViewBag.Categories = new SelectList(categories, "Id", "Name", categories.Find(c => c.Id == model.ParentId));

            if (ModelState.IsValid)
            {
                try
                {
                    var category = categoryService.UpdateCategory(model);
                    Success(string.Format("Category [{0}] with id [{1}] was modified.", category.Name, category.Id));

                    return RedirectToAction("Index");
                }
                catch(Exception e)
                {
                    Error(e.Message);
                }
            }

            return View(model);
        }