public IActionResult Create(ThirdPartyChequeViewModel model)
        {
            ThirdPartyCheque          thirdPartyCheque = _mapper.Map <ThirdPartyCheque>(model);
            ThirdPartyChequeActionLog actionLog        = model.ActionLog;

            actionLog.ThirdPartyCheque = thirdPartyCheque;
            _context.ThirdPartyChequeActionLogs.Add(actionLog);
            var flag = _context.SaveChanges();

            if (thirdPartyCheque.Status == 1)   // if cheque is in hand
            {
                var single = _context.BalanceSheets.Single(x => x.BalanceSheetId == 1);
                single.InHandCheque += thirdPartyCheque.Amount;
                flag = _context.SaveChanges();
            }

            if (thirdPartyCheque.Status == 5)   // if cheque is banked
            {
                var single = _context.BalanceSheets.Single(x => x.BalanceSheetId == 1);
                single.InHold += thirdPartyCheque.Amount;
                flag           = _context.SaveChanges();
            }

            return(Ok(flag > 0));
        }
        public IActionResult ThirdPartyChequeDetailView(string breadCumValue, long thirdPartyChequeId)
        {
            if (HttpContext.Session.GetString("loggedIn") == null || HttpContext.Session.GetString("loggedIn") == "false")
            {
                return(RedirectToAction("Index", "Login"));
            }
            ViewBag.breadCumValue = breadCumValue;
            ViewBag.IsUpdate      = thirdPartyChequeId > 0 ? "true" : "false";

            ThirdPartyChequeViewModel thirdPartyChequeViewModel = new ThirdPartyChequeViewModel();

            if (thirdPartyChequeId > 0)
            {
                thirdPartyChequeViewModel = _mapper
                                            .Map <ThirdPartyChequeViewModel>(_context.ThirdPartyCheques.SingleOrDefault(x => x.ThirdPartyChequeId == thirdPartyChequeId));
            }


            thirdPartyChequeViewModel.ChequeStatusesVm = _mapper.Map <List <ChequeStatusViewModel> >(_context.ChequeStatuses.Where(x => x.StatusType.Contains("CH")).ToList());
            thirdPartyChequeViewModel.BankList         = _context.ThirdPartyCheques.Select(x => x.Bank).Distinct().ToList();
            thirdPartyChequeViewModel.BranchList       = _context.ThirdPartyCheques.Select(x => x.Branch).Distinct().ToList();

            thirdPartyChequeViewModel.CustomerList = _context.Customers.Where(s => s.CurrentStatus == 1).Select(x => new Customer()
            {
                CustomerId = x.CustomerId, CustomerName = x.CustomerName
            }).ToList();
            thirdPartyChequeViewModel.SupplierList = _context.Suppliers.Where(s => s.CurrentStatus == 1).Select(x => new Supplier()
            {
                SupplierId = x.SupplierId, SupplierName = x.SupplierName
            }).ToList();

            return(View(thirdPartyChequeViewModel));
        }
        public IActionResult Update(ThirdPartyChequeViewModel model)
        {
            ThirdPartyCheque thirdPartyCheque = _mapper.Map <ThirdPartyCheque>(model);

            _context.ThirdPartyCheques.Update(thirdPartyCheque);
            //            _context.SaveChanges();

            ThirdPartyChequeActionLog actionLog = model.ActionLog;

            actionLog.ThirdPartyChequeId = model.ThirdPartyChequeId;
            _context.ThirdPartyChequeActionLogs.Add(actionLog);
            var flag = _context.SaveChanges();

            if (thirdPartyCheque.Status == 5)   // if cheque is banked
            {
                var single = _context.BalanceSheets.Single(x => x.BalanceSheetId == 1);
                single.InHold += thirdPartyCheque.Amount;
                flag           = _context.SaveChanges();
            }

            if (thirdPartyCheque.Status == 6)   // if cheque is passed
            {
                var single = _context.BalanceSheets.Single(x => x.BalanceSheetId == 1);
                single.InHold      -= thirdPartyCheque.Amount;
                single.BankBalance += thirdPartyCheque.Amount;
                flag = _context.SaveChanges();
            }

            if (thirdPartyCheque.Status == 2)   // if cheque is returned
            {
                var single = _context.BalanceSheets.Single(x => x.BalanceSheetId == 1);
                single.InHold -= thirdPartyCheque.Amount;
                flag           = _context.SaveChanges();
            }

            return(Ok(flag > 0));
        }