Beispiel #1
0
        public void UpdateMarcaProduto(MarcaProdutoDTO marcaProdutoDTO)
        {
            try
            {
                if (marcaProdutoDTO == null)
                {
                    throw new Exception("Objeto não instânciado.");
                }

                var persistido = _marcaProdutoRepository.Get(marcaProdutoDTO.Id);
                if (persistido == null)
                {
                    throw new Exception("MarcaProduto não encontrado.");
                }

                var corrente = ProdutoFactory.CreateMarcaProduto(marcaProdutoDTO.Nome
                                                                 );

                corrente.Id = persistido.Id;

                AlterarMarcaProduto(persistido, corrente);
            }
            catch (ApplicationValidationErrorsException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                LoggerFactory.CreateLog().LogError(ex);
                throw new Exception("O servidor não respondeu.");
            }
        }
Beispiel #2
0
        public MarcaProdutoDTO AddMarcaProduto(MarcaProdutoDTO MarcaProdutoDTO)
        {
            try
            {
                if (MarcaProdutoDTO == null)
                {
                    throw new Exception("Objeto não instânciado.");
                }

                var marcaProduto = ProdutoFactory.CreateMarcaProduto(MarcaProdutoDTO.Nome
                                                                     );

                SalvarMarcaProduto(marcaProduto);

                var adapter = TypeAdapterFactory.CreateAdapter();
                return(adapter.Adapt <MarcaProduto, MarcaProdutoDTO>(marcaProduto));
            }
            catch (ApplicationValidationErrorsException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                LoggerFactory.CreateLog().LogError(ex);
                throw new Exception("O servidor não respondeu.");
            }
        }
Beispiel #3
0
        public ActionResult Editar(int?id, string error)
        {
            try
            {
                MarcaProdutoDTO MarcaProdutoDTO;
                if (!id.HasValue || id == 0)
                {
                    MarcaProdutoDTO = new MarcaProdutoDTO();
                }
                else
                {
                    MarcaProdutoDTO = _marcaProdutoAppService.FindMarcaProduto(id.Value);
                }

                return(View(MarcaProdutoDTO));
            }
            catch (Exception ex)
            {
                return(View("Error", ex));
            }
        }
Beispiel #4
0
        public ActionResult POSTEditar(MarcaProdutoDTO marcaProdutoDTO)
        {
            try
            {
                if (marcaProdutoDTO.Id == 0)
                {
                    marcaProdutoDTO = _marcaProdutoAppService.AddMarcaProduto(marcaProdutoDTO);
                }
                else
                {
                    _marcaProdutoAppService.UpdateMarcaProduto(marcaProdutoDTO);
                }


                return(JavaScript(
                           "MensagemSucesso(' + mensagemSucesso + ');" +
                           "CarregarPaginaAjax('" + Url.Action("Index", "MarcaProduto") + "');"));
            }
            catch (Exception ex)
            {
                TratamentoErro.Tratamento(this, ex);
                return(View("Editar", marcaProdutoDTO));
            }
        }