Пример #1
0
        public async Task <IActionResult> EditDepositAdvanceInfo(DepositAdance depositAdance)
        {
            if (ModelState.IsValid)
            {
                var getDepositAdvanceDetails = _db.advance.SingleOrDefault(p => p.CustomerCID == depositAdance.CustomerCID);

                getDepositAdvanceDetails.CustomerCID = depositAdance.CustomerCID;

                if (depositAdance.Amount > getDepositAdvanceDetails.Amount)
                {
                    actualCreditedAmt = getDepositAdvanceDetails.Amount - depositAdance.Amount;
                    getDepositAdvanceDetails.Balance = getDepositAdvanceDetails.Balance + actualCreditedAmt;
                }
                if (depositAdance.Amount == getDepositAdvanceDetails.Amount)
                {
                    getDepositAdvanceDetails.Balance = getDepositAdvanceDetails.Balance;
                }
                if (depositAdance.Amount < getDepositAdvanceDetails.Amount)
                {
                    actualCreditedAmt = getDepositAdvanceDetails.Amount - depositAdance.Amount;
                    getDepositAdvanceDetails.Balance = getDepositAdvanceDetails.Balance + actualCreditedAmt;
                }
                getDepositAdvanceDetails.Amount = depositAdance.Amount;

                _db.Update(getDepositAdvanceDetails);
                await _db.SaveChangesAsync();

                return(RedirectToAction("DepositAdvance"));
            }
            return(View(depositAdance));
        }
Пример #2
0
        public async Task <IActionResult> EnterNewDepositAdvance(DepositAdance depositAdance)
        {
            if (ModelState.IsValid)
            {
                //get Customer Id form customer registration
                // Get the customers sites
                var customer = from c in _db.customer
                               where c.CID == depositAdance.CustomerCID
                               select c;
                if (customer.ToList().Count == 0)
                {
                    ViewBag.CustomerID = depositAdance.CustomerCID;
                    return(View("DoesNotExists_ID"));
                }

                var depositAdvanceInfo = _db.advance.SingleOrDefault(p => p.CustomerCID == depositAdance.CustomerCID);

                if (depositAdvanceInfo?.CustomerCID == depositAdance.CustomerCID)
                {
                    var getDepositAdvanceDetails = await _db.advance.FindAsync(depositAdance.CustomerCID);

                    getDepositAdvanceDetails.CustomerCID = depositAdance.CustomerCID;
                    getDepositAdvanceDetails.Amount      = depositAdance.Amount;
                    getDepositAdvanceDetails.Balance     = getDepositAdvanceDetails.Balance + depositAdance.Amount;
                    _db.Update(getDepositAdvanceDetails);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("DepositAdvance"));
                }
                else
                {
                    depositAdance.Balance = depositAdance.Amount;
                    _db.Add(depositAdance);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("DepositAdvance"));
                }
            }
            //enter history
            DepositAdvanceHistory depositAdvanceHistory = new DepositAdvanceHistory();

            depositAdvanceHistory.CustomerCID   = depositAdance.CustomerCID;
            depositAdvanceHistory.DepositAmount = depositAdance.Amount;
            depositAdvanceHistory.BalanceAmount = depositAdvanceHistory.BalanceAmount;
            depositAdvanceHistory.DepositTime   = new DateTime();
            _db.advancehistory.Add(depositAdvanceHistory);
            await _db.SaveChangesAsync();

            return(View(depositAdance));
        }