public static ExtendedCategory GetByCode(string code) { var context = new Ecommerce.DbEntity.ecommerceEntities(); var cat = context.categories.Where(m => m.Code == code).FirstOrDefault(); var category = new ExtendedCategory(); category.Code = cat.Code; category.discription = cat.discription; category.id = cat.id; category.name = cat.name; return category; }
public ActionResult Create() { if (Request.IsAuthenticated) { ViewBag.PageTittle = "Add Category"; ViewBag.breadCrum = "<a href='/Admin/Category/index'>Category</a> >> Add Category"; ExtendedCategory obj = new ExtendedCategory(); return View(obj); } else { return RedirectToAction("index", "home"); } }
public static bool Create(ExtendedCategory obj) { bool check = true; try { var context = new Ecommerce.DbEntity.ecommerceEntities(); context.categories.Add(new DbEntity.category {Code=obj.name.Replace(" ","-"),discription=obj.discription,name=obj.name }); context.SaveChanges(); } catch (Exception ex) { check = false; } return check; }
public ActionResult Edit(int id) { if (Request.IsAuthenticated) { ViewBag.PageTittle = "Edit Category"; ViewBag.breadCrum = "<a href='/Admin/Category/index'>Category</a> >> Edit Category"; ExtendedCategory obj = new ExtendedCategory(); obj = CategoryDal.GetById(id); return View("Create", obj); } else { return RedirectToAction("index", "home"); } }
public static bool Update(ExtendedCategory obj) { bool check = true; try { var context = new Ecommerce.DbEntity.ecommerceEntities(); var cat = context.categories.Where(m => m.id == obj.id).FirstOrDefault(); cat.Code = obj.name.Replace(" ", "-"); cat.discription = obj.discription; cat.name = obj.name; context.SaveChanges(); } catch (Exception ex) { check = false; } return check; }
public ActionResult Save(ExtendedCategory obj) { bool check = true; if (Request.IsAuthenticated) { if (obj.id > 0) { check = CategoryDal.Update(obj); } else { check=CategoryDal.Create(obj); } if (check) { TempData["message"] = "Saved successfully"; } else { TempData["message"] = "Error while saving data"; } return RedirectToAction("Create","Category"); } else { return RedirectToAction("index", "home"); } }