Пример #1
0
        public ActionResult List(foto entity, String message, int idJuri = 0)
        {
            ViewData["message"] = message;
            ViewData["Juri"] = entity.juri;
            ViewData["idFoto"] = entity.id_foto;

            if (idJuri == 0)
            {
                idJuri = entity.fk_id_juri;
                ViewData["idJuri"] = entity.fk_id_juri;
            }
            else
            {
                ViewData["idJuri"] = idJuri;
            }

            var imagesModel = new ImageGallery();

            if (Directory.Exists(Server.MapPath("~/Documentos/Fotos/" + idJuri)))
            {
                var imageFiles = Directory.GetFiles(Server.MapPath("~/Documentos/Fotos/" + idJuri));
                foreach (var item in imageFiles)
                {
                    if (item.IndexOf("Thumbs.db") < 0)
                    imagesModel.ImageList.Add(Path.GetFileName(item));
                }
            }

            return View(imagesModel);
        }
Пример #2
0
        public ActionResult UploadImage(foto foto)
        {
            if (Request.Files.Count != 0)
            {
                if (!Directory.Exists(Server.MapPath("~/Documentos/Fotos/" + Session["idJuri"])))
                {
                    Directory.CreateDirectory(Server.MapPath("~/Documentos/Fotos/" + Session["idJuri"]));
                }
                if (validate(foto)){
                    return View(foto);
                }

                HttpFileCollectionBase hfc = Request.Files;
                List<foto> fotos = new List<foto>();

                for (int i = 0; i < hfc.Count; i++)
                {
                    HttpPostedFileBase file = hfc[i];
                    int fileSize = file.ContentLength;
                    string fileName = file.FileName;

                    file.SaveAs(Server.MapPath("~/Documentos/Fotos/" + Session["idJuri"] + "/" + fileName));

                    ImageGallery imageGallery = new ImageGallery();
                    imageGallery.ID = Guid.NewGuid();
                    imageGallery.Name = fileName;
                    imageGallery.ImagePath = "~/Documentos/Fotos/" + Session["idJuri"] + "/" + fileName;

                    foto salvafoto = new foto();
                    salvafoto.fk_id_juri = int.Parse(Session["idJuri"].ToString());
                    salvafoto.path = imageGallery.ImagePath;
                    fotos.Add(salvafoto);
                }

                FotoRepository.Create(fotos);
                return RedirectToAction("List", new { message = "Fotos publicadas com sucesso!", idJuri = int.Parse(Session["idJuri"].ToString()) });
            }

            return View(foto);
        }