Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Login,Password,adm")] Usuario usuario)
        {
            if (HttpContext.Session.GetString("login") == null || HttpContext.Session.GetString("login") == "")
            {
                return(RedirectToAction("Login", "Home"));
            }
            ViewData["usuario"] = HttpContext.Session.GetString("name");
            ViewData["isAdm"]   = HttpContext.Session.GetString("is_adm");

            if (id != usuario.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Usuario user = new Usuario
                    {
                        Nome     = usuario.Nome,
                        Login    = usuario.Login,
                        Password = EncryptHash.Encript(usuario.Password),
                        adm      = usuario.adm
                    };
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UsuarioExists(usuario.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(usuario));
        }
Пример #2
0
        public async Task <IActionResult> Edit(Pesquisa pesquisa)
        {
            if (pesquisa.id != pesquisa.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pesquisa);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(Redirect("https://www.google.com.br"));
            }
            return(View(pesquisa));
        }
Пример #3
0
        public IActionResult Edit(Cliente cliente)
        {
            if (HttpContext.Session.GetString("login") == null || HttpContext.Session.GetString("login") == "")
            {
                return(RedirectToAction("Login", "Home"));
            }
            ViewData["usuario"] = HttpContext.Session.GetString("name");
            ViewData["isAdm"]   = HttpContext.Session.GetString("is_adm");

            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cliente);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClienteExists(cliente.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }