Exemplo n.º 1
0
        public ActionResult Create(Category_lang category)
        {
            Category origin = new Category();

            if (ModelState.IsValid)
            {
                //origin.ID = category.ID;
                if (category.ImageFile != null && category.ImageFile.FileName != null && category.ImageFile.FileName != "")
                {
                    FileInfo fi = new FileInfo(category.ImageFile.FileName);
                    if (fi.Extension != ".jpeg" && fi.Extension != ".jpg" && fi.Extension != ".png" && fi.Extension != ".JPEG" && fi.Extension != ".JPG" && fi.Extension != ".PNG")
                    {
                        TempData["Errormsg"] = "Image File Extension is Not valid";
                    }
                    else
                    {
                        string fileName  = Path.GetFileNameWithoutExtension(category.ImageFile.FileName);
                        string extension = Path.GetExtension(category.ImageFile.FileName);
                        fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        category.Image = "~/Content/images/Cat/" + fileName;
                        fileName       = Path.Combine(Server.MapPath("~/Content/images/Cat/"), fileName);
                        category.ImageFile.SaveAs(fileName);
                    }
                }
                origin.Parent_Id = category.temp;
                db.Categories.Add(origin);
                db.SaveChanges();
                category.category_ID = origin.ID;
                db.Category_lang.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public ActionResult Create(Category_lang category, string hiddenname)
        {
            if (ModelState.IsValid)
            {
                Category_lang cat = db.Category_lang.Find(category.ID);
                if (category.ImageFile != null)
                {
                    FileInfo fi = new FileInfo(category.ImageFile.FileName);
                    if (fi.Extension != ".jpeg" && fi.Extension != ".jpg" && fi.Extension != ".png" && fi.Extension != ".JPEG" && fi.Extension != ".JPG" && fi.Extension != ".PNG")
                    {
                        TempData["Errormsg"] = "Image File Extension is Not valid";
                    }
                    else
                    {
                        string fileName  = Path.GetFileNameWithoutExtension(category.ImageFile.FileName);
                        string extension = Path.GetExtension(category.ImageFile.FileName);
                        fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        category.Image = "~/Content/images/Cat/" + fileName;
                        fileName       = Path.Combine(Server.MapPath("~/Content/images/Cat/"), fileName);
                        category.ImageFile.SaveAs(fileName);
                    }
                }
                else
                {
                    category.Image = cat.Image;
                }
                //category.category_ID
                db.Category_lang.Add(category);
                db.SaveChanges();
                int CatId = Convert.ToInt32(TempData["Data"]);
                return(RedirectToAction("Index", "Category_lang", new { id = CatId }));
            }

            return(View(category));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Category_lang category_lang = db.Category_lang.Find(id);

            db.Category_lang.Remove(category_lang);
            db.SaveChanges();
            int catlang = Convert.ToInt32(TempData["Data"]);

            return(RedirectToAction("Index", new { id = catlang }));
        }
Exemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id = 0)
        {
            Category_lang category = db.Category_lang.Find(id);
            Category      cat_per  = db.Categories.Find(category.category_ID);

            db.Categories.Remove(cat_per);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        //
        // GET: /Category_lang/Details/5

        public ActionResult Details(int id = 0, int catlang = 0)
        {
            Category_lang category_lang = db.Category_lang.Find(id);

            ViewBag.catlang = catlang;
            if (category_lang == null)
            {
                return(HttpNotFound());
            }
            return(View(category_lang));
        }
Exemplo n.º 6
0
        //
        // GET: /Category/Details/5

        public ActionResult Details(int id = 0)
        {
            Category_lang category = db.Category_lang.Find(id);

            //var category = db.Category_lang.Where(x => x.Lang_ID == idLan && x.category_ID == idCat);
            if (category == null)
            {
                return(HttpNotFound());
            }
            return(View(category));
        }
        //
        // GET: /Category_lang/

        public ActionResult Index(int id = 0)
        {
            Category_lang        cat      = db.Category_lang.Find(id);
            int                  cat_ID   = (int)cat.category_ID;
            List <Language>      lang     = db.Language.Where(x => x.Default == false).ToList();
            List <Category_lang> category = new List <Category_lang>();

            foreach (Language obj in lang)
            {
                List <Category_lang> CatLang = db.Category_lang.Where(x => x.Lang_ID.Value.Equals(obj.ID) && x.category_ID == cat_ID).ToList();
                category.AddRange(CatLang);
            }
            ViewBag.Cat_lang = id;
            return(View(category));
        }
Exemplo n.º 8
0
        //
        // GET: /Category/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Category_lang category = db.Category_lang.Find(id);
            Category      cat_per  = db.Categories.Find(category.category_ID);

            category.temp = cat_per.Parent_Id;

            List <Category_lang> men = db.Category_lang.ToList();

            ViewBag.parentlist = new SelectList(men, "category_ID", "Name");


            if (category == null)
            {
                return(HttpNotFound());
            }
            return(View(category));
        }
Exemplo n.º 9
0
        //
        // GET: /Category/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ViewBag.flag = false;
            Category_lang category = db.Category_lang.Find(id);
            Category      cat_per  = db.Categories.Find(category.category_ID);

            Category cat = db.Categories.SingleOrDefault(x => x.Parent_Id == cat_per.ID);

            if (cat != null)
            {
                ViewBag.error = "This Category is a Perant to another Category, So You can not delete it";
                ViewBag.flag  = true;
            }
            if (category == null)
            {
                return(HttpNotFound());
            }
            return(View(category));
        }
        //
        // GET: /Category_lang/Create

        public ActionResult Create(int id = 0)
        {
            Category_lang category_lang = db.Category_lang.Find(id);

            ViewBag.CatID = category_lang.category_ID;

            List <Language> lang     = db.Language.Where(x => x.Default == false).ToList();
            List <Language> language = new List <Language>();

            foreach (Language obj in lang)
            {
                Category_lang catLang = db.Category_lang.Where(x => x.Lang_ID.Value.Equals(obj.ID) && x.category_ID == category_lang.category_ID).SingleOrDefault();
                if (catLang == null)
                {
                    language.Add(obj);
                }
            }
            ViewBag.Lang_ID = new SelectList(language, "ID", "Name");
            ViewBag.catlang = id;
            return(View(category_lang));
        }
Exemplo n.º 11
0
 public ActionResult Edit(Category_lang category)
 {
     if (ModelState.IsValid)
     {
         Category_lang cat = db.Category_lang.Find(category.ID);
         category.category_ID = cat.category_ID;
         category.Lang_ID     = cat.Lang_ID;
         Category cat_per = db.Categories.Find(category.category_ID);
         cat_per.Parent_Id = category.temp;
         if (category.ImageFile != null)
         {
             FileInfo fi = new FileInfo(category.ImageFile.FileName);
             if (fi.Extension != ".jpeg" && fi.Extension != ".jpg" && fi.Extension != ".png" && fi.Extension != ".JPEG" && fi.Extension != ".JPG" && fi.Extension != ".PNG")
             {
                 TempData["Errormsg"] = "Image File Extension is Not valid";
             }
             else
             {
                 string fileName  = Path.GetFileNameWithoutExtension(category.ImageFile.FileName);
                 string extension = Path.GetExtension(category.ImageFile.FileName);
                 fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                 category.Image = "~/Content/images/Cat/" + fileName;
                 fileName       = Path.Combine(Server.MapPath("~/Content/images/Cat/"), fileName);
                 category.ImageFile.SaveAs(fileName);
             }
         }
         else
         {
             category.Image = cat.Image;
         }
         //db.Entry(category).State = EntityState.Modified;
         db.Entry(cat).CurrentValues.SetValues(category);
         db.Entry(cat_per).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }