public ActionResult IncluirAutor(FormCollection collection) { try { if (collection.HasKeys()) { var autor = new Autor(); autor.Nome = collection["Nome"]; autor.DataNascimento = DateTime.Parse(collection["DataNascimento"]); autor.UF = (UF)int.Parse(collection["UF"]); autor.Cidade = collection["Cidade"]; autor.Bairro = collection["Bairro"]; autor.Logradouro = collection["Logradouro"]; autor.Numero = int.Parse(collection["Numero"]); autor.Complemento = collection["Complemento"]; autor.Cep = collection["CEP"]; autor.Ativo = false; //if (!string.IsNullOrEmpty(collection["TelefoneComercial"])) // autor.Telefones.Add(new Telefone() { Key = "TelefoneComercial", Value = collection["TelefoneComercial"] }); //if (!string.IsNullOrEmpty(collection["TelefonePessoal"])) // autor.Telefones.Add(new Telefone() { Key = "TelefonePessoal", Value = collection["TelefonePessoal"] }); //if (!string.IsNullOrEmpty(collection["TelefoneResidencial"])) // autor.Telefones.Add(new Telefone() { Key = "TelefoneResidencial", Value = collection["TelefoneResidencial"] }); foreach (var key in collection.AllKeys.Where(x => x.Contains("Telefone"))) { if (autor.Telefones.Where(x => x.Key == key).Count() > 0) { autor.Telefones.FirstOrDefault(x => x.Key == key).Value = collection[key]; } else { autor.Telefones.Add(new Telefone(key, collection[key])); } } autor.Usuario.Grupo = Grupo.Autor; autor.Usuario.Login = collection["Usuario.Login"]; autor.Usuario.Senha = collection["Usuario.Senha"]; autor.Usuario.EMail = collection["Usuario.EMail"]; AutorBusiness.Add(autor); RedirectToAction("SucessoCadastro", autor); } } catch (Exception ex) { return(RedirectToAction("Erro", "Index", ex)); } return(RedirectToAction("SucessoCadastro")); }
public ActionResult IncluirAutor(int id, FormCollection collection) { Autor Autor = new Autor(); try { if (collection.HasKeys()) { if (id != 0) { Autor = AutorBusiness.Obter(id); } Autor.Nome = collection["Nome"]; Autor.DataNascimento = DateTime.Parse(collection["DataNascimento"]); Autor.UF = (UF)int.Parse(collection["UF"]); Autor.Cidade = collection["Cidade"]; Autor.Bairro = collection["Bairro"]; Autor.Logradouro = collection["Logradouro"]; Autor.Numero = int.Parse(collection["Numero"]); Autor.Complemento = collection["Complemento"]; Autor.Cep = collection["CEP"]; Autor.Ativo = false; Autor.Usuario.Grupo = Grupo.Autor; if (!string.IsNullOrEmpty(collection["Usuario.Senha"]) && !string.IsNullOrEmpty(collection["ConfirmaSenha"]) && (collection["Usuario.Senha"] == collection["ConfirmaSenha"])) { if (User.IsInRole(TCC.CL.Core.Seguranca.RoleManager.Administrador) || Autor.Id == 0 || User.ObterAutor().Id == Autor.Id) { Autor.Usuario.Login = collection["Usuario.Login"]; } Autor.Usuario.Senha = collection["Usuario.Senha"]; Autor.Usuario.EMail = collection["Usuario.EMail"]; } foreach (var key in collection.AllKeys.Where(x => x.Contains("Telefone"))) { if (!string.IsNullOrEmpty(collection[key])) { if (Autor.Telefones.Where(x => x.Key == key).Count() > 0) { Autor.Telefones.FirstOrDefault(x => x.Key == key).Value = collection[key]; } else if (!string.IsNullOrEmpty(collection[key])) { Autor.Telefones.Add(new Telefone(key, collection[key])); } } } AutorBusiness.Add(Autor); } } catch { if (Autor.Usuario.Grupo != Grupo.Autor) { return(RedirectToAction("Autores")); } else { return(RedirectToAction("Index", "Home", new { area = "" })); } } if (Autor.Usuario.Grupo != Grupo.Autor) { return(RedirectToAction("Autores")); } else { return(RedirectToAction("Index", "Home", new { area = "" })); } }