public ActionResult SalvarUf(UfModel model) { var resultado = "OK"; var mensagens = new List <string>(); var idSalvo = string.Empty; if (!ModelState.IsValid) { resultado = "AVISO"; mensagens = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList(); } else { try { var id = model.Salvar(); if (id > 0) { idSalvo = id.ToString(); } else { resultado = "ERRO"; } } catch (Exception ex) { resultado = "ERRO"; } } return(Json(new { Resultado = resultado, Mensagens = mensagens, IdSalvo = idSalvo })); }
public void E_Possivel_Mapear_osModelos_Uf() { var model = new UfModel() { Id = Guid.NewGuid(), Nome = Faker.Address.UsState(), Sigla = Faker.Address.UsState().Substring(1, 3), CreateAt = DateTime.UtcNow, UpdateAt = DateTime.UtcNow }; var listaEntity = new List <UfEntity>(); for (int i = 0; i < 5; i++) { var item = new UfEntity() { Id = Guid.NewGuid(), Nome = Faker.Address.UsState(), Sigla = Faker.Address.UsState().Substring(1, 3), CreateAt = DateTime.UtcNow, UpdateAt = DateTime.UtcNow }; listaEntity.Add(item); } // Model => Entity var entity = Mapper.Map <UfEntity>(model); Assert.Equal(entity.Id, model.Id); Assert.Equal(entity.Nome, model.Nome); Assert.Equal(entity.Sigla, model.Sigla); Assert.Equal(entity.CreateAt, model.CreateAt); Assert.Equal(entity.UpdateAt, model.UpdateAt); // Entity => Dto var dto = Mapper.Map <UfDto>(entity); Assert.Equal(dto.Id, entity.Id); Assert.Equal(dto.Nome, entity.Nome); Assert.Equal(dto.Sigla, entity.Sigla); var listaDto = Mapper.Map <List <UfDto> >(listaEntity); Assert.True(listaDto.Count() == listaEntity.Count()); for (int i = 0; i < listaDto.Count(); i++) { Assert.Equal(listaDto[i].Id, listaEntity[i].Id); Assert.Equal(listaDto[i].Nome, listaEntity[i].Nome); Assert.Equal(listaDto[i].Sigla, listaEntity[i].Sigla); } // Dto => Model var ufModel = Mapper.Map <UfModel>(dto); Assert.Equal(ufModel.Id, dto.Id); Assert.Equal(ufModel.Nome, dto.Nome); Assert.Equal(ufModel.Sigla, dto.Sigla); }
public void Teste_Mapper() { var model = new UfModel { Id = Guid.NewGuid(), Nome = Faker.Address.UsState(), Sigla = Faker.Address.UsState().Substring(1, 3), CreateAt = DateTime.Now, UpdateAt = DateTime.Now }; var listaEntity = new List <UfEntity>(); for (int i = 0; i < 5; i++) { var item = new UfEntity { Id = Guid.NewGuid(), Nome = Faker.Address.UsState(), Sigla = Faker.Address.UsState().Substring(1, 3), CreateAt = DateTime.Now, UpdateAt = DateTime.Now }; listaEntity.Add(item); } //Model to Entity var dtoToEntity = Mapper.Map <UfEntity>(model); Assert.Equal(dtoToEntity.Id, model.Id); Assert.Equal(dtoToEntity.Nome, model.Nome); Assert.Equal(dtoToEntity.Sigla, model.Sigla); Assert.Equal(dtoToEntity.CreateAt, model.CreateAt); Assert.Equal(dtoToEntity.UpdateAt, model.UpdateAt); //Entity to DTO var UfDto = Mapper.Map <UfDto>(dtoToEntity); Assert.Equal(UfDto.Id, dtoToEntity.Id); Assert.Equal(UfDto.Nome, dtoToEntity.Nome); Assert.Equal(UfDto.Sigla, dtoToEntity.Sigla); var listDto = Mapper.Map <List <UfDto> >(listaEntity); Assert.True(listaEntity.Count == listDto.Count()); for (int i = 0; i < listDto.Count(); i++) { Assert.Equal(listDto[i].Id, listaEntity[i].Id); Assert.Equal(listDto[i].Nome, listaEntity[i].Nome); Assert.Equal(listDto[i].Sigla, listaEntity[i].Sigla); } var ufModel = Mapper.Map <UfDto>(dtoToEntity); }
public UfModel GetByUF(string name) { UfModel obj = null; try { obj = DbSet.FirstOrDefault(x => x.UfNome == name); } catch (Exception ex) { _log.LogError(ex.Message, ex); } return(obj); }
public UfModel GetById(int id) { UfModel obj = null; try { obj = DbSet.FirstOrDefault(x => x.id == id); } catch (Exception ex) { _log.LogError(ex.Message, ex); } return(obj); }
private void UFmudou(object sender, EventArgs e) { codMunic_comboBox.Items.Clear(); ComboBox combo = (ComboBox)sender; UfModel uf = (UfModel)combo.SelectedItem; MunicipioFacede facede = new MunicipioFacede(); List <MunicipioModel> municipios = facede.RetornaDadosMunicipiosFacede(uf.codigo); codMunic_comboBox.DisplayMember = "nome"; codMunic_comboBox.ValueMember = "codigo"; object[] x = municipios.ToArray(); codMunic_comboBox.Items.AddRange(x); }
public ActionResult Manager() { int idEvento = int.Parse(Request.QueryString["EventoID"]); string estado = Request.QueryString["estado"]; ViewBag.UF = "-- Select UF --"; Evento e = new Evento(); using (UfModel uf = new UfModel()) { ViewBag.Estados = uf.Ufs(); } using (CidadeModel cm = new CidadeModel()) { ViewBag.Cidades = cm.Cidades(); } using (EsporteModel em = new EsporteModel()) { ViewBag.Esportes = em.Esportes(); } using (OrganizadorModel model = new OrganizadorModel()) { model.UpdateQualificacaoOrg((Session["usuario"] as Usuario).Id_usuario); } using (EventoModel model = new EventoModel()) { if (model.isAdmin(idEvento, (Session["usuario"] as Usuario).Id_usuario)) { e = model.Read(idEvento); ViewBag.listSubs = model.InscritosEvento(e.Id_Evento); ViewBag.Noticias = model.NoticiasEvento(e.Id_Evento); return(View(e)); } else { return(RedirectToAction("FeedEvents", "Event")); } } }
public ActionResult Search(string estado) { ViewBag.UF = "UF"; using (UfModel uf = new UfModel()) { ViewBag.Estados = uf.Ufs(); } using (CidadeModel cm = new CidadeModel()) { ViewBag.Cidades = cm.Cidades(); } using (EsporteModel em = new EsporteModel()) { ViewBag.Esportes = em.Esportes(); } return(View()); }
public ActionResult Create(string estado, FormCollection form) { ViewBag.UF = "-- Select UF --"; using (UfModel uf = new UfModel()) { ViewBag.Estados = uf.Ufs(); } using (CidadeModel cm = new CidadeModel()) { ViewBag.Cidades = cm.Cidades(); } using (EsporteModel em = new EsporteModel()) { ViewBag.Esportes = em.Esportes(); } return(View()); }
public ActionResult ExcluirUf(int id) { return(Json(UfModel.ExcluirPeloId(id))); }
public ActionResult RecuperarEstado(int id) { return(Json(UfModel.RecuperarPeloId(id))); }
public ActionResult Index() { return(View(UfModel.RecuperarLista())); }
public bool Add(UfModel model) { return(_rep.Add(model)); }
public ActionResult Index() { ViewBag.ListaUf = UfModel.RecuperarLista(); return(View(CidadeModel.RecuperarLista())); }