Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("PayProductId,ProductIdFrom,ProductIdTo,Description,Amount,Tax,PayProductDate,CreatedDate,StatusPayProduct")] PayProduct payProduct)
        {
            if (id != payProduct.PayProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    PayProduct payProductOld = await _context.PayProduct.SingleOrDefaultAsync(p => p.PayProductId == payProduct.PayProductId);

                    if (payProduct.Amount != payProductOld.Amount)
                    {
                        FunctionsConvert functionsConvert = new FunctionsConvert(_context);

                        var _amount = payProduct.Amount - payProductOld.Amount;
                        var _tax    = payProduct.Tax - payProductOld.Tax;

                        payProduct.ProductFrom = await _context.Product.SingleOrDefaultAsync(p => p.ProductId == payProduct.ProductIdFrom);

                        payProduct.ProductTo = await _context.Product.SingleOrDefaultAsync(p => p.ProductId == payProduct.ProductIdTo);

                        var _payProduct = functionsConvert.ConvertCurrency(payProduct, _amount, _tax);

                        if (payProduct.ProductFrom.Balance < (_payProduct.Amount + _payProduct.Tax))
                        {
                            CreateInitial(payProduct.ProductIdFrom, payProduct.ProductIdTo);
                            ModelState.AddModelError("", "Balance de Producto origen insuficiente.");
                            return(View(payProduct));
                        }

                        //restar el balance del producto origen
                        payProduct.ProductFrom.Balance = payProduct.ProductFrom.Balance - _payProduct.Amount - _payProduct.Tax;

                        //sumar al balance del prestamo destino
                        payProduct.ProductTo.Balance = payProduct.ProductTo.Balance - _amount;
                    }
                    _context.Entry(payProductOld).State = EntityState.Detached; //detach old to update the new
                    _context.Update(payProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PayProductExists(payProduct.PayProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CreateInitial(payProduct.ProductIdFrom, payProduct.ProductIdTo);
            return(View(payProduct));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("PayExpenseId,ProductId,ExpenseId,Description,Amount,Tax,PayExpenseDate,CreatedDate,StatusPayExpense")] PayExpense payExpense)
        {
            if (id != payExpense.PayExpenseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    PayExpense payExpenseOld = await _context.PayExpense.SingleOrDefaultAsync(c => c.PayExpenseId == payExpense.PayExpenseId);

                    if (payExpense.Amount != payExpenseOld.Amount)
                    {
                        FunctionsConvert functionsConvert = new FunctionsConvert(_context);

                        var _amount = payExpense.Amount - payExpenseOld.Amount;
                        var _tax    = payExpense.Tax - payExpenseOld.Tax;

                        payExpense.Product = await _context.Product.SingleOrDefaultAsync(p => p.ProductId == payExpense.ProductId);

                        payExpense.Expense = await _context.Expense.SingleOrDefaultAsync(e => e.ExpenseId == payExpense.ExpenseId);

                        var _payExpense = functionsConvert.ConvertCurrency(payExpense, _amount, _tax);

                        if (payExpense.Product.Balance < (_payExpense.Amount + _payExpense.Tax))
                        {
                            CreateInitial(payExpense.ProductId, payExpense.ExpenseId);
                            ModelState.AddModelError("", "Balance de Producto origen insuficiente.");
                            return(View(payExpense));
                        }

                        payExpense.Product.Balance = payExpense.Product.Balance - _payExpense.Amount - _payExpense.Tax;
                        //_context.Update(product);
                    }

                    _context.Entry(payExpenseOld).State = EntityState.Detached; //detach old to update the new
                    _context.Update(payExpense);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PayExpenseExists(payExpense.PayExpenseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CreateInitial(payExpense.ProductId, payExpense.ExpenseId);
            return(View(payExpense));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("CashIncomeId,ProductId,Description,Amount,IncomeDate,CreatedDate,StatusIncome")] CashIncome cashIncome)
        {
            if (id != cashIncome.CashIncomeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var cashIncomeOld = await _context.CashIncome.SingleOrDefaultAsync(c => c.CashIncomeId == cashIncome.CashIncomeId);

                    cashIncome.Product = await _context.Product.SingleOrDefaultAsync(p => p.ProductId == cashIncome.ProductId);

                    if (cashIncome.Amount != cashIncomeOld.Amount)
                    {
                        var _amount = cashIncome.Amount - cashIncomeOld.Amount;
                        cashIncome.Product.Balance = cashIncome.Product.Balance + _amount;
                        //_context.Update(product);
                    }
                    _context.Entry(cashIncomeOld).State = EntityState.Detached; //detach old to update the new
                    _context.Update(cashIncome);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CashIncomeExists(cashIncome.CashIncomeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CreateInitial(cashIncome.ProductId);
            return(View(cashIncome));
        }