Пример #1
0
        public ActionResult EditImageEvent(FormCollection form, int id)
        {
            int idEvento = id;
            HttpPostedFileBase arquivo = Request.Files[0];

            if (ModelState.IsValid)
            {
                string Foto_Perfil = null;
                using (System.Drawing.Image pic = System.Drawing.Image.FromStream(arquivo.InputStream))
                {
                    /*if (pic.Height != 256 && pic.Width != 256)
                     * {
                     *
                     *  return RedirectToAction("Edit");
                     * }
                     * else*/
                    if (arquivo.ContentType != "image/png" && arquivo.ContentType != "image/jpeg" && arquivo.ContentType != "image/jpg")
                    {
                        TempData["errorManager"] = "Check the photo format";
                        return(RedirectToAction("Manager", "Event", new { EventoID = idEvento }));
                    }
                    else if (arquivo.ContentLength > 2097152)
                    {
                        TempData["errorManager"] = "Very large picture";
                        return(RedirectToAction("Manager", "Event", new { EventoID = idEvento }));
                    }
                }

                if (Request.Files.Count > 0)
                {
                    if (arquivo.ContentLength > 0)
                    {
                        DateTime today = DateTime.Now;
                        string   img   = "/Pictures/Event/" + idEvento.ToString() + today.ToString("yyyyMMddhhmmss") + System.IO.Path.GetExtension(arquivo.FileName);
                        string   path  = HostingEnvironment.ApplicationPhysicalPath;

                        string caminho = path + "\\Pictures\\Event\\" + idEvento.ToString() + today.ToString("yyyyMMddhhmmss") + System.IO.Path.GetExtension(arquivo.FileName);
                        arquivo.SaveAs(caminho);
                        Foto_Perfil = img;
                    }
                }
                using (EventoModel model = new EventoModel())
                {
                    model.UpdateImage(idEvento, Foto_Perfil);
                }

                TempData["successManager"] = "Picutere Changed";
                return(RedirectToAction("Manager", "Event", new { EventoID = idEvento }));
            }
            else
            {
                TempData["errorManager"] = "Erro Changed Picutere";
                return(RedirectToAction("Manager", "Event", new { EventoID = idEvento }));
            }
        }