// GET: ProductSubCategories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblProductSubCategory tblProductSubCategory = db.tblProductSubCategories.Find(id);
            tblUser objSource = (tblUser)Session["UserDetails"];

            if (tblProductSubCategory == null)
            {
                return(HttpNotFound());
            }
            else
            {
                tblProductSubCategory.IsActive        = false;
                tblProductSubCategory.UpdatedBy       = objSource.Id;
                tblProductSubCategory.UpdatedOn       = DateTime.Now;
                db.Entry(tblProductSubCategory).State = EntityState.Modified;
                db.SaveChanges();
                var tblProductSubCategories = db.tblProductSubCategories.Include(t => t.tblProductCategory);
                return(RedirectToAction("Index", tblProductSubCategories.ToList()));
            }
            //return View(tblProductSubCategory);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            tblProductSubCategory tblProductSubCategory = db.tblProductSubCategories.Find(id);

            db.tblProductSubCategories.Remove(tblProductSubCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "ProductSubCategoryID,ProductCategoryID,SubCategoryName,Description,IsActive,CreatedOn,UpdatedOn,CreatedBy,UpdatedBy")] tblProductSubCategory tblProductSubCategory)
        {
            ViewBag.ProductCategoryID = new SelectList(db.tblProductCategories, "ProductCategoryID", "CategoryName");
            if (ModelState.IsValid)
            {
                tblUser objSource = (tblUser)Session["UserDetails"];
                tblProductSubCategory.CreatedBy = objSource.Id;
                tblProductSubCategory.CreatedOn = DateTime.Now;
                tblProductSubCategory.IsActive  = true;
                db.tblProductSubCategories.Add(tblProductSubCategory);
                db.SaveChanges();
                TempData["Success"] = "Sub Category added successfully.";
                ViewBag.SubCategory = new tblProductSubCategory();
                return(RedirectToAction("Index"));
            }
            ViewBag.SubCategory = new tblProductSubCategory();
            var tblProductSubCategories = db.tblProductSubCategories.Include(t => t.tblProductCategory);

            return(View("Index", tblProductSubCategories.ToList()));
        }
        // GET: ProductSubCategories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblProductSubCategory tblProductSubCategory = db.tblProductSubCategories.Find(id);

            if (tblProductSubCategory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductCategoryID = new SelectList(db.tblProductCategories, "ProductCategoryID", "CategoryName", tblProductSubCategory.ProductCategoryID);
            ViewBag.SubCategory       = tblProductSubCategory;
            var tblProductSubCategories = db.tblProductSubCategories.Include(t => t.tblProductCategory);

            return(View("Index", tblProductSubCategories.ToList()));

            //ViewBag.ProductCategoryID = new SelectList(db.tblProductCategories, "ProductCategoryID", "CategoryName", tblProductSubCategory.ProductCategoryID);
            //return View(tblProductSubCategory);
        }
Пример #5
0
    private bool Delete(int intPKID)
    {
        bool retval = false;

        objProduct = new tblProduct();
        if (objProduct.IsProductInOrder(intPKID.ToString()))
        {
            return(retval);
        }

        if (objProduct.LoadByPrimaryKey(intPKID))
        {
            tblPixcelCode objPixelCode = new tblPixcelCode();
            objPixelCode.Where.AppProductId.Value = intPKID;
            objPixelCode.Query.Load();
            if (objPixelCode.RowCount > 0)
            {
                objPixelCode.DeleteAll();
                objPixelCode.Save();
            }
            objPixelCode = null;

            tblProductSubCategory objProductSubCategory = new tblProductSubCategory();
            objProductSubCategory.Where.AppProductID.Value = intPKID;
            objProductSubCategory.Query.Load();
            if (objProductSubCategory.RowCount > 0)
            {
                objProductSubCategory.DeleteAll();
                objProductSubCategory.Save();
            }
            objProductSubCategory = null;

            tblRelatedProduct objRelatedProduct = new tblRelatedProduct();
            objRelatedProduct.Where.AppProductID.Value = intPKID;
            objRelatedProduct.Query.Load();
            if (objRelatedProduct.RowCount > 0)
            {
                objRelatedProduct.DeleteAll();
                objRelatedProduct.Save();
            }
            objRelatedProduct = null;

            tblProductProperty objProductProperty = new tblProductProperty();
            objProductProperty.Where.AppProductID.Value = intPKID;
            objProductProperty.Query.Load();
            if (objProductProperty.RowCount > 0)
            {
                objProductProperty.DeleteAll();
                objProductProperty.Save();
            }
            objProductProperty = null;

            tblProductColor objProductColor = new tblProductColor();
            objProductColor.Where.AppProductID.Value = intPKID;
            objProductColor.Query.Load();
            if (objProductColor.RowCount > 0)
            {
                while (!(objProductColor.EOF))
                {
                    tblProductDetail objProductDetail = new tblProductDetail();
                    objProductDetail.Where.AppProductColorID.Value = objProductColor.AppProductColorID;
                    objProductDetail.Query.Load();
                    if (objProductDetail.RowCount > 0)
                    {
                        objProductDetail.DeleteAll();
                        objProductDetail.Save();
                    }
                    objProductDetail = null;

                    tblProductImage objProductImage = new tblProductImage();
                    objProductImage.Where.AppProductColorID.Value = objProductColor.AppProductColorID;
                    objProductImage.Query.Load();
                    if (objProductImage.RowCount > 0)
                    {
                        //while(! objProductImage.EOF )
                        //{
                        //    if (System.IO.File.Exists(Server.MapPath(objProductImage.s_AppLargeImage )))
                        //    {
                        //        System.IO.File.Delete(Server.MapPath(objProductImage.s_AppLargeImage));
                        //    }
                        //    if (System.IO.File.Exists(Server.MapPath(objProductImage.s_AppNormalImage)))
                        //    {
                        //        System.IO.File.Delete(Server.MapPath(objProductImage.s_AppNormalImage));
                        //    }
                        //    if (System.IO.File.Exists(Server.MapPath(objProductImage.s_AppSmallImage)))
                        //    {
                        //        System.IO.File.Delete(Server.MapPath(objProductImage.s_AppSmallImage));
                        //    }
                        //    if (System.IO.File.Exists(Server.MapPath(objProductImage.s_AppThumbImage)))
                        //    {
                        //        System.IO.File.Delete(Server.MapPath(objProductImage.s_AppLargeImage));
                        //    }
                        //    objProductImage.MoveNext();
                        //}
                        objProductImage.DeleteAll();
                        objProductImage.Save();
                    }
                    objProductImage = null;


                    objProductColor.MoveNext();
                }
                objProductColor.DeleteAll();
                objProductColor.Save();
            }
            objProductColor = null;

            string StrFolder = "Uploads/Product/" + objProduct.s_AppProductID + "/";

            if (System.IO.Directory.Exists(Server.MapPath("~/admin/" + StrFolder)))
            {
                System.IO.Directory.Delete(Server.MapPath("~/admin/" + StrFolder), true);
            }

            objProduct.MarkAsDeleted();
            objProduct.Save();
        }

        retval     = true;
        objProduct = null;
        return(retval);
    }