示例#1
0
        public ActionResult productUpdate(int id)
        {
            Products product = ctx.productBll.getOne(id);

            if (product != null)
            {
                productUpdateModel pModel = new productUpdateModel();
                pModel.Product    = product;
                pModel.Categories = ctx.categoryBll.getAll();
                return(View(pModel));
            }
            else
            {
                TempData["productUpdateError"] = "Güncellemek İstediğiniz Ürün Bulunamadı !";
                return(RedirectToAction("Index", "product", new { area = "AdminPanel" }));
            }
        }
示例#2
0
        public ActionResult productUpdate(Products pro, HttpPostedFileBase file)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Products product = ctx.productBll.getOne(pro.id);
                    if (product != null)
                    {
                        if (file != null)
                        {
                            if (System.IO.File.Exists(Server.MapPath(product.coverPicturePath)))
                            {
                                System.IO.File.Delete(Server.MapPath(product.coverPicturePath));
                            }

                            product.coverPicturePath = pictureController.pictureAddForProduct(file, HttpContext);
                            product.pictureAlt       = pro.pictureAlt;
                        }

                        product.name        = pro.name;
                        product.categoryID  = pro.categoryID;
                        product.caption     = pro.caption;
                        product.description = pro.description;
                        product.price       = pro.price;
                        bool resultUpdate = ctx.productBll.add(product);


                        if (resultUpdate)
                        {
                            return(RedirectToAction("Index", "product", new{ area = "AdminPanel" }));
                        }
                        else
                        {
                            productUpdateModel updateModel = new productUpdateModel();
                            updateModel.Categories         = ctx.categoryBll.getAll();
                            updateModel.Product            = pro;
                            TempData["productUpdateError"] = "Ürün Güncellenemedi Tekrar Deneyiniz !";
                            return(View(updateModel));
                        }
                    }
                    else
                    {
                        productUpdateModel updateModel = new productUpdateModel();
                        updateModel.Categories         = ctx.categoryBll.getAll();
                        updateModel.Product            = pro;
                        TempData["productUpdateError"] = "Ürün Bulunamadı!";

                        return(View(updateModel));
                    }
                }
                else
                {
                    productUpdateModel updateModel = new productUpdateModel();
                    updateModel.Categories         = ctx.categoryBll.getAll();
                    updateModel.Product            = pro;
                    TempData["productUpdateError"] = "Geçersiz Değer!";

                    return(View("productUpdate", updateModel));
                }
            }
            catch (Exception e)
            {
                productUpdateModel updateModel = new productUpdateModel();
                updateModel.Categories         = ctx.categoryBll.getAll();
                updateModel.Product            = pro;
                TempData["productUpdateError"] = e.Message;

                return(View(updateModel));
            }
        }