Example #1
0
        public NotificationResult Salvar(Venda entidade)
        {
            var notificationResult = new NotificationResult();

            try
            {
                if (entidade.idProduto <= 0)
                {
                    notificationResult.Add(new NotificationError("Codigo do Produto Invalido!", NotificationErrorType.USER));
                }

                if (entidade.idCliente <= 0)
                {
                    notificationResult.Add(new NotificationError("Código do Cliente Inválido!", NotificationErrorType.USER));
                }

                if (entidade.QtdVendida <= 0)
                {
                    notificationResult.Add(new NotificationError("Quantidade De Produtos Inválida!", NotificationErrorType.USER));
                }

                if (entidade.idVendedor <= 0)
                {
                    notificationResult.Add(new NotificationError("Código do Vendedor Inválido!", NotificationErrorType.USER));
                }

                if (entidade.ValorTotal <= 00.00)
                {
                    notificationResult.Add(new NotificationError("Valor Informado Inválido!", NotificationErrorType.USER));
                }

                if (entidade.DataVenda < DateTime.Now)
                {
                    notificationResult.Add(new NotificationError("Data de Venda Inválida!", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.Descricao))
                {
                    notificationResult.Add(new NotificationError("Descrição de Venda Inválida!", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.EnderecoImagem))
                {
                    notificationResult.Add(new NotificationError("URL da Imagem Inválida ou Não Suportada!", NotificationErrorType.USER));
                }

                if (notificationResult.IsValid)
                {
                    _vendaRepositorio.Adicionar(entidade);
                    notificationResult.Add("Venda Realizada com sucesso.");
                }

                notificationResult.Result = entidade;

                return(notificationResult);
            }
            catch (Exception ex)
            {
                return(notificationResult.Add(new NotificationError(ex.Message)));
            }
        }