public ActionResult Upload(ImageMetaData imageMetaData)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var imageGallary = new ImagGallary();
                    var data = new byte[imageMetaData.File.ContentLength];
                    imageMetaData.File.InputStream.Read(data, 0, imageMetaData.File.ContentLength);
                    imageGallary.Image = data;
                    imageGallary.Description = imageMetaData.Description;
                    _db.ImagGallaries.Add(imageGallary);
                    _db.SaveChanges();

                    ViewData["users"] = _db.ImagGallaries.ToList();

                    return View();

                }
                catch (Exception)
                {
                    Response.Write("<div id='uploadImageError'>");
                    Response.Write("* Sorry,You are allowed to Upload only JPG type Picture .If Your picture is jpg typed then make sure that it is less than 2MB in size");
                    Response.Write("</div>");
                }

            }

            ViewData["users"] = _db.ImagGallaries.ToList();
            return View();
        }
Exemple #2
0
        public ActionResult Upload(ImagGallary imageGallary, int?page)
        {
            if (imageGallary.file == null)
            {
                Response.Write("<div id='uploadImageError'>");
                Response.Write("You have to select a photo of type jpg");
                Response.Write("</div>");
            }
            if (imageGallary.Description == null)
            {
                Response.Write("<div id='uploadImageErro'>");
                Response.Write("You must provide a very short description about the Image");
                Response.Write("</div>");
            }
            if (imageGallary.file != null && imageGallary.Description != null)
            {
                try
                {
                    byte[] data = new byte[imageGallary.file.ContentLength];
                    imageGallary.file.InputStream.Read(data, 0, imageGallary.file.ContentLength);
                    imageGallary.Image = data;

                    db.ImagGallaries.Add(imageGallary);
                    db.SaveChanges();
                    imageGallary.file = null;

                    ViewData["users"] = db.ImagGallaries.ToList().ToPagedList(page ?? 1, 5);


                    return(View(db.ImagGallaries.ToList().ToPagedList(page ?? 1, 3)));
                }
                catch (Exception)
                {
                    Response.Write("<div id='uploadImageError'>");
                    Response.Write("Sorry,You are allowed to Upload only JPG type Picture .If Your picture is jpg typed then make sure that it is less than 2MB in size");
                    Response.Write("</div>");
                }
            }


            ViewData["users"] = db.ImagGallaries.ToList().ToPagedList(page ?? 1, 3);
            return(View(db.ImagGallaries.ToList().ToPagedList(page ?? 1, 3)));
        }
Exemple #3
0
        public ActionResult Delete(int id)
        {
            ImagGallary imagId = db.ImagGallaries.Where(m => m.ID == id).FirstOrDefault();

            if (imagId != null)
            {
                try
                {
                    db.ImagGallaries.Remove(imagId);

                    db.SaveChanges();
                }

                catch
                {
                }
            }

            return(RedirectToAction("Upload", "ImageUpload"));
        }