Beispiel #1
0
        public ActionResult EditCategory(Guid? id)
        {
            Category cat = null;

            if (id.HasValue)
            {
                using (var db = new qStoreDBEntities())
                {
                    cat = db.Categories.SingleOrDefault(x => x.Id == id);
                }
            }

            if (cat == null)
            {
                cat = new Category
                      {
                          Id = Guid.NewGuid()
                      };
            }

            return View(cat);
        }
Beispiel #2
0
        public ActionResult SaveCategory(Category model)
        {
            using (var db = new qStoreDBEntities())
            {
                var cat = db.Categories.SingleOrDefault(x => x.Id == model.Id);

                if (cat != null)
                {
                    cat.Title = model.Title;
                    cat.IsDisabled = model.IsDisabled;
                }
                else
                {
                    db.Categories.Add(model);
                }

                db.SaveChanges();
            }

            return RedirectToAction("Index");
        }