public ActionResult IncluirPatrocinador(int id, FormCollection collection) { try { PessoaJuridica Patrocinador = new PessoaJuridica(); if (collection.HasKeys()) { if (id != 0) { Patrocinador = PessoaJuridicaBusiness.Obter(id); } Patrocinador.RazaoSocial = collection["RazaoSocial"]; Patrocinador.CNPJ = collection["CNPJ"]; Patrocinador.NomeFantasia = collection["NomeFantasia"]; Patrocinador.UF = (UF)int.Parse(collection["UF"]); Patrocinador.Cidade = collection["Cidade"]; Patrocinador.Bairro = collection["Bairro"]; Patrocinador.Logradouro = collection["Logradouro"]; Patrocinador.Numero = int.Parse(collection["Numero"]); Patrocinador.Complemento = collection["Complemento"]; Patrocinador.Cep = collection["CEP"]; foreach (var key in collection.AllKeys.Where(x => x.Contains("Telefone"))) { if (Patrocinador.Telefones.Where(x => x.Key == key).Count() > 0) { Patrocinador.Telefones.FirstOrDefault(x => x.Key == key).Value = collection[key]; } else if (!string.IsNullOrEmpty(collection[key])) { Patrocinador.Telefones.Add(new Telefone(key, collection[key])); } } PessoaJuridicaBusiness.Add(Patrocinador); } } catch { return(RedirectToAction("Patrocinadores")); } return(RedirectToAction("Patrocinadores")); }
public ActionResult IncluirPatrocinador(FormCollection collection) { try { var Patrocinador = new PessoaJuridica(); Patrocinador.RazaoSocial = collection["RazaoSocial"]; Patrocinador.CNPJ = collection["CNPJ"]; Patrocinador.NomeFantasia = collection["NomeFantasia"]; Patrocinador.UF = (UF)int.Parse(collection["UF"]); Patrocinador.Cidade = collection["Cidade"]; Patrocinador.Bairro = collection["Bairro"]; Patrocinador.Logradouro = collection["Logradouro"]; Patrocinador.Numero = int.Parse(collection["Numero"]); Patrocinador.Complemento = collection["Complemento"]; Patrocinador.Cep = collection["CEP"]; //if (!string.IsNullOrEmpty(collection["Telefone_Comercial"])) // Patrocinador.Telefones.Add(new Telefone() { Key = "TelefoneComercial", Value = collection["TelefoneComercial"] }); //if (!string.IsNullOrEmpty(collection["TelefonePessoal"])) // Patrocinador.Telefones.Add(new Telefone() { Key = "TelefonePessoal", Value = collection["TelefonePessoal"] }); //if (!string.IsNullOrEmpty(collection["TelefoneResidencial"])) // Patrocinador.Telefones.Add(new Telefone() { Key = "TelefoneResidencial", Value = collection["TelefoneResidencial"] }); foreach (var key in collection.AllKeys.Where(x => x.Contains("Telefone"))) { if (Patrocinador.Telefones.Where(x => x.Key == key).Count() > 0) { Patrocinador.Telefones.FirstOrDefault(x => x.Key == key).Value = collection[key]; } else { Patrocinador.Telefones.Add(new Telefone(key, collection[key])); } } var Autor = new Autor(); Autor.Nome = collection["Nome"]; if (!string.IsNullOrEmpty(collection["Telefone_Autor"])) { Autor.Telefones.Add(new Telefone() { Key = "Telefone_Pessoal", Value = Telefone.LimparCaracteresEspeciais(collection["Telefone_Autor"]) }); } Autor.Usuario.Grupo = Grupo.AutorPatrocinado; Autor.Usuario.Login = collection["Login"]; Autor.Usuario.Senha = collection["Senha"]; Autor.Usuario.EMail = collection["Email"]; if (!string.IsNullOrEmpty(collection["TelefoneResidencial"])) { Autor.Empresa = Patrocinador; } Patrocinador.Autores.Add(Autor); PessoaJuridicaBusiness.Add(Patrocinador); } catch (Exception ex) { return(RedirectToAction("Erro", "Index", ex)); } return(RedirectToAction("SucessoCadastro")); }