Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Enable")] GALibrary.Models.Environment environment)
        {
            if (id != environment.Id)
            {
                return(NotFound());
            }

            try
            {
                if (ModelState.IsValid)
                {
                    _context.Update(environment);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }

                ViewBag.EnvironmentEnabled = new SelectList(new[] { new { ID = true, Name = "Sim" }, new { ID = false, Name = "Não" }, }, "ID", "Name", environment.Enable);

                GALibrary.GALogs.SaveLog("Environment", "Fim da edicao do ambiente " + environment.Name + " realizada pelo usuario " + User.Identity.Name, 2, _context.Parameter.FirstOrDefault());

                return(View(environment));
            }
            catch (Exception erro)
            {
                GALibrary.GALogs.SaveLog("Environment", "Erro ao editar ambiente " + environment.Name + " pelo usuario " + User.Identity.Name + ": " + erro.ToString(), 1, _context.Parameter.FirstOrDefault());
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Enable")] GALibrary.Models.Environment environment)
        {
            environment.Enable = true;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(environment);
                    await _context.SaveChangesAsync();

                    GALibrary.GALogs.SaveLog("Environment", "Fim do cadastro do ambiente " + environment.Name + " pelo usuario " + User.Identity.Name, 2, _context.Parameter.FirstOrDefault());

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception erro) {
                    GALibrary.GALogs.SaveLog("Environment", "Erro ao cadastrar ambiente pelo usuario " + User.Identity.Name + ": " + erro.ToString(), 1, _context.Parameter.FirstOrDefault());
                }
            }
            return(View(environment));
        }