예제 #1
0
        public IActionResult Salvar(GftViewModel gftVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (gftVM == null)
                    {
                        throw new Exception("Gft inválida!");
                    }

                    _enderecoRepository.Salvar(gftVM.Endereco);
                    _gftRepository.Salvar(gftVM.ToModel());

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Gft", gftVM));
                }
            }
            catch (EntidadeNaoEncontradaException)
            {
                return(NotFound("Cargo não encontrado"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
예제 #2
0
        public static Gft ToModel(this GftViewModel gftVM)
        {
            var gft = new Gft()
            {
                id       = (gftVM.Id.HasValue ? gftVM.Id.Value : 0),
                nome     = gftVM.Nome,
                endereco = gftVM.Endereco,
                telefone = gftVM.Telefone,
                status   = true
            };

            if (gftVM.HasId)
            {
                gft.data_alteracao = DateTime.Now;
            }
            return(gft);
        }