コード例 #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("CreditCardCutId,ProductId,PayDayCut,PayDayLimit,AmountCut,AmountPayment,AmountPending,CreatedDate")] CreditCardCut creditCardCut)
        {
            if (id != creditCardCut.CreditCardCutId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(creditCardCut);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CreditCardCutExists(creditCardCut.CreditCardCutId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CreateInitial(creditCardCut.ProductId);
            return(View(creditCardCut));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,Number,Alias,BankId,CurrencyId,TotalAmount,Balance,OpeningDate,CutDay,DaysToPayCut,StatusProduct,CreatedDate")] Product product)
        {
            if (id != product.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user = await _userManager.GetUserAsync(User);

                    product.UserId      = user.Id;
                    product.UpdatedDate = DateTime.Now;
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BankId"]     = new SelectList(_context.Banks, "BankId", "Description", product.BankId);
            ViewData["CurrencyId"] = new SelectList(_context.Currency, "CurrencyId", "Description", product.CurrencyId);
            return(View(product));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("BankId,Description,Country,StatusBank")] Bank bank)
        {
            if (id != bank.BankId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bank);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BankExists(bank.BankId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bank));
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("CurrencyConvertId,Multiple,CurrencyFromCurrencyId,CurrencyToCurrencyId,DateValidFrom,DateValidTo,StatusCurrency")] CurrencyConvert currencyConvert)
        {
            if (id != currencyConvert.CurrencyConvertId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(currencyConvert);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CurrencyConvertExists(currencyConvert.CurrencyConvertId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CurrencyFromCurrencyId"] = new SelectList(_context.Currency, "CurrencyId", "Description", currencyConvert.CurrencyFromCurrencyId);
            ViewData["CurrencyToCurrencyId"]   = new SelectList(_context.Currency, "CurrencyId", "Description", currencyConvert.CurrencyToCurrencyId);
            return(View(currencyConvert));
        }
コード例 #7
0
        public async Task <IActionResult> Edit(int id, [Bind("CurrencyId,Description,StatusCurrency")] Currency currency)
        {
            if (id != currency.CurrencyId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(currency);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CurrencyExists(currency.CurrencyId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(currency));
        }
コード例 #8
0
        public async Task <IActionResult> Edit(int id, [Bind("PaymentReminderId,ReminderTypeId,ProductId,ExpenseId,StartDate,StartTime,EndDate,EndTime,CreatedDate,StatusPaymentReminder")] PaymentReminder paymentReminder)
        {
            if (id != paymentReminder.PaymentReminderId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(paymentReminder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentReminderExists(paymentReminder.PaymentReminderId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExpenseId"]      = new SelectList(_context.Expense, "ExpenseId", "Description", paymentReminder.ExpenseId);
            ViewData["ProductId"]      = new SelectList(_context.Product, "ProductId", "Alias", paymentReminder.ProductId);
            ViewData["ReminderTypeId"] = new SelectList(_context.ReminderType, "ReminderTypeId", "Description", paymentReminder.ReminderTypeId);
            return(View(paymentReminder));
        }
コード例 #9
0
        public async Task <IActionResult> Edit(int id, [Bind("ExpenseId,ExpenseTypeId,Description,CurrencyId,Amount,CutDay,PayDayLimit,StatusExpense,CreatedDate,UserId")] Expense expense)
        {
            if (id != expense.ExpenseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(expense);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExpenseExists(expense.ExpenseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CurrencyId"] = new SelectList(_context.Currency, "CurrencyId", "Description", expense.CurrencyId);
            return(View(expense));
        }
コード例 #10
0
        public async Task <IActionResult> Edit(int id, [Bind("ReminderTypeId,Description,RecurrenceHour,RecurrenceDay,RecurrenceMonth,RecurrenceYear")] ReminderType reminderType)
        {
            if (id != reminderType.ReminderTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(reminderType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReminderTypeExists(reminderType.ReminderTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(reminderType));
        }
コード例 #11
0
        public async Task <IActionResult> Edit(int id, [Bind("CashOutcomeId,ProductId,Description,Amount,OutcomeDate,CreatedDate,StatusOutcome")] CashOutcome cashOutcome)
        {
            if (id != cashOutcome.CashOutcomeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    CashOutcome cashOutcomeOld = await _context.CashOutcome.SingleOrDefaultAsync(c => c.CashOutcomeId == cashOutcome.CashOutcomeId);

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

                    if (cashOutcome.Amount != cashOutcomeOld.Amount)
                    {
                        var _amount = cashOutcome.Amount - cashOutcomeOld.Amount;
                        product.Balance = product.Balance - _amount;
                        _context.Update(product);
                    }

                    _context.Update(cashOutcome);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CashOutcomeExists(cashOutcome.CashOutcomeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CreateInitial(cashOutcome.ProductId);
            return(View(cashOutcome));
        }