public ActionResult Edit(FormCollection collection)
        {
            int id = Convert.ToInt32(collection["id"]);
            db_ImageDecor ctx = new db_ImageDecor();
            var cat = ctx.Categories.Where(x => x.id == id).FirstOrDefault();
            cat.category = collection["category"];

            ctx.SaveChanges();

            return RedirectToAction("Index","Categories");
        }
        public ActionResult Create(FormCollection collection)
        {
            db_ImageDecor ctx = new db_ImageDecor();
            Categories cat = new Categories();
            cat.category = collection["category"];

            ctx.Categories.Add(cat);
            ctx.SaveChanges();

            return RedirectToAction("Index", "Categories");
        }
        public ActionResult Create(FormCollection collection, HttpPostedFileBase[] Imagefiles)
        {
            try
            {
                db_ImageDecor ctx = new db_ImageDecor();
                /*Loop for multiple files*/
                foreach (HttpPostedFileBase file in Imagefiles)
                {
                    Images model = new Images();

                    /*Geting the file name*/
                    string filename = System.IO.Path.GetFileName(file.FileName);
                    /*Saving the file in server folder*/
                    file.SaveAs(Server.MapPath("~/img/Gallery/" + filename));
                    string filepathtosave = "/img/Gallery/" + filename;

                    string fileExtention = file.ContentType;
                    int fileLenght = file.ContentLength;
                    if (fileExtention == "image/png" || fileExtention == "image/jpeg" || fileExtention == "image/x-png")
                    {
                        //if (fileLenght <= 1048576)
                        //{
                            System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(file.InputStream);
                            System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 200);

                            objImage.Save(Server.MapPath("/img/Gallery/thumbnails/" + filename), ImageFormat.Png);
                            model.thumbnailPath = "/img/Gallery/thumbnails/" + filename;
                        //}
                    }
                    model.imageName = filename;
                    model.imagePath = filepathtosave;
                    model.categoryID = Convert.ToInt32(collection["category"].ToString());
                    ctx.Images.Add(model);

                }
                ctx.SaveChanges();
                ViewBag.Message = "File Uploaded successfully.";
                //return RedirectToAction("Index", "Admin");
                return View();

            }
            catch(Exception ex)
            {
                ViewBag.Message = "Error while uploading the files. ex:" +ex.Message;
                return View();

            }
        }
        public ActionResult Delete(FormCollection collection)
        {
            int id = Convert.ToInt32(collection["id"].ToString());
            db_ImageDecor ctx = new db_ImageDecor();

            var image = ctx.Images.Where(x => x.id == id).FirstOrDefault();
            System.IO.File.Delete(Server.MapPath("/img/Gallery/" + image.imageName));
            System.IO.File.Delete(Server.MapPath("/img/Gallery/thumbnails/" + image.imageName));

            ctx.Images.Remove(image);
            ctx.SaveChanges();

            return RedirectToAction("Index", "Admin");
        }
        public ActionResult Edit(FormCollection collection, HttpPostedFileBase Imagefiles)
        {
            if (!string.IsNullOrEmpty(collection["id"]))
            {
                int id = Convert.ToInt32(collection["id"]);
                db_ImageDecor ctx = new db_ImageDecor();
                var image = ctx.Images.Where(x => x.id == id).FirstOrDefault();
                image.categoryID = Convert.ToInt32(collection["category"].ToString());
                if (Imagefiles != null)
                {
                    System.IO.File.Delete(Server.MapPath("/img/Gallery/" + image.imageName));

                    string filename = System.IO.Path.GetFileName(Imagefiles.FileName);
                    image.imageName = System.IO.Path.GetFileName(Imagefiles.FileName);
                    Imagefiles.SaveAs(Server.MapPath("~/img/Gallery/" + filename));

                    string fileExtention = Imagefiles.ContentType;
                    int fileLenght = Imagefiles.ContentLength;
                    if (fileExtention == "image/png" || fileExtention == "image/jpeg" || fileExtention == "image/x-png")
                    {
                        //if (fileLenght <= 1048576)
                        //{
                        System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(Imagefiles.InputStream);
                        System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 200);
                        objImage.Save(Server.MapPath("/img/Gallery/thumbnails/" + filename), ImageFormat.Png);
                        image.thumbnailPath = "/img/Gallery/thumbnails/" + filename;
                        //}
                    }

                    string filepathtosave = "/img/Gallery/" + filename;
                    image.imagePath = filepathtosave;
                }

                ctx.SaveChanges();
            }

            return RedirectToAction("Index", "Admin");
        }