public async Task <CustomResponse> AddAsync(Order order)
        {
            var deposit = await _depositRepository.FindByID(order.CustomerCID);

            var product  = _productRepository.FindByID(order.ProductID).Result;
            var site     = _siteRepository.FindByID(order.SiteID).Result;
            var response = CalculateData(order.CustomerCID, product, site, deposit, order.Quantity);

            if (response.Status != 1)
            {
                return(response);
            }

            var orderDetails = (Order)response.ResponseData;

            _context.Orders.Add(orderDetails);
            await _context.SaveChangesAsync();

            // To update the deposit balance of given customer.
            deposit.DepositID  = 1;
            deposit.Balance    = deposit.Balance - orderDetails.OrderedAmount;
            deposit.LastAmount = -orderDetails.OrderedAmount;
            await _depositRepository.Update(deposit);

            return(response);
        }
示例#2
0
        public async Task <IActionResult> Index([Bind("CustomerID,LastAmount,Balance,DepositID")] Deposit deposit)
        {
            var userID = _userManager.GetUserId(User);

            if (ModelState.IsValid)
            {
                var status = 1;
                deposit.CustomerID = userID;
                if (await _depositRepository.IsIDExists(userID))
                {
                    status = 2;
                    await _depositRepository.Update(deposit);
                }
                else
                {
                    await _depositRepository.Add(deposit);
                }
                return(RedirectToAction(nameof(Index), new { id = 0, status, customerID = "" }));
            }
            ViewData["DepositList"] = await _depositRepository.FindAll(userID);

            return(View(deposit));
        }