public async Task <IActionResult> Edit(long id, [Bind("Id,Name")] Models.Setor setor)
        {
            if (id != setor.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _repositorySetor.UpdateAsync(id, setor);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(setor));
        }
Example #2
0
        //obter linha de uma tabela do banco de acordo com um id passado, e jogando para um objeto
        public Models.Setor Obter(int id)
        {
            Models.Setor setor = null;

            string select = @"select * 
                              from setor 
                              where id = " + id;

            DataTable dt = _bd.ExecutarSelect(select);

            if (dt.Rows.Count == 1)
            {
                //ORM - Relacional -> Objeto
                setor = Map(dt.Rows[0]);
            }

            return(setor);
        }
Example #3
0
        public IActionResult Editar([FromBody] Dictionary <string, string> dados)
        {
            bool operacao = false;

            Models.Setor setor = new Models.Setor();
            setor.Id        = Convert.ToInt32(dados["Id"]);
            setor.Descriçao = (dados["Descriçao"]);

            CamadaNegocio.SetorCN
                scn = new CamadaNegocio.SetorCN();
            operacao = scn.Editar(setor);


            return(Json(new
            {
                operacao
            }));
        }
        public (bool, string) Criar(Models.Setor setor)
        {
            string msg      = "";
            bool   operacao = false;

            DAL.SetorDAL sbd = new DAL.SetorDAL();

            if (sbd.validarnomeUnico(setor.Descriçao))
            {
                msg = "setor já cadastrado.";
            }
            else
            {
                operacao = sbd.Criar(setor);
            }

            return(operacao, msg);
        }
Example #5
0
        public IActionResult Criar([FromBody] Dictionary <string, string> dados)
        {
            bool   operacao = false;
            string msg      = "";

            Models.Setor setor = new Models.Setor();
            setor.Descriçao = (dados["Descriçao"]);

            CamadaNegocio.SetorCN
                scn = new CamadaNegocio.SetorCN();
            (operacao, msg) = scn.Criar(setor);


            return(Json(new
            {
                operacao,
                msg
            }));
        }
Example #6
0
        //Editar uma linha da tabela passando um objeto
        public bool Editar(Models.Setor setor)
        {
            int linhasAfetadas = 0;

            try
            {
                string update = @"update setor set Descriçao = @descriçao where Id =" + setor.Id;

                //var parametros = _bd.GerarParametros();
                Dictionary <string, object> parametros = new Dictionary <string, object>();
                parametros.Add("@descriçao", setor.Descriçao);

                linhasAfetadas = _bd.ExecutarNonQuery(update, parametros);
            }
            catch (Exception ex)
            {
                string erro = ex.Message;
            }

            return(linhasAfetadas > 0);
        }
Example #7
0
        public IActionResult Setor_Edicao(int idSetor)
        {
            try
            {
                var setorViewModel = new SetorViewModel();
                ViewBag.Setor    = "Setor";
                ViewBag.Empresas = _empresaRepository.Empresas.Select(e => new SelectListItem()
                {
                    Text = e.RazaoSocial, Value = e.IdEmpresa.ToString()
                }).ToList();

                Models.Setor setor = _setorRepository.GetSetorById(idSetor);
                setorViewModel.setor    = setor;
                setorViewModel.Empresas = _empresaRepository.Empresas;

                return(View(setorViewModel));
            }
            catch (Exception)
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }