Exemplo n.º 1
0
        public ActionResult Edit(ProductViewModel model)
        {
            try
            {
                G2BPMDataContext context = new G2BPMDataContext();
                Product          product = context.Products.FirstOrDefault(i => i.Id == model.Id);

                product.Title     = model.Title;
                product.ShortDesc = model.ShortDesc;
                product.FullDesc  = model.FullDesc;

                // Check image is uploaded or not.
                // If uploaded, add/change image.
                // If not, leave old image there, no change.
                if (model.ImageUrl != null)
                {
                    product.ImageUrl = model.ImageUrl;
                }

                context.SubmitChanges();

                return(Json(new { success = true }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, error = e.Message }));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(ProductViewModel model)
        {
            try
            {
                G2BPMDataContext context = new G2BPMDataContext();

                Product product = new Product()
                {
                    Title     = model.Title,
                    ShortDesc = model.ShortDesc,
                    FullDesc  = model.FullDesc
                };

                // Check image is uploaded or not.
                // If uploaded, add/change image.
                // If not, leave old image there, no change.
                if (model.ImageUrl != null)
                {
                    product.ImageUrl = model.ImageUrl;
                }

                context.Products.InsertOnSubmit(product);
                context.SubmitChanges();

                // Auto create test product
                //AutoCreateProduct();

                return(Json(new { success = true }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, error = e.Message }));
            }
        }
Exemplo n.º 3
0
        public ActionResult Details(int id)
        {
            try
            {
                G2BPMDataContext context = new G2BPMDataContext();
                Product          product = context.Products.FirstOrDefault(i => i.Id == id);
                ProductViewModel pVM     = MappingMethod(product);

                return(View(pVM));
            }
            catch (Exception e)
            {
                return(View());
            }
        }
Exemplo n.º 4
0
        public ActionResult ListAll()
        {
            List <ProductViewModel> ListProductVMs = new List <ProductViewModel>();

            G2BPMDataContext context      = new G2BPMDataContext();
            List <Product>   ListProducts = context.Products.ToList();

            foreach (Product product in ListProducts)
            {
                ProductViewModel pVM = MappingMethod(product);
                ListProductVMs.Add(pVM);
            }

            TempData["ErrorMessageOfDelete"] = "";
            return(View(ListProductVMs));
        }
Exemplo n.º 5
0
        private void AutoCreateProduct()
        {
            G2BPMDataContext context = new G2BPMDataContext();

            for (int i = 1; i <= 24; i++)
            {
                Product s = new Product()
                {
                    Title     = "auto-create-" + i,
                    ImageUrl  = "",
                    ShortDesc = "auto-create-product",
                    FullDesc  = "auto-create-product-auto-create-product-auto-create-product-auto-create-product-auto-create-product"
                };
                context.Products.InsertOnSubmit(s);
            }

            context.SubmitChanges();
        }
Exemplo n.º 6
0
        public ActionResult Delete(int id)
        {
            try
            {
                G2BPMDataContext context = new G2BPMDataContext();
                Product          product = context.Products.FirstOrDefault(i => i.Id == id);
                context.Products.DeleteOnSubmit(product);
                context.SubmitChanges();

                TempData["ErrorMessageOfDelete"] = "";
                return(RedirectToAction("ListAll"));
            }
            catch (Exception e)
            {
                TempData["ErrorMessageOfDelete"] = "Couldn't deleted the product. Error: " + e.Message;
                return(RedirectToAction("ListAll"));
            }
        }
Exemplo n.º 7
0
        public ActionResult Edit(int id)
        {
            try
            {
                ProductViewModel pVM     = new ProductViewModel();
                G2BPMDataContext context = new G2BPMDataContext();

                if (id > 0)
                {
                    Product product = context.Products.FirstOrDefault(i => i.Id == id);
                    pVM = MappingMethod(product);
                }

                return(View(pVM));
            }
            catch (Exception e)
            {
                return(View());
            }
        }