Exemple #1
0
        public async Task <IActionResult> Create2([Bind("PontoDeInteresseID,CategoriaID,PNome,PDescricao,PEndereco,PCoordenadas,PContacto,PEmail,PNumPessoas,PMaxPessoas,EstadoID,PDataEstado,PComments")] PontoDeInteresse pontoDeInteresse)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pontoDeInteresse);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoriaID"] = new SelectList(_context.Categoria, "CategoriaID", "CategoriaID", pontoDeInteresse.CategoriaID);
            ViewData["EstadoID"]    = new SelectList(_context.Estado, "EstadoID", "EstadoID", pontoDeInteresse.EstadoID);

            return(View(pontoDeInteresse));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, [Bind("PontoDeInteresseID,CategoriaID,PImagem,PNome,PDescricao,PEndereco,PCoordenadas,PContacto,PEmail,PNumPessoas,PMaxPessoas,EstadoID,PDataEstado,PComments")] PontoDeInteresse pontoDeInteresse, List <IFormFile> PImagem)
        {
            if (id != pontoDeInteresse.PontoDeInteresseID)
            {
                return(NotFound());
            }

            foreach (var item in PImagem)
            {
                if (item.Length > 0)
                {
                    using (var stream = new MemoryStream())
                    {
                        await item.CopyToAsync(stream);

                        pontoDeInteresse.PImagem = stream.ToArray();
                    }
                }
            }
            _context.PontoDeInteresse.Update(pontoDeInteresse);


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pontoDeInteresse);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PontoDeInteresseExists(pontoDeInteresse.PontoDeInteresseID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoriaID"] = new SelectList(_context.Categoria, "CategoriaID", "CategoriaID", pontoDeInteresse.CategoriaID);
            ViewData["EstadoID"]    = new SelectList(_context.Estado, "EstadoID", "EstadoID", pontoDeInteresse.EstadoID);
            return(View(pontoDeInteresse));
        }
Exemple #3
0
        public async Task <IActionResult> Create(PontoDeInteresse pontosdeinteresse, List <IFormFile> PImagem)
        {
            foreach (var item in PImagem)
            {
                if (item.Length > 0)
                {
                    using (var stream = new MemoryStream())
                    {
                        await item.CopyToAsync(stream);

                        pontosdeinteresse.PImagem = stream.ToArray();
                    }
                }
            }
            _context.PontoDeInteresse.Add(pontosdeinteresse);
            _context.SaveChanges();
            //return View("../Home/PontoSucesso");
            return(RedirectToAction("PontoSucesso", "Home"));
        }