public ActionResult Edit(int id, CategoryModel categoryModel) { try { CategoryDAO.UpdateProduct(id, categoryModel); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(CategoryModel categoryModel) { try { CategoryDAO.CreateProduct(categoryModel); return RedirectToAction("Index"); } catch { return View(); } }
public static void UpdateProduct(int id, CategoryModel categoryModel) { var storageDbEntities = new StorageDBEntities(); Category category = storageDbEntities.Categories.Where(c => c.ID == id && c.UserID == UserHelper.UserID).FirstOrDefault(); if (category != null) { category.Name = categoryModel.Name; } storageDbEntities.SaveChanges(); }
public static void CreateProduct(CategoryModel categoryModel) { if (UserHelper.UserID != null) { var storageDbEntities = new StorageDBEntities(); Category newCategory = new Category { Name = categoryModel.Name, UserID = UserHelper.UserID.Value }; storageDbEntities.Categories.AddObject(newCategory); storageDbEntities.SaveChanges(); } }
public ProductModel() { Category = new CategoryModel(); }