public List<ProductsListModel> GenerateProductsListModel() { List<ProductsListModel> plmList = new List<ProductsListModel>(); ProductsListModel plm = new ProductsListModel(); try { using (VenturadaDataContext vdc = new VenturadaDataContext()) { var productsList = from p in vdc.ProductsLists.ToList() orderby p.ProductId ascending select p; foreach (var item in productsList) { plm = new ProductsListModel(); plm.ProductsId = item.ProductId; plm.MainDescription = item.MainDescription; plm.DetailsDescription = item.DetailsDescription; plmList.Add(plm); } return plmList; } } catch (Exception ex) { throw ex; } }
public ActionResult Add(ProductsListModel plm) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ProductsDataService dataService = new ProductsDataService(); try { if (ModelState.IsValid) { dataService.InsertProductList(plm); return RedirectToAction("Edit", "Products"); } else { return View(plm); } } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public ActionResult EditProduct(ProductsListModel plm) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ProductsDataService dataService = new ProductsDataService(); try { string id = (string)Request.Form["edit_ProductsId"]; if (ModelState.IsValid) { plm.ProductsId = int.Parse(id); dataService.UpdateProductList(plm); return RedirectToAction("Edit", "Products"); } else { plm = new ProductsListModel(); plm.ProductsId = int.Parse(id); return View(plm); } } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public ActionResult EditProduct(int productId) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ProductsListModel model = new ProductsListModel(); ProductsDataService dataService = new ProductsDataService(); try { model = dataService.GetProductsListModelByProductId(productId); return View(model); } catch (Exception ex) { throw ex; } finally { model = null; dataService = null; } }
public void UpdateProductList(ProductsListModel aum) { try { ProductsList au = new ProductsList(); using (VenturadaDataContext vdc = new VenturadaDataContext()) { au = vdc.ProductsLists.Single(a => a.ProductId == aum.ProductsId); au.ProductId = aum.ProductsId; au.MainDescription = aum.MainDescription; au.DetailsDescription = aum.DetailsDescription; vdc.SubmitChanges(); } } catch (Exception ex) { throw ex; } }
public void InsertProductList(ProductsListModel plm) { try { using (VenturadaDataContext vdc = new VenturadaDataContext()) { ProductsList receivedPM = new ProductsList(); receivedPM.MainDescription = plm.MainDescription; receivedPM.DetailsDescription = plm.DetailsDescription; vdc.ProductsLists.InsertOnSubmit(receivedPM); vdc.SubmitChanges(); } } catch (Exception ex) { throw ex; } }
public ProductsListModel GetProductsListModelByProductId(int productId) { ProductsListModel model = new ProductsListModel(); try { using (VenturadaDataContext vdc = new VenturadaDataContext()) { var productsList = from p in vdc.ProductsLists.ToList() where p.ProductId == productId select p; model = new ProductsListModel(); model.ProductsId = productsList.FirstOrDefault().ProductId; model.MainDescription = productsList.FirstOrDefault().MainDescription; model.DetailsDescription = productsList.FirstOrDefault().DetailsDescription; return model; } } catch (Exception ex) { throw ex; } }