public ActionResult Create(CadastroEmpresa cadastro)
        {
            try
            {
                cadastro.CadastradoPor = _login.GetIdUsuario(System.Web.HttpContext.Current.User.Identity.Name);
                cadastro.Id            = 0;
                TryUpdateModel(cadastro);

                if (ModelState.IsValid)
                {
                    _serviceCadastro.Gravar(cadastro);
                    // TODO - redirect to inclusao do salao
                    return(RedirectToAction("Index"));
                }

                ViewBag.TipoPessoa   = GetTipoPessoa(1);
                ViewBag.TipoEndereco = GetTipoEndereco();
                ViewBag.Estados      = GetEstados();
                return(View(cadastro));
            }
            catch (ArgumentException e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                ViewBag.TipoPessoa   = GetTipoPessoa(1);
                ViewBag.TipoEndereco = GetTipoEndereco();
                ViewBag.Estados      = GetEstados();
                return(View(cadastro));
            }
        }
Example #2
0
        public ActionResult Index([Bind(Include = "Id,IdEndereco,Fantasia,RazaoSocial,TipoPessoa,Cnpj,Cpf,TipoEndereco,Cep,Logradouro,Numero,Bairro,Cidade,IdEstado,Contato,Email,DDD,Telefone,Observ,Cortesia,Desconto,DescontoCarencia,CadastradoPor")] CadastroEmpresa cadastro)
        {
            try
            {
                if (string.IsNullOrEmpty(cadastro.Cnpj))
                {
                    cadastro.Cnpj = "";
                }
                if (string.IsNullOrEmpty(cadastro.Cpf))
                {
                    cadastro.Cpf = "";
                }

                if (ModelState.IsValid)
                {
                    _service.Gravar(cadastro);
                    return(RedirectToAction("Index", "Home", new { mensagem = "Cadastro atualizado" }));
                }

                return(View(cadastro));
            }
            catch (System.Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(cadastro));
            }
        }
Example #3
0
        public void EmpresaCadastrar()
        {
            // Arrange
            var cadastro = new CadastroEmpresa
            {
                CadastradoPor    = 1,
                Bairro           = "MIRANDOPOLIS",
                Cep              = "04043200",
                Cidade           = "SAO PAULO",
                Cnpj             = "",
                Cpf              = "12557634859",
                Complemento      = "APTO 12",
                Contato          = "JOSE",
                Cortesia         = true,
                DDD              = "11",
                Desconto         = 100M,
                DescontoCarencia = 3,
                Email            = "*****@*****.**",
                Fantasia         = "FLORISBELLA",
                IdEstado         = 1,
                Logradouro       = "RUA LUIS GOIS",
                Numero           = "1850",
                Observ           = "",
                RazaoSocial      = "FLORISBELLA LTDA",
                Telefone         = "997218670",
                TipoEndereco     = 1,
                TipoPessoa       = 2
            };

            // Act
            int id = service.Gravar(cadastro);

            // Assert
            Assert.AreNotEqual(0, id);
        }