public ActionResult Edit(ManobristaViewModel dados)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Manobrista manobrista = _mapper.Map<ManobristaViewModel, Manobrista>(dados);

                    manobristaBLL.Atualizar(manobrista);

                    _toastNotification.AddSuccessToastMessage();
                    return RedirectToAction("Index", "Manobrista");
                }

                PreencheViewBag();
                _toastNotification.AddWarningToastMessage("Verifique se todos os campos estão preenchidos corretamente.");
                return View(dados);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                _toastNotification.AddErrorToastMessage();
                return RedirectToAction("Index", "Manobrista");
            }
        }
        public static Manobrista ListarPorCPF(Manobrista manobrista)
        {
            try
            {
                String strQuery = "SELECT NM_NOME, NM_CPF, DT_NASC"
                                  + " FROM T_MANOBRISTA "
                                  + " WHERE (NM_CPF ="
                                  + " '" + manobrista.cpf + "')";

                Conexao       Dados         = new Conexao();
                SqlDataReader retornoReader = Dados.RetornoReader(strQuery);

                Manobrista obj = null;

                while (retornoReader.Read())
                {
                    obj = new Manobrista();

                    obj.nome     = retornoReader["NM_NOME"].ToString();
                    obj.dataNasc = String.Format("{0:d}", (DateTime.Parse(retornoReader["DT_NASC"].ToString())));
                    obj.cpf      = retornoReader["NM_CPF"].ToString();
                }
                return(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> Edit(long id, [Bind("ManobristaId,Name,Cpf,DataNascimento")] Manobrista manobrista)
        {
            if (id != manobrista.ManobristaId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(manobrista);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ManobristaExists(manobrista.ManobristaId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(manobrista));
        }
        public async Task <IActionResult> Edit(Guid?id, [Bind("Id,Cpf,PrimeiroNome,Sobrenome,Nascimento")] ManobristaViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Manobrista ent = (await _domain.GetByIdAsync(id.Value));
                    if (ent == null)
                    {
                        return(NotFound());
                    }
                    ent = ent.Map(model);
                    _domain.Update(ent);
                    await _work.SaveChangesAsync();
                }
                catch (Exception)
                {
                    if (!ManobristaViewModelExists(model.Id))
                    {
                        return(NotFound());
                    }
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Example #5
0
        public static List <Manobrista> ListarAllManobristas()
        {
            try
            {
                String strQuery = "SELECT M.NM_CPF, M.NM_NOME, M.DT_NASC"
                                  + " FROM T_MANOBRISTA M "
                                  + " WHERE M.FL_EXCLUIDO = 0 ";

                Conexao       Dados         = new Conexao();
                SqlDataReader retornoReader = Dados.RetornoReader(strQuery);

                Manobrista        obj            = null;
                List <Manobrista> listmanobrista = new List <Manobrista>();

                while (retornoReader.Read())
                {
                    obj = new Manobrista();

                    obj.nome     = retornoReader["NM_NOME"].ToString();
                    obj.cpf      = retornoReader["NM_CPF"].ToString();
                    obj.dataNasc = retornoReader["DT_NASC"].ToString();

                    listmanobrista.Add(obj);
                }
                return(listmanobrista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        public ActionResult Details(string cpf)
        {
            Manobrista manobrista = new Manobrista();

            manobrista.cpf = cpf;
            return(View(ListarPorCPF(manobrista)));
        }
Example #7
0
        // GET: Manobrista
        public ActionResult Index(Mensagem retorno, string searchStringNome, string searchStringCPF)
        {
            if (retorno.msg != null)
            {
                ViewBag.Alerta = retorno.msg;
            }
            else
            {
                ViewBag.Alerta = string.Empty;
            }
            Manobrista manobrista = new Manobrista();

            if (!String.IsNullOrEmpty(searchStringNome))
            {
                manobrista.nome = searchStringNome.ToUpper();
            }
            if (!String.IsNullOrEmpty(searchStringCPF))
            {
                if (!IsCpf(searchStringCPF))
                {
                    ViewBag.Alerta = "CPF invalido, favor preenche-lo conforme o modelo XXX.XXX.XXX-XX e com uma combinacao valida!";
                    return(View());
                }
                manobrista.cpf = searchStringCPF;
            }
            return(View(Listar(manobrista)));
        }
Example #8
0
 /// <summary>
 /// Mapeia uma view-model de Manobrista para uma entidade existente
 /// </summary>
 /// <param name="ent">Entidade existente</param>
 /// <param name="model">View-model do Manobrista</param>
 public static Manobrista Map(this Manobrista ent, ManobristaViewModel model)
 {
     ent.Cpf          = model.Cpf;
     ent.PrimeiroNome = model.PrimeiroNome;
     ent.Sobrenome    = model.Sobrenome;
     ent.Nascimento   = model.Nascimento;
     return(ent);
 }
Example #9
0
        public ActionResult Edit(string cpf)
        {
            Manobrista manobrista = new Manobrista();

            manobrista.cpf = cpf;
            ViewBag.Alerta = string.Empty;
            return(View(ListarPorCPF(manobrista)));
        }
Example #10
0
 public ActionResult Edit([Bind(Include = "IdManobrista,NomeManobrista,CpfManobrista,DataNascManobrista")] Manobrista manobrista)
 {
     if (ModelState.IsValid)
     {
         db.Entry(manobrista).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(manobrista));
 }
 public static List <Manobrista> Listar(Manobrista manobrista)
 {
     try
     {
         return(ManobristaDAL.Listar(manobrista));
     }catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <IActionResult> Create([Bind("ManobristaId,Name,Cpf,DataNascimento")] Manobrista manobrista)
        {
            if (ModelState.IsValid)
            {
                _context.Add(manobrista);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(manobrista));
        }
Example #13
0
        public ActionResult Create([Bind(Include = "IdManobrista,NomeManobrista,CpfManobrista,DataNascManobrista")] Manobrista manobrista)
        {
            if (ModelState.IsValid)
            {
                db.Manobristas.Add(manobrista);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(manobrista));
        }
Example #14
0
 /// <summary>
 /// Mapeia uma entidade de Manobrista para uma view-model
 /// </summary>
 /// <param name="ent">Instância de Manobrista</param>
 public static ManobristaViewModel Map(this Manobrista ent)
 {
     return(new ManobristaViewModel()
     {
         Id = ent.Id,
         Cpf = ent.Cpf,
         PrimeiroNome = ent.PrimeiroNome,
         Sobrenome = ent.Sobrenome,
         Nascimento = ent.Nascimento
     });
 }
 public static Manobrista ListarPorCPF(Manobrista manobrista)
 {
     try
     {
         return(ManobristaDAL.ListarPorCPF(manobrista));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public static string Excluir(Manobrista manobrista)
 {
     try
     {
         return(ManobristaDAL.Excluir(manobrista));
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
        public async Task <IActionResult> DeleteConfirmed(Guid?id)
        {
            Manobrista ent = (await _domain.GetByIdAsync(id.Value));

            if (ent != null)
            {
                _domain.Delete(ent);
            }
            await _work.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Example #18
0
 public ActionResult Delete(Manobrista manobrista)
 {
     try
     {
         Mensagem retorno = new Mensagem();
         retorno.msg = ManobristaBLL.Excluir(manobrista);
         return(RedirectToAction("Index", retorno));
     }
     catch
     {
         return(View());
     }
 }
Example #19
0
        public ActionResult DeleteConfirmed(int id)
        {
            Manobrista manobrista = db.Manobristas.Find(id);

            if (manobrista.CarrosManobras.Count >= 1)
            {
                ViewBag.Message = "Este manobrista esta vinculado a alguma manobra!";
                return(RedirectToAction("Index"));
            }

            db.Manobristas.Remove(manobrista);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #20
0
        // GET: Manobristas/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Manobrista manobrista = db.Manobristas.Find(id);

            if (manobrista == null)
            {
                return(HttpNotFound());
            }
            return(View(manobrista));
        }
        /// <summary>
        /// Iniciar a edição de um manobrista existente
        /// </summary>
        /// <param name="id">Id do registro</param>
        public async Task <IActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Manobrista ent = (await _domain.GetByIdAsync(id.Value));

            if (ent == null)
            {
                return(NotFound());
            }
            return(View(ent.Map()));
        }
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                DateTime dtNascimento = DateTime.TryParse(collection["DataNascimento"], out dtNascimento) ? dtNascimento : throw new ArgumentException("Data nascimento inválida");
                var      manobrista   = new Manobrista(collection["Nome"], collection["Cpf"], dtNascimento);
                repositorio.Adicionar(manobrista);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #23
0
        public async Task Atualizar(Manobrista manobrista)
        {
            manobrista.Cpf = Utils.RemoverCharEspecial(manobrista.Cpf);
            if (!ExecutarValidacao(new ManobristaValidation(), manobrista))
            {
                return;
            }

            if (_manobristaRepository.Buscar(m => m.Cpf == manobrista.Cpf && m.Id != manobrista.Id).Result.Any())
            {
                Notificar("Já existe um manobrista com esse cpf informado.");
                return;
            }

            await _manobristaRepository.Atualizar(manobrista);
        }
Example #24
0
        public IActionResult Put([FromBody] Manobrista item)
        {
            try
            {
                service.Put <ManobristaValidator>(item);

                return(new ObjectResult(item));
            }
            catch (ArgumentNullException ex)
            {
                return(NotFound(ex));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public ActionResult Edit(int id)
        {
            try
            {
                Manobrista manobrista = manobristaBLL.ObterPorId(id);

                ManobristaViewModel dados = _mapper.Map<Manobrista, ManobristaViewModel>(manobrista);

                PreencheViewBag();

                return View(dados);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                _toastNotification.AddErrorToastMessage();
                return RedirectToAction("Index", "Manobrista");
            }
        }
        public static string Excluir(Manobrista manobrista)
        {
            try
            {
                Conexao dados = new Conexao();

                StringBuilder strQuery = new StringBuilder();
                strQuery.Append("UPDATE T_MANOBRISTA ");
                strQuery.Append(" SET ");
                strQuery.Append(" FL_EXCLUIDO = 1 ");
                strQuery.Append(" WHERE NM_CPF = ");
                strQuery.Append("'" + manobrista.cpf + "'");

                dados.ExecutarComando(strQuery);
                return("Registro excluido com sucesso!");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public static List <Manobrista> Listar(Manobrista manobrista)
        {
            try
            {
                String strQuery = "SELECT NM_NOME, NM_CPF, DT_NASC"
                                  + " FROM T_MANOBRISTA "
                                  + " WHERE (NM_NOME LIKE"
                                  + " '%" + manobrista.nome + "%' OR"
                                  + " '" + manobrista.nome + "' = '' OR"
                                  + " '" + manobrista.nome + "' = null)"
                                  + " AND (NM_CPF ="
                                  + " '" + manobrista.cpf + "' OR"
                                  + " '" + manobrista.cpf + "' = '' OR"
                                  + " '" + manobrista.cpf + "' = null) AND FL_EXCLUIDO = 0"
                                  + "ORDER BY NM_NOME, NM_CPF, DT_NASC";

                Conexao       Dados         = new Conexao();
                SqlDataReader retornoReader = Dados.RetornoReader(strQuery);

                Manobrista        obj            = null;
                List <Manobrista> listmanobrista = new List <Manobrista>();

                while (retornoReader.Read())
                {
                    obj = new Manobrista();

                    obj.nome     = retornoReader["NM_NOME"].ToString();
                    obj.dataNasc = String.Format("{0:d}", (DateTime.Parse(retornoReader["DT_NASC"].ToString())));
                    obj.cpf      = retornoReader["NM_CPF"].ToString();

                    listmanobrista.Add(obj);
                }
                return(listmanobrista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #28
0
 public ActionResult Create(Manobrista manobrista)
 {
     try
     {
         ViewBag.Alerta = string.Empty;
         if (manobrista.cpf.Length != 14)
         {
             ViewBag.Alerta = "CPF incorreto, favor preenche-lo conforme o modelo XXX.XXX.XXX-XX!";
         }
         if (!IsCpf(manobrista.cpf))
         {
             ViewBag.Alerta = "CPF invalido, favor preenche-lo conforme o modelo XXX.XXX.XXX-XX e com uma combinacao valida!";
         }
         if (manobrista.nome.Length <= 3 || manobrista.nome.Length > 200)
         {
             ViewBag.Alerta = "O Nome deve ter no minimo 3 caracteres e no maximo de 200!";
         }
         if (manobrista.dataNasc.Length != 10)
         {
             ViewBag.Alerta = "A data deve estar no formato DD/MM/YYYY!";
         }
         if (ViewBag.Alerta == string.Empty)
         {
             Mensagem retorno = new Mensagem();
             manobrista.nome = manobrista.nome.ToUpper();
             retorno.msg     = ManobristaBLL.Inserir(manobrista);
             return(RedirectToAction("Index", retorno));
         }
         else
         {
             return(View());
         }
     }
     catch
     {
         return(View());
     }
 }
        public static string Editar(Manobrista manobrista)
        {
            try
            {
                Conexao dados = new Conexao();

                StringBuilder strQuery = new StringBuilder();
                strQuery.Append("UPDATE T_MANOBRISTA ");
                strQuery.Append(" SET ");
                strQuery.Append(" NM_NOME = ");
                strQuery.Append("'" + manobrista.nome + "',");
                strQuery.Append(" DT_NASC = ");
                strQuery.Append("CONVERT(date,'" + manobrista.dataNasc + "',103)");
                strQuery.Append(" WHERE NM_CPF = ");
                strQuery.Append("'" + manobrista.cpf + "'");

                dados.ExecutarComando(strQuery);
                return("Registro editado com sucesso!");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #30
0
 public Manobrista ListarPorCPF(Manobrista manobrista)
 {
     return(ManobristaBLL.ListarPorCPF(manobrista));
 }