public ActionResult ImageUpload(UploadModel picture, PictureModel p_model, Category c_model)
        {
            string fileExt = Path.GetExtension(picture.File.FileName);
            var filename = Path.GetFileName(picture.File.FileName);
            bool DatabaseFilename = (from name in db2.Picture
                                   where name.File_name == filename
                                   select name).Any();

            if (picture.File.ContentLength > 0 &&picture.File.ContentLength < 204800 && (fileExt == "jpeg." || fileExt == ".jpg") && DatabaseFilename == false)
            {
                //THUMBNAIL GENERATOR
                string thumbpad = Server.MapPath("~/Images/Categories/" + p_model.Category + "/Thumbnails/" + picture.File.FileName);
                Directory.CreateDirectory(Server.MapPath("~/Images/Categories/" + p_model.Category + "/Thumbnails/"));
                Image Thumb = makeThumb(picture.File, true);
                SaveJpeg(thumbpad, Thumb);

                //PREVIEW GENERATOR
                var PreviewPath = Server.MapPath("~/Images/Categories/" + p_model.Category + "/Previews/" + picture.File.FileName);
                Directory.CreateDirectory(Server.MapPath("~/Images/Categories/" + p_model.Category + "/Previews/"));
                Image Preview = makeThumb(picture.File, false);
                SaveJpeg(PreviewPath, Preview);

                p_model.File_name = filename;
                p_model.CTime = DateTime.Now;
                p_model.MTime = DateTime.Now;

                if (Preview.Width >= Preview.Height)
                    p_model.Orientation = "horizontal";
                else
                    p_model.Orientation = "vertical";

                //Actual image upload
                Image image = Image.FromStream(picture.File.InputStream,true,true);
                var path = Server.MapPath("~/Images/Categories/" + p_model.Category + "/" + filename);
                SaveJpeg(path, image);

                db2.Picture.Add(p_model);
                db2.SaveChanges();
            }
            else
            {
                if (DatabaseFilename == true)
                    return Json("The filename " + filename + " is already used. Please provide an other filename.");
                return Json("There was an error processing your file, please only upload JPG and JPEG images.");
            }
            return RedirectToAction("ImageIndex");
        }
        public ActionResult CategoryCreate(Category category)
        {
            if (ModelState.IsValid)
            {
                var intermediate = from cato in dbcategories.Categories
                                   where cato.Name == category.Name
                                   select cato;
                if (intermediate.Count() == 0)
                {
                    dbcategories.Categories.Add(category);
                    dbcategories.SaveChanges();
                    string pad = Server.MapPath("~/Images/Categories/" + category.Name);
                    Directory.CreateDirectory(pad);
                }

                return RedirectToAction("CategoryIndex");

            }

            return View(category);
        }
 /// <summary>
 /// shows a list of categories for the imageupload.
 /// </summary>
 /// <returns>List in ImageUpload</returns>
 public ActionResult ImageUpload()
 {
     Category c = new Category();
     return View(dbcategories.Categories.ToList());
 }