示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("ClienteEnderecoId,ClienteId,Rua,Numero,Bairro,Cidade,Estado,Cep,Referencia,Ativo,Padrao")] ClienteEnderecoModel clienteEnderecoModel)
        {
            if (id != clienteEnderecoModel.ClienteEnderecoId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(clienteEnderecoModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClienteEnderecoModelExists(clienteEnderecoModel.ClienteEnderecoId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), "Cliente"));
            }
            ViewData["ClienteId"] = new SelectList(_context.ClienteModel, "ClienteId", "NomeFantasia", clienteEnderecoModel.ClienteId);
            return(View(clienteEnderecoModel));
        }
        /// <summary>
        /// Obtem um endereço de cliente e converte em Model
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <param name="mensagemErro"></param>
        /// <returns></returns>
        private bool ObterClienteEndereco(Guid id, ref ClienteEnderecoModel model, ref string mensagemErro)
        {
            //Preparar a requisição e o retorno
            RetornoObterDto <ClienteEnderecoDto> retorno = new RetornoObterDto <ClienteEnderecoDto>();
            RequisicaoObterDto requisicaoDto             = new RequisicaoObterDto()
            {
                Id            = id,
                Identificacao = SessaoUsuario.SessaoLogin.Identificacao,
                IdUsuario     = SessaoUsuario.SessaoLogin.IdUsuario
            };

            //Consumir o serviço
            ClienteEnderecoBll clienteBll = new ClienteEnderecoBll(true);

            clienteBll.Obter(requisicaoDto, ref retorno);

            //Tratar o retorno
            if (retorno.Retorno == false)
            {
                mensagemErro = retorno.Mensagem;
                return(false);
            }
            else
            {
                //Converter para Model
                return(model.ConverterDtoParaModel(retorno.Entidade, ref mensagemErro));
            }
        }
        /// <summary>
        /// Chama a tela para editar um endereço de cliente
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Editar(Guid id, string nomeCliente)
        {
            //Se não tiver login, encaminhar para a tela de login
            if (string.IsNullOrWhiteSpace(SessaoUsuario.SessaoLogin.Identificacao))
            {
                return(RedirectToAction("Login", "Usuario"));
            }

            //Model a ser populada
            ClienteEnderecoModel model = new ClienteEnderecoModel();
            string mensagemRetorno     = "";

            //Obtem o cliente pelo ID
            if (!this.ObterClienteEndereco(id, ref model, ref mensagemRetorno))
            {
                ViewBag.MensagemErro = mensagemRetorno;
                return(View("Erro"));
            }

            model.NomeCliente = nomeCliente;

            TempData["Retorno"] = "EDITANDO";

            //Chamar a view
            return(View(model));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("ClienteEnderecoId,ClienteId,Rua,Numero,Bairro,Cidade,Estado,Cep,Referencia,Ativo,Padrao")] ClienteEnderecoModel clienteEnderecoModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clienteEnderecoModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClienteId"] = new SelectList(_context.ClienteModel, "ClienteId", "NomeFantasia", clienteEnderecoModel.ClienteId);
            return(View(clienteEnderecoModel));
        }
        public ActionResult Incluir(ClienteEnderecoModel model)
        {
            //Se não tiver login, encaminhar para a tela de login
            if (string.IsNullOrWhiteSpace(SessaoUsuario.SessaoLogin.Identificacao))
            {
                return(RedirectToAction("Login", "Usuario"));
            }

            //Validar a model recebida
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //Converter para DTO
            ClienteEnderecoDto clienteEnderecoDto = new ClienteEnderecoDto();
            string             mensagemErro       = "";

            if (!model.ConverterModelParaDto(ref clienteEnderecoDto, ref mensagemErro))
            {
                ModelState.AddModelError("", $"Erro ao converter para Dto: {mensagemErro}");
                return(View(model));
            }

            clienteEnderecoDto.Id = Guid.NewGuid();

            //Preparar requisição e retorno
            RetornoDto retorno = new RetornoDto();
            RequisicaoEntidadeDto <ClienteEnderecoDto> requisicaoDto = new RequisicaoEntidadeDto <ClienteEnderecoDto>()
            {
                EntidadeDto   = clienteEnderecoDto,
                Identificacao = SessaoUsuario.SessaoLogin.Identificacao,
                IdUsuario     = SessaoUsuario.SessaoLogin.IdUsuario
            };

            //Consumir o serviço
            ClienteEnderecoBll clienteEnderecoBll = new ClienteEnderecoBll(true);

            clienteEnderecoBll.Incluir(requisicaoDto, ref retorno);

            //Verificar o retorno
            if (retorno.Retorno == false)
            {
                //Se houver erro, exibir na tela de inclusão
                ModelState.AddModelError("", retorno.Mensagem);
                return(View(model));
            }

            TempData["Retorno"] = "INCLUIDO";

            //Retornar para o cliente
            return(RedirectToAction("Visualizar", "Cliente", new { id = model.IdCliente }));
        }
        public ActionResult Editar(ClienteEnderecoModel model)
        {
            //Se não tiver login, encaminhar para a tela de login
            if (string.IsNullOrWhiteSpace(SessaoUsuario.SessaoLogin.Identificacao))
            {
                return(RedirectToAction("Login", "Usuario"));
            }

            //Valida a entidade recebida
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //Converte para DTO
            ClienteEnderecoDto clienteDto   = new ClienteEnderecoDto();
            string             mensagemErro = "";

            if (!model.ConverterModelParaDto(ref clienteDto, ref mensagemErro))
            {
                ViewBag.MensagemErro = mensagemErro;
                return(View("Erro"));
            }

            //Preparar requisição e retorno
            RetornoDto retorno = new RetornoDto();
            RequisicaoEntidadeDto <ClienteEnderecoDto> requisicaoDto = new RequisicaoEntidadeDto <ClienteEnderecoDto>()
            {
                EntidadeDto   = clienteDto,
                Identificacao = SessaoUsuario.SessaoLogin.Identificacao,
                IdUsuario     = SessaoUsuario.SessaoLogin.IdUsuario
            };

            //Consumir o serviço
            ClienteEnderecoBll clienteBll = new ClienteEnderecoBll(true);

            clienteBll.Editar(requisicaoDto, ref retorno);

            //Tratar o retorno
            if (retorno.Retorno == false)
            {
                ModelState.AddModelError("", retorno.Mensagem);
                return(View(model));
            }

            TempData["Retorno"] = "ALTERADO";

            //Retornar para o cliente
            return(RedirectToAction("Visualizar", "Cliente", new { id = model.IdCliente }));
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(ClienteEnderecoModel model)
        {
            #region Regras

            var update = Get(model.Id);
            update.Logradouro    = !string.IsNullOrEmpty(model.Logradouro)? model.Logradouro:update.Logradouro;
            update.Numero        = !string.IsNullOrEmpty(model.Numero) ? model.Numero : update.Numero;
            update.Bairro        = !string.IsNullOrEmpty(model.Bairro) ? model.Bairro : update.Bairro;
            update.Complemento   = !string.IsNullOrEmpty(model.Complemento) ? model.Complemento : update.Complemento;
            update.CEP           = !string.IsNullOrEmpty(model.CEP) ? model.CEP : update.CEP;
            update.IdCidade      = model.IdCidade > 0? model.IdCidade: update.IdCidade;
            update.DataCadastro  = update.DataCadastro;
            update.DataAlteracao = DateTime.Now;
            update.Ativo         = update.Ativo;

            #endregion

            return(_rep.Update(update));
        }
        /// <summary>
        /// Chama a tela para incluir um endereço de cliente
        /// </summary>
        /// <returns></returns>
        public ActionResult Incluir(Guid Id, string nomeCliente)
        {
            //Se não tiver login, encaminhar para a tela de login
            if (string.IsNullOrWhiteSpace(SessaoUsuario.SessaoLogin.Identificacao))
            {
                return(RedirectToAction("Login", "Usuario"));
            }

            //Cliente a ser incluído
            ClienteEnderecoModel model = new ClienteEnderecoModel()
            {
                Id          = Guid.NewGuid(),
                IdCliente   = Id,
                NomeCliente = nomeCliente
            };

            TempData["Retorno"] = "INCLUINDO";

            //Chamar a view
            return(View(model));
        }