Пример #1
0
        //
        // GET: /Admin/
        public ActionResult Index()
        {
            db_ImageDecor ctx = new db_ImageDecor();
            AdminHomeViewModel model = new AdminHomeViewModel();
            model.images = ctx.Images.ToList();

            return View(model);
        }
Пример #2
0
        public ActionResult Gallery(int s=0)
        {
            db_ImageDecor ctx = new db_ImageDecor();
            GalleryViewModel model = new GalleryViewModel();
            model.categories = ctx.Categories.ToList();
            model.images = ctx.Images.ToList();
            model.SelectedCategory = s;

            return View(model);
        }
        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 CatDropDown(int sel=0)
        {
            db_ImageDecor ctx = new db_ImageDecor();
            CategoryListViewModel model = new CategoryListViewModel();
            model.categories = ctx.Categories.ToList();
            if (sel != 0)
            {
                model.selectedCat = sel;
            }

            return PartialView(model);
        }
Пример #6
0
        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();

            }
        }
        //
        // GET: /Categories/
        public ActionResult Index()
        {
            CategoryViewModel model = new CategoryViewModel();
            db_ImageDecor ctx = new db_ImageDecor();

            model.categories = ctx.Categories.ToList();

            return View(model);
        }
        public ActionResult Edit(int id)
        {
            db_ImageDecor ctx = new db_ImageDecor();

            return View(ctx.Categories.Where(x=>x.id == id).FirstOrDefault());
        }
Пример #9
0
        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");
        }
Пример #10
0
        public ActionResult Delete(int id)
        {
            db_ImageDecor ctx = new db_ImageDecor();

            return View(ctx.Images.Where(x => x.id == id).FirstOrDefault());
        }
Пример #11
0
        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");
        }