Beispiel #1
0
        public JsonResult Alterar(BeneficiarioModel model)
        {
            BoBeneficiario bo = new BoBeneficiario();

            if (!this.ModelState.IsValid)
            {
                List <string> erros = (from item in ModelState.Values
                                       from error in item.Errors
                                       select error.ErrorMessage).ToList();

                Response.StatusCode = 400;
                return(Json(string.Join(Environment.NewLine, erros)));
            }
            else
            {
                if (bo.ValidaCPF(model.CPF))
                {
                    bo.Alterar(new Beneficiario()
                    {
                        Id        = model.Id,
                        CPF       = model.CPF,
                        Nome      = model.Nome,
                        IdCliente = model.IdCliente
                    });
                }
                else
                {
                    return(Json("CPF Inválido"));
                }

                return(Json("Cadastro alterado com sucesso"));
            }
        }
Beispiel #2
0
        public JsonResult Incluir(BeneficiarioModel model)
        {
            BoBeneficiario bo = new BoBeneficiario();

            if (!this.ModelState.IsValid)
            {
                List <string> erros = (from item in ModelState.Values
                                       from error in item.Errors
                                       select error.ErrorMessage).ToList();

                Response.StatusCode = 400;
                return(Json(string.Join(Environment.NewLine, erros)));
            }
            else
            {
                if (bo.VerificarExistencia(model.CPF))
                {
                    Response.StatusCode = 400;
                    return(Json("CPF já cadastrado"));
                }
                else
                {
                    if (bo.ValidaCPF(model.CPF))
                    {
                        model.Id = bo.Incluir(new Beneficiario()
                        {
                            CPF       = model.CPF,
                            Nome      = model.Nome,
                            IdCliente = (int)Session["IdCliente"]
                        });
                    }
                    else
                    {
                        Response.StatusCode = 400;
                        return(Json("CPF inválido"));
                    }
                }

                return(Json("Cadastro efetuado com sucesso"));
            }
        }