public ActionResult Save(LengthModel obj) { bool check = true; if (Request.IsAuthenticated) { if (obj.id > 0) { check = LengthDal.Update(obj); } else { check = LengthDal.Create(obj); } if (check) { TempData["message"] = "Saved successfully"; } else { TempData["message"] = "Error while saving data"; } return RedirectToAction("Create", "Length"); } else { return RedirectToAction("index", "home"); } }
public static List<LengthModel> GetAllLengthByProductId(int id) { List<LengthModel> returnObj = new List<LengthModel>(); var context = new Ecommerce.DbEntity.ecommerceEntities(); var cat = context.productpricings.Where(m => m.productid == id).ToList(); foreach (var x in cat) { var length = new LengthModel(); length.id = Convert.ToInt32(x.lengthId); length.value = GetById(Convert.ToInt32(x.lengthId)).value; length.IsSelected = true; if (returnObj.Count == 0) { returnObj.Add(length); } else { if (returnObj.Where(m => m.id == x.lengthId).FirstOrDefault() == null) { returnObj.Add(length); } } } return returnObj.Distinct().ToList(); }
public ActionResult Create() { if (Request.IsAuthenticated) { ViewBag.PageTittle = "Add Length"; ViewBag.breadCrum = "<a href='/Admin/Length/index'>Length</a> >> Add Length"; LengthModel obj = new LengthModel(); return View(obj); } else { return RedirectToAction("index", "home"); } }
public ActionResult Edit(int id) { if (Request.IsAuthenticated) { ViewBag.PageTittle = "Edit Length"; ViewBag.breadCrum = "<a href='/Admin/Length/index'>Length</a> >> Edit Length"; LengthModel obj = new LengthModel(); obj = LengthDal.GetById(id); return View("Create", obj); } else { return RedirectToAction("index", "home"); } }
public static bool Create(LengthModel obj) { bool check = true; try { var context = new Ecommerce.DbEntity.ecommerceEntities(); context.lengths.Add(new DbEntity.length { value = obj.value + " " + "inch" }); context.SaveChanges(); } catch (Exception ex) { check = false; } return check; }
//public static bool Delete(int id) //{ // bool check = true; // try // { // var context = new Ecommerce.DbEntity.ecommerceEntities(); // var cat = context.lengths.Where(m => m.id == id).FirstOrDefault(); // var productPrices = context.productpricings.Where(m => m.LengthId == id).ToList(); // foreach (var x in productPrices) // { // check = ProductPricingDal.Delete(x.id); // if (check == false) // { // break; // } // } // if (check) // { // context.lengths.Remove(cat); // context.SaveChanges(); // } // } // catch (Exception ex) // { // check = false; // } // return check; //} public static List<LengthModel> GetAllLengthByProductIdForEditProduct(int id) { List<LengthModel> returnObj = new List<LengthModel>(); var context = new Ecommerce.DbEntity.ecommerceEntities(); var cat = context.productpricings.Where(m => m.productid == id).ToList(); foreach (var x in cat) { var length = new LengthModel(); length.id = Convert.ToInt32(x.lengthId); length.value = GetById(Convert.ToInt32(x.lengthId)).value; length.IsSelected = true; returnObj.Add(length); } return returnObj.ToList(); }
public static bool Update(LengthModel obj) { bool check = true; try { var context = new Ecommerce.DbEntity.ecommerceEntities(); var length = context.lengths.Where(m => m.id == obj.id).FirstOrDefault(); length.value = obj.value+" "+"inch"; context.SaveChanges(); } catch (Exception ex) { check = false; } return check; }
public static LengthModel GetById(int id) { var context = new Ecommerce.DbEntity.ecommerceEntities(); var col = context.lengths.Where(m => m.id == id).FirstOrDefault(); var length = new LengthModel(); length.id = col.id; length.value = col.value; return length; }