Beispiel #1
0
        // GET: FotoAtlas/Create
        //public ActionResult Create()
        //{
        //    ViewBag.EspecieID = new SelectList(db.Especies, "ID", "Nome");
        //    return View();
        //}
        public ActionResult Create(Especie espec)
        {
            FotoAtlas fa = new FotoAtlas();

            fa.EspecieID      = espec.ID;
            ViewBag.EspecieID = new SelectList(db.Especies, "ID", "Nome");
            return(View(fa));
        }
Beispiel #2
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            FotoAtlas fotoAtlas = await db.FotoAtlas.FindAsync(id);

            db.FotoAtlas.Remove(fotoAtlas);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,EspecieID,Caminho,Aprovado")] FotoAtlas fotoAtlas)
        {
            if (ModelState.IsValid)
            {
                db.Entry(fotoAtlas).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.EspecieID = new SelectList(db.Especies, "ID", "Nome", fotoAtlas.EspecieID);
            return(View(fotoAtlas));
        }
Beispiel #4
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FotoAtlas fotoAtlas = await db.FotoAtlas.FindAsync(id);

            if (fotoAtlas == null)
            {
                return(HttpNotFound());
            }
            return(View(fotoAtlas));
        }
Beispiel #5
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FotoAtlas fotoAtlas = await db.FotoAtlas.FindAsync(id);

            if (fotoAtlas == null)
            {
                return(HttpNotFound());
            }
            ViewBag.EspecieID = new SelectList(db.Especies, "ID", "Nome", fotoAtlas.EspecieID);
            return(View(fotoAtlas));
        }
Beispiel #6
0
        public async Task <ActionResult> Create([Bind(Include = "ID,EspecieID,Caminho,Aprovado")] FotoAtlas fotoAtlas, HttpPostedFileBase File)
        {
            if (ModelState.IsValid)
            {
                if (File != null && File.ContentLength > 0)
                {
                    int fileSize = File.ContentLength;
                    int size     = 4194304;
                    if (fileSize < size)
                    {
                        string _FileName = Path.GetFileName(File.FileName);

                        // store the file inside ~/App_Data/uploads folder
                        //string strID = animalFoto.ID.ToString();
                        //string _path = Path.Combine(Server.MapPath("~/Foto"), _FileName);
                        string _path = Path.Combine(Server.MapPath("~/Content/Images"), _FileName);

                        File.SaveAs(_path);
                        //string caminho = "Foto/" + _FileName;
                        string caminho = "Content/Images/" + _FileName;
                        fotoAtlas.Caminho = caminho;
                    }
                    else
                    {
                        //ViewBag.ErrorMessage = "Tamanho excedido";
                        ModelState.AddModelError("Caminho", "Excedido tamanho. Foto < 2MB");
                        return(View());
                    }
                }

                db.FotoAtlas.Add(fotoAtlas);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Especies", new { id = fotoAtlas.EspecieID }));

                //return RedirectToAction("Index");
            }

            ViewBag.EspecieID = new SelectList(db.Especies, "ID", "Nome", fotoAtlas.EspecieID);
            return(View(fotoAtlas));
        }