예제 #1
0
        public void Insert(MoneyDonation donation)
        {
            FinancialBoxRepository financialBoxRepository = new FinancialBoxRepository();

            if (donation == null)
            {
                throw new Exception("A doação não pode ser nulo");
            }

            if (donation.Value <= 0)
            {
                throw new Exception("A doação deve ser maior que 0");
            }

            if (string.IsNullOrEmpty(donation.Donor.Name))
            {
                throw new Exception("O doador precisa ter Name");
            }

            if (donation.Date == null || donation.Date == DateTime.MinValue)
            {
                throw new Exception("Informe a data da doação");
            }

            moneyDonationRepository.Insert(donation);

            FinancialBox financialBox = new FinancialBox();

            financialBox.Date        = donation.Date;
            financialBox.Description = "Caixa atualizado atraves da doação " + donation.Id;
            financialBox.Value       = donation.Value;

            financialBoxRepository.Insert(financialBox);
        }
예제 #2
0
        private void btConfirma_Click(object sender, EventArgs e)
        {
            try
            {
                FinancialBoxService financialBoxService = new FinancialBoxService();
                FinancialBox        caixa = new FinancialBox();
                DateTime            data;

                var x = DateTime.TryParse(tbData.Text, out data);

                if (x == false)
                {
                    throw new Exception("Data invalida");
                }
                caixa.Date        = data;
                caixa.Description = tbDescricao.Text;
                caixa.Value       = Convert.ToDecimal(tbValor.Text);
                financialBoxService.Insert(caixa);
                MessageBox.Show("Valor adicionado ao caixa!");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        public void Insert(Purchase purchase)
        {
            FinancialBoxService purchaseService = new FinancialBoxService();
            ProductService      productService  = new ProductService();

            if (purchase == null)
            {
                throw new Exception("A compra não pode ser nulo");
            }

            if (purchase.Products == null)
            {
                throw new Exception("A compra precisa ter um produto");
            }

            if (purchase.Date == null || purchase.Date == DateTime.MinValue)
            {
                throw new Exception("Informe a data da compra");
            }


            //verifica se há dinheiro em caixa suficiente
            decimal totalCaixa = purchaseService.GetTotal();

            if (purchase.Total > totalCaixa)
            {
                throw new Exception("Não há valor em caixa para realizar a compra. Value disponível R$ " + totalCaixa);
            }

            purchaseRepository.Insert(purchase);

            FinancialBox caixa = new FinancialBox();

            //atualiza o caixa
            caixa.Date        = purchase.Date;
            caixa.Description = "Caixa atualizado atravez da compra " + purchase.Id;
            caixa.Value       = 0 - purchase.Total;

            purchaseService.Insert(caixa);

            //atualiza o estoque
            foreach (Product productPurchase in purchase.Products.ToList())
            {
                Product product = productService.GetById(productPurchase.Id);

                if (product != null)
                {
                    product.Quantity = productPurchase.Quantity + productPurchase.QuantBuy;
                    product.Note     = product.Note + Environment.NewLine + " Quantidade atualizada para "
                                       + product.Quantity + " atraves da compra " + purchase.Id;

                    productService.Update(product);
                }
            }
        }
예제 #4
0
        public void Insert(FinancialBox financialBox)
        {
            if (financialBox == null)
            {
                throw new Exception("O caixa não pode ser nulo");
            }

            if (string.IsNullOrEmpty(financialBox.Description))
            {
                throw new Exception("É necessário adicionar uma descrição para entrada de dinheiro no caixa");
            }

            financialBox.Total = financialBoxRepository.GetTotal() + financialBox.Value;

            financialBoxRepository.Insert(financialBox);
        }
 public void Insert(FinancialBox financialBox)
 {
     db.FinancialBox.Add(financialBox);
     Save();
 }