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); }
// GET: Sites public async Task <IActionResult> Index(int?id, int?status, string customerID) { var userID = _userManager.GetUserId(User); var customerCID = string.IsNullOrEmpty(customerID) ? userID : customerID; Deposit deposit = null; if (id != null && id > 0) { deposit = await _depositRepository.FindByID(customerCID); deposit.DepositID = 1; } if (status != null && status > 0) { ViewBag.Status = true; ViewBag.Message = status == 1 ? "Desposited" : "Updated"; } Deposit depositDetails = await _depositRepository.FindByID(customerCID); ViewData["DepositList"] = User.IsInRole("Admin") ? await _depositRepository.FindAll() : await _depositRepository.FindAll(customerCID); ViewBag.CustomerID = customerCID; ViewBag.LastAmount = depositDetails == null ? 0 : depositDetails.Balance; return(View(deposit)); }