public JsonResult SalvarCidade(CidadeViewModel 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 vm = Mapper.Map <CidadeModel>(model);
                    var id = vm.Salvar();
                    if (id > 0)
                    {
                        idSalvo = id.ToString();
                    }
                    else
                    {
                        resultado = "ERRO";
                    }
                }
                catch (Exception ex)
                {
                    resultado = "ERRO";
                }
            }

            return(Json(new { Resultado = resultado, Mensagens = mensagens, IdSalvo = idSalvo }));
        }
Exemplo n.º 2
0
        public IActionResult AddEditCidade(long?id, CidadeViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool   isNew  = !id.HasValue;
                    Cidade cidade = isNew ? new Cidade
                    {
                    } : context.Set <Cidade>().SingleOrDefault(s => s.Id == id.Value);

                    cidade.Descricao = model.Descricao;
                    cidade.Estado    = model.Estado;

                    if (isNew)
                    {
                        context.Add(cidade);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public void Update(CidadeViewModel obj)
        {
            var cidade = Mapper.Map <CidadeViewModel, Cidade>(obj);

            _cidadeService.Update(cidade);
            _cidadeService.SaveChanges();
        }
Exemplo n.º 4
0
        public CidadeViewModel Edit(CidadeViewModel Model)
        {
            try
            {
                daoCidade DaoCidade = new daoCidade();

                CIDADE ModelEdit = DaoCidade.FindCidade(Model).FirstOrDefault();
                Model.toEdit(ModelEdit);
                DaoCidade.Update(ModelEdit);
                return(Model);
            }
            catch (DbEntityValidationException e)
            {
                #region Detalha Erro
                string erro = "";

                foreach (var eve in e.EntityValidationErrors)
                {
                    erro = "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:";
                    erro = String.Format(erro, eve.Entry.Entity.GetType().Name, eve.Entry.State);

                    foreach (var ve in eve.ValidationErrors)
                    {
                        erro = erro + String.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                    }
                }

                #endregion
                throw new Exception(erro.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
 public ActionResult Create([Bind(Include = "Id,Nome,Id_Estado")] CidadeViewModel cidadeViewModel)
 {
     if (ModelState.IsValid)
     {
         using (UnitOfWork.UnitOfWork uow = new UnitOfWork.UnitOfWork())
         {
             try
             {
                 Cidade cidade = new Cidade();
                 cidade           = Mapper.Map <Cidade>(cidadeViewModel);
                 cidade.Id        = Guid.NewGuid();
                 cidade.TimesTamp = DateTime.Now;
                 uow.CidadeRepositorio.Adcionar(cidade);
                 uow.Commit();
                 TempData["mensagem"] = string.Format("Registro Cadastrado com Sucesso!");
                 return(RedirectToAction("Index"));
             }
             catch (Exception ex)
             {
                 TempData["mensagem"] = string.Format("Não Foi Possivel Gravar o Registro!\n {0}", ex.Message);
                 return(View());
             }
             finally
             {
                 uow.Dispose();
             }
         }
     }
     return(View(cidadeViewModel));
 }
        public IActionResult Cadastro(CidadeViewModel cidade)
        {
            if (ModelState.IsValid)
            {
                Cidade objCidade = new Cidade()
                {
                    Codigo = cidade.Codigo,
                    Nome   = cidade.Nome,
                    UF     = cidade.UF
                };

                if (cidade.Codigo == null)
                {
                    myContexto.Cidade.Add(objCidade);
                }
                else
                {
                    myContexto.Entry(objCidade).State = EntityState.Modified;
                }

                myContexto.SaveChanges();
            }
            else
            {
                cidade.ListaEstado = ListaEstado();
                return(View(cidade));
            }

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,Nome,Id_Estado")] CidadeViewModel cidadeViewModel)
 {
     if (ModelState.IsValid)
     {
         using (UnitOfWork.UnitOfWork uow = new UnitOfWork.UnitOfWork())
         {
             try
             {
                 Cidade cidade = new Cidade();
                 cidade           = Mapper.Map <Cidade>(cidadeViewModel);
                 cidade.TimesTamp = DateTime.Now;
                 uow.CidadeRepositorio.Atualizar(cidade);
                 uow.Commit();
                 TempData["mensagem"] = string.Format("Registro Alterado Com Sucesso!");
                 return(RedirectToAction("Index"));
             }
             catch (Exception ex)
             {
                 TempData["mensagem"] = string.Format("Ocorreu ao Alterar o Registro!\n {0}", ex.Message);
                 return(RedirectToAction("Index"));
             }
             finally
             {
                 uow.Dispose();
             }
         }
     }
     return(View(cidadeViewModel));
 }
        // GET: CidadeViewModels/Details/5
        public ActionResult Details(Guid?id)
        {
            CidadeViewModel cidadeViewModel = null;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (UnitOfWork.UnitOfWork uow = new UnitOfWork.UnitOfWork())
            {
                try
                {
                    cidadeViewModel = Mapper.Map <CidadeViewModel>(uow.CidadeRepositorio.Get(x => x.Id == id));
                    return(View(cidadeViewModel));
                }
                catch (Exception ex)
                {
                    TempData["mensagem"] = string.Format("Ocorreu um Erro! \n {0}", ex.Message);
                    if (cidadeViewModel == null)
                    {
                        return(HttpNotFound());
                    }
                    return(View(cidadeViewModel));
                }
                finally
                {
                    uow.Dispose();
                }
            }
        }
Exemplo n.º 9
0
        public static Expression <Func <CIDADE, bool> > ToExpression(this CidadeViewModel Filter)
        {
            Expression <Func <CIDADE, bool> > predicate = PredicateBuilder.True <CIDADE>();


            if (!string.IsNullOrEmpty(Filter.UKEY))
            {
                predicate = predicate.And(x => x.UKEY == Filter.UKEY);
                return(predicate);
            }

            if (Filter.Tipo == fncEnum.eOperacao.Contido)
            {
                if (Filter.CI_001_N != 0 && Filter.CI_001_N != null)
                {
                    predicate = predicate.And(x => x.CI_001_N.ToString().Contains(Filter.CI_001_N.ToString()));
                }

                if (!string.IsNullOrEmpty(Filter.CI_002_C))
                {
                    predicate = predicate.And(x => x.CI_002_C.ToUpper().ToString().Contains(Filter.CI_002_C.ToUpper().ToString()));
                }

                if (!string.IsNullOrEmpty(Filter.CI_003_C))
                {
                    predicate = predicate.And(x => x.CI_003_C.ToUpper().ToString().Contains(Filter.CI_003_C.ToUpper().ToString()));
                }
            }
            else if (Filter.Tipo == fncEnum.eOperacao.Igual)
            {
                if (Filter.CI_001_N != 0 && Filter.CI_001_N != null)
                {
                    predicate = predicate.And(x => x.CI_001_N == Filter.CI_001_N);
                }

                if (!string.IsNullOrEmpty(Filter.CI_002_C))
                {
                    predicate = predicate.And(x => x.CI_002_C.ToUpper().ToString() == Filter.CI_002_C.ToUpper().ToString());
                }

                if (!string.IsNullOrEmpty(Filter.CI_003_C))
                {
                    predicate = predicate.And(x => x.CI_003_C.ToUpper().ToString() == Filter.CI_003_C.ToUpper().ToString());
                }
            }

            if (Filter.CI_004_N != fncEnum.eCapital.Ambos)
            {
                if (Filter.CI_004_N == fncEnum.eCapital.Sim)
                {
                    predicate = predicate.And(x => x.CI_004_L == true);
                }
                else
                {
                    predicate = predicate.And(x => x.CI_004_L == false);
                }
            }

            return(predicate);
        }
Exemplo n.º 10
0
        public void Delete(string ukey)
        {
            try
            {
                if (dbs.Connexao())
                {
                    CidadeViewModel Filter = new CidadeViewModel()
                    {
                        UKEY = ukey
                    };

                    List <CIDADE> ListModel = dbs.Cidade.Where(Filter.ToExpression()).ToList();

                    foreach (CIDADE item in ListModel)
                    {
                        dbs.Entry(item).State = EntityState.Deleted;
                        dbs.SaveChanges();
                    }
                }
                else
                {
                    if (MvcApplication.CidadePublic.Where(x => x.UKEY == ukey).Count() > 0)
                    {
                        CIDADE Model = MvcApplication.CidadePublic.Where(x => x.UKEY == ukey).First();
                        MvcApplication.CidadePublic.Remove(Model);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
Exemplo n.º 11
0
        // GET: Cidade
        public ActionResult Index()
        {
            //cria a listagem que será exibida na tela
            List <CidadeViewModel> lista = new List <CidadeViewModel>();

            //abre a conexao com o banco
            using (CrudModel connection = new CrudModel())
            {
                //faz o select no banco
                List <cidade> listaCidades = connection.cidades.ToList();

                //percorre todos os itens retornados do select
                foreach (var item in listaCidades)
                {
                    //cria um objeto da listagem da tela
                    CidadeViewModel cidadeTela = new CidadeViewModel();
                    //preenche as informações do objeto da tela com o item corrente do select
                    cidadeTela.Id   = item.id;
                    cidadeTela.Nome = item.nome;
                    //adiciona o objeto da tela na listagem da tela
                    lista.Add(cidadeTela);
                }
            }

            //retorna a lista para a tela
            return(View(lista));
        }
Exemplo n.º 12
0
        public void Remove(CidadeViewModel cidadeViewModel)
        {
            var cidade = Mapper.Map <CidadeViewModel, Cidade>(cidadeViewModel);

            BeginTransaction();
            _cidadeService.Remove(cidade);
            Commit();
        }
Exemplo n.º 13
0
        public ActionResult Create()
        {
            CidadeViewModel cidadeViewModel = new CidadeViewModel();

            cidadeViewModel.Cidade = new Cidade();

            return(View(cidadeViewModel));
        }
Exemplo n.º 14
0
        public ActionResult Cidades()
        {
            CidadeViewModel cidadeViewModel = new CidadeViewModel();

            cidadeViewModel.Cidades = _cidadeService.GetAll();

            return(View(cidadeViewModel));
        }
Exemplo n.º 15
0
        public ActionResult Edit(int id)
        {
            CidadeViewModel cidadeViewModel = new CidadeViewModel();

            cidadeViewModel.Cidade = _cidadeService.GetById(id);

            return(View(cidadeViewModel));
        }
Exemplo n.º 16
0
        public ActionResult Create()
        {
            ViewData["COLOR"]    = "VERDE";
            ViewData["Message"]  = "";
            ViewData["SubTitle"] = "Criar Cidade";
            CidadeViewModel Model = new CidadeViewModel();

            return(View(Model));
        }
        public CidadeViewModel Adicionar(CidadeViewModel cidadeViewModel)
        {
            var cidadeCommand = Mapper.Map <AdicionaNovaCidadeCommand>(cidadeViewModel);

            var result = _handlerAdicionaNovaCidade.Handle(cidadeCommand);

            Commit();

            return(cidadeViewModel);
        }
        public CidadeViewModel Atualizar(CidadeViewModel cidadeViewModel)
        {
            var cidadeCommand = Mapper.Map <AtualizaCidadeCommand>(cidadeViewModel);

            var result = _handlerAtualizaCidade.Handle(cidadeCommand);

            Commit();

            return(cidadeViewModel);
        }
        public HttpResponseMessage Post(CidadeViewModel cidade)
        {
            if (ModelState.IsValid)
            {
                _repositorioDeCidades.Inserir(cidade.Model());

                return(Request.CreateResponse(HttpStatusCode.Created, cidade));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }
        public async Task <ActionResult <CidadeViewModel> > Adicionar(CidadeViewModel CidadeViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            await _cidadeService.Adicionar(_mapper.Map <Cidade>(CidadeViewModel));

            return(CustomResponse(CidadeViewModel));
        }
Exemplo n.º 21
0
        public PessoaJuridicaFormViewModel PessoaJuridicaPorId(long pessoaJuridicaId)
        {
            var  cidadeModel = new CidadeViewModel();
            var  telefone    = new StringBuilder();
            long telmax;
            var  entidade =
                _pessoaJuridicaServico.PesquisarPessoaJuridica("", "", "", pessoaJuridicaId, "").FirstOrDefault();

            if (entidade != null)
            {
                var listaUf           = _cidadeServico.ObterTodosEstados();
                var listaCidade       = _cidadeServico.ObterCidadesPorEstado(entidade.NomeEstado);
                var telefones         = _telefoneServico.ObterTelefonePessoaJuridica(pessoaJuridicaId);
                var viewDinamicaModel = _viewDinamicaAppServico.Carregar("PESSOASJUR", "padrão", null, pessoaJuridicaId,
                                                                         true);
                var listaCanalDeEnvio = _entidadeCampoValorServico.ObterPor("pessoasJuridicas",
                                                                            "canalEntidadesCamposValoresID", true, null);
                var listaTipo = _entidadeCampoValorServico.ObterPor("pessoasJuridicas", "tipoEntidadesCamposValoresID",
                                                                    true, null);

                if (telefones.Any())
                {
                    telmax = telefones.Max(c => c.Id);
                    var tel = telefones.FirstOrDefault(c => c.Id == telmax);
                    if (tel != null)
                    {
                        telefone.Append(tel.Ddd);
                        telefone.Append(tel.Numero);
                    }
                }

                if (entidade.CidadeId != null)
                {
                    var cidade = _cidadeServico.ObterPorId((long)entidade.CidadeId);
                    cidadeModel = new CidadeViewModel(cidade.Id, cidade.Nome, cidade.Uf);
                }

                return(new PessoaJuridicaFormViewModel(entidade.Id, entidade.RazaoSocial, entidade.NomeFantasia,
                                                       entidade.InscricaoEstadual, entidade.Cnpj, entidade.DataDeConstituicao, listaUf, entidade.NomeEstado,
                                                       entidade.CidadeId, listaCidade, entidade.EmailPrincipal, entidade.Logradouro, entidade.Numero,
                                                       entidade.Bairro, entidade.CodigoPostal, entidade.Complemento, telefone.ToString(), viewDinamicaModel,
                                                       cidadeModel, entidade.CriadoEm, entidade.AlteradoEm, listaCanalDeEnvio, listaTipo,
                                                       entidade.AceitaComunicados, entidade.CanalEntidadesCamposValoresId,
                                                       entidade.TipoEntidadesCamposValoresId));
            }

            var validacaoRetorno = new ValidationResult();

            validacaoRetorno.Add(new ValidationError("Nenhum cliente encontrado com os parâmetros informados."));
            return(new PessoaJuridicaFormViewModel {
                ValidationResult = validacaoRetorno
            });
        }
        public ActionResult Cadastrar(CidadeViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var cidade = viewModel.Model();
                _repositorioDeCidades.Inserir(cidade);
                return(RedirectToAction("Index"));
            }

            ViewBag.Estados = _repositorioDeEstados.Todos();
            return(View(viewModel));
        }
 public string RemoverCidade([FromBody] CidadeViewModel Dados)
 {
     if (CheckSession())
     {
         _registerAppService.RemoverCidade(Dados);
         return(RetornaNotificacaoFormatada());
     }
     else
     {
         return("Sessão Expirou");
     }
 }
Exemplo n.º 24
0
        public CidadeViewModel Atualizar(CidadeViewModel cidadeViewModel)
        {
            var cidade = Mapper.Map <Cidade>(cidadeViewModel);
            var obj    = _cidadeDomainService.Atualizar(cidade);

            if (!Commit())
            {
                //Parte reservada para retornar o erro
                return(null);
            }
            return(Mapper.Map <CidadeViewModel>(obj));
        }
Exemplo n.º 25
0
        public ActionResult Edit(string id, CidadeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var cidade = Mapper.Map <CidadeViewModel, Cidade>(model);
                _cidadeApplicationService.Update(cidade);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public ActionResult Edit(CidadeViewModel cidade)
        {
            if (ModelState.IsValid)
            {
                var cidadeDomain = Mapper.Map <CidadeViewModel, Cidade>(cidade);
                _cidadeApp.Update(cidadeDomain);

                return(RedirectToAction("Index"));
            }

            return(View(cidade));
        }
Exemplo n.º 27
0
        public virtual void Adicionar(CidadeViewModel cidadeVM)
        {
            var entidade = new Cidade
            {
                OpenWeatherId = cidadeVM.OpenWeatherId,
                Nome          = cidadeVM.Nome,
                Latitude      = cidadeVM.Latitude,
                Longitude     = cidadeVM.Longitude,
                Pais          = cidadeVM.Pais
            };

            base.Adicionar(entidade);
        }
Exemplo n.º 28
0
        public CidadeViewModel Salvar(CidadeViewModel model)
        {
            string URI = Constantes.URL + "cidade";

            if (model.Id == 0)
            {
                return(new Operacao <CidadeViewModel>().Insert(URI, model));
            }
            else
            {
                return(new Operacao <CidadeViewModel>().Update(URI, model));
            }
        }
Exemplo n.º 29
0
        public ActionResult Edit([Bind(Include = "IdCidade,Nome,IdEstado")] CidadeViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Cidade cidade = Mapper.Map <CidadeViewModel, Cidade>(viewModel);

                repositorioCidade.Alterar(cidade);

                return(RedirectToAction("Index"));
            }
            //ViewBag.IdEstado = new SelectList(db.Estados, "IdEstado", "Nome", cidade.IdEstado);

            return(View(viewModel));
        }
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CidadeViewModel cidadeViewModel = _cidadeAppService.ObterPorId(id.Value);

            if (cidadeViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(cidadeViewModel));
        }