public ActionResult Create(PJModel model) { try { PJ pjData = new PJ(); int idPJ = pjData.Inserir(model); List<EmailModel> listaEmail = new List<EmailModel>(); if (Session["EmailPJ"] != null) listaEmail = (List<EmailModel>)Session["EmailPJ"]; List<TelefoneModel> listaTelefone = new List<TelefoneModel>(); if (Session["TelefonePJ"] != null) listaTelefone = (List<TelefoneModel>)Session["TelefonePJ"]; List<EnderecoModel> listaEndereco = new List<EnderecoModel>(); if (Session["EnderecoPJ"] != null) listaEndereco = (List<EnderecoModel>)Session["EnderecoPJ"]; List<InternetModel> listaInternet = new List<InternetModel>(); if (Session["InternetPJ"] != null) listaInternet = (List<InternetModel>)Session["InternetPJ"]; Email _dataEmail = new Email(); foreach (EmailModel item in listaEmail) { item.IdPessoa = idPJ; _dataEmail.Inserir(item); } Telefone _dataTel = new Telefone(); foreach (TelefoneModel item in listaTelefone) { item.IdPessoa = idPJ; _dataTel.Inserir(item); } Endereco _dataEndereco = new Endereco(); foreach (EnderecoModel item in listaEndereco) { item.IdPessoa = idPJ; _dataEndereco.Inserir(item); } Internet _dataInternet = new Internet(); foreach (InternetModel item in listaInternet) { item.IdPessoa = idPJ; _dataInternet.Inserir(item); } Session["EnderecoPJ"] = null; Session["TelefonePJ"] = null; Session["EmailPJ"] = null; return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult InserirInternet(string endereco, int idTipo, int IdPJ) { Internet _dataInternet = new Internet(); InternetModel internetModel = new InternetModel() { Nome = endereco, IdPessoa = IdPJ, TipoInternet = new TipoInternetModel { Id = idTipo } }; if (internetModel.Nome.Length < 100) { _dataInternet.Inserir(internetModel); return PartialView("_Internet", _dataInternet.Lista(IdPJ)); } else throw new Exception("Erro;"); }
public ActionResult ExcluirInternet(int idInternet) { Internet _dataInternet = new Internet(); InternetModel _internetOld = _dataInternet.Busca(idInternet); _dataInternet.Excluir(idInternet); return PartialView("_Internet", _dataInternet.Lista(_internetOld.IdPessoa)); }
public ActionResult InserirInternetSession(string endereco, int idTipo) { Internet _dataInternet = new Internet(); InternetModel internetModel = new InternetModel() { Nome = endereco, TipoInternet = new TipoInternetModel { Id = idTipo } }; if (internetModel.Nome.Length < 100) { List<InternetModel> listaInternet = new List<InternetModel>(); if (Session["InternetPJ"] != null) listaInternet = (List<InternetModel>)Session["InternetPJ"]; int id = listaInternet.Count == 0 ? 1 : listaInternet.Last().Id + 1; internetModel.Id = id; internetModel.TipoInternet = new TipoInternet().Lista(idTipo).FirstOrDefault(); listaInternet.Add(internetModel); Session["InternetPJ"] = listaInternet; return PartialView("_Internet", listaInternet); } else throw new Exception("Erro;"); }