示例#1
0
        public ActionResult editCat(int?id)
        {
            edit_category_vm catVM = new edit_category_vm();

            if (id == null)
            {
                message = "Your Action is Wrong";
            }
            else
            {
                category_tbl cat_tbl = db.category_tbl.Find(id);
                if (cat_tbl == null)
                {
                    message = "No Data Found";
                }
                else
                {
                    catVM.serial       = cat_tbl.category_id;
                    catVM.CategoryName = cat_tbl.cat_name;
                    catVM.LogoV        = cat_tbl.logo;
                    catVM.BannerV      = cat_tbl.banner;
                    catVM.parentID     = cat_tbl.parent_id;
                    catVM.top_cat      = cat_tbl.top_cat;
                    catVM.sort_order   = cat_tbl.sort_order;
                    catVM.status       = cat_tbl.status;
                    catVM.videoLink    = cat_tbl.VideoLink;
                    ViewBag.parentCat  = new SelectList(db.category_tbl.ToList(), "category_id", "cat_name");
                    return(PartialView(catVM));
                }
            }

            TempData["Message"] = message;
            return(RedirectToAction("manageCat"));
        }
示例#2
0
        // GET: Category by products
        public ActionResult products(int?id)
        {
            var products = new product();
            var cates    = new List <category_tbl>();
            //if(!string.IsNullOrEmpty(Session.SessionID))

            List <product_tbl> p = new List <product_tbl>();

            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                var cs = db.category_tbl.Find(id);
                ViewBag.baner = cs.banner;
                ViewBag.video = cs.VideoLink;
                var getProduct = db.product_to_category_tbl.Where(a => a.category_id == id).ToList();
                foreach (var t in getProduct)
                {
                    p.Add(db.product_tbl.Find(t.product_id));
                }

                // bag data
                ViewBag.varient_search = varient_search(id);

                //get min price
                ViewBag.minP = p.Select(asd => asd.price).Min();
                //get max price
                ViewBag.maxP = p.Select(a => a.price).Max();
                var cat = db.category_tbl.Where(a => a.parent_id == id).ToList();
                if (cat.Count > 0)
                {
                    foreach (var c in cat)
                    {
                        var category = new category_tbl();
                        category.category_id = c.category_id;
                        category.parent_id   = c.parent_id;
                        category.logo        = c.logo;
                        category.VideoLink   = c.VideoLink;
                        category.sort_order  = c.sort_order;
                        category.cat_name    = c.cat_name;
                        category.banner      = c.banner;
                        cates.Add(category);
                    }
                    products.proCategory = cates;
                }

                if (getProduct.Count > 0)
                {
                    commonWork(id);
                    return(View(products));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
        }
示例#3
0
        public ActionResult editCat(edit_category_vm cat, HttpPostedFileBase logo, HttpPostedFileBase banner)
        {
            string       path    = "";
            category_tbl cat_tbl = new category_tbl();

            if (cat.CategoryName != null)
            {
                cat_tbl = db.category_tbl.Find(cat.serial);

                if (cat.logo != null && cat_tbl.logo != cat.logo.FileName)
                {
                    if (cat_tbl.logo != null)
                    {
                        string fullPath = Request.MapPath("~/AppFiles/Cat/" + cat_tbl.logo);
                        if (System.IO.File.Exists(fullPath))
                        {
                            try
                            {
                                System.IO.File.Delete(fullPath);
                            }
                            catch (Exception e)
                            {
                                //Debug.WriteLine(e.Message);
                            }
                        }
                    }
                    //delete logo form system fileFolder

                    //save the new logo
                    string fileName  = Path.GetFileNameWithoutExtension(logo.FileName);
                    string extension = Path.GetExtension(logo.FileName);
                    fileName = "L" + cat.serial + extension;
                    fileName = fileName.Replace(" ", "-");
                    path     = fileName;
                    string savePath = Server.MapPath("~/AppFiles/Cat/");
                    logo.SaveAs(Path.Combine(savePath, fileName));
                    cat_tbl.logo = path;
                }// manage cat logo


                if (cat.banner != null && cat_tbl.banner != cat.banner.FileName)
                {
                    if (cat_tbl.banner != null)
                    {
                        string fullPath = Request.MapPath("~/AppFiles/Cat/" + cat_tbl.banner);
                        if (System.IO.File.Exists(fullPath))
                        {
                            try
                            {
                                System.IO.File.Delete(fullPath);
                            }
                            catch (Exception e)
                            {
                                //Debug.WriteLine(e.Message);
                            }
                        }
                    }//delete the banner form filefolder

                    string fileName  = Path.GetFileNameWithoutExtension(banner.FileName);
                    string extension = Path.GetExtension(banner.FileName);
                    fileName = "B" + cat.serial + extension;
                    fileName = fileName.Replace(" ", "-");
                    path     = fileName;
                    string savePath = Server.MapPath("~/AppFiles/Cat/");
                    banner.SaveAs(Path.Combine(savePath, fileName));
                    cat_tbl.banner = path;
                }

                cat_tbl.category_id   = cat.serial;
                cat_tbl.cat_name      = cat.CategoryName;
                cat_tbl.date_modified = DateTime.Now;
                cat_tbl.Entry_by      = User.Identity.GetUserId();
                cat_tbl.parent_id     = cat.parentID;
                cat_tbl.sort_order    = cat.sort_order;
                cat_tbl.status        = cat.status;
                cat_tbl.top_cat       = cat.top_cat;
                cat_tbl.VideoLink     = cat.videoLink;

                db.Entry(cat_tbl).State = EntityState.Modified;
                db.SaveChanges();

                message = "Category Updated Successfully";
                status  = true;
            }
            else
            {
                message = "Thare have some problems.try agine";
            }



            TempData["Status"]  = status;
            TempData["Message"] = message;
            return(RedirectToAction("manageCat"));
        }
示例#4
0
        public ActionResult createCat(create_category_vm cat, HttpPostedFileBase logo, HttpPostedFileBase banner)
        {
            category_tbl cat_tbl = new category_tbl();

            string path;

            cat_tbl.cat_name   = cat.cat_name;
            cat_tbl.Entry_by   = User.Identity.GetUserId();
            cat_tbl.date_added = DateTime.Now;
            cat_tbl.parent_id  = cat.Parent_id;
            cat_tbl.sort_order = 0;
            cat_tbl.status     = true;
            cat_tbl.VideoLink  = cat.videoLink;
            cat_tbl.top_cat    = cat.top_cat;
            db.category_tbl.Add(cat_tbl);
            db.SaveChanges();


            var cat_Id = db.category_tbl.Find(cat_tbl.category_id);

            if (cat.cat_name != null)
            {
                if (cat.logo != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(logo.FileName);
                    string extension = Path.GetExtension(logo.FileName);
                    fileName = "L" + cat_Id.category_id + extension;
                    fileName = fileName.Replace(" ", "-");

                    path = fileName;

                    string savePath = Server.MapPath("~/AppFiles/Cat/");
                    logo.SaveAs(Path.Combine(savePath, fileName));


                    cat_tbl.logo = path;
                }
                else
                {
                    cat_tbl.logo = "download.png";
                }


                if (cat.banner != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(banner.FileName);
                    string extension = Path.GetExtension(banner.FileName);
                    fileName = "B" + cat_Id.category_id + extension;;
                    fileName = fileName.Replace(" ", "-");

                    path = fileName;

                    string savePath = Server.MapPath("~/AppFiles/Cat/");
                    banner.SaveAs(Path.Combine(savePath, fileName));
                    cat_tbl.banner = path;
                }
                else
                {
                    cat_tbl.banner = "download.png";
                }

                db.SaveChanges();
                message = "Save Success Fully";
                status  = true;
            }
            else
            {
                message = "Your Entry Is Wrong";
            }

            TempData["Status"]  = status;
            TempData["Message"] = message;
            return(RedirectToAction("manageCat"));
        }