public async Task <IActionResult> Sell(int id, int sellAmount) { User user = HttpContext.Items["user"] as User; var q = from s in _context.Stock where s.id == id select s; Stock stock = q.Single(); if (stock.userId == user.id) { int newAmount = stock.count - sellAmount; await StockHelper.UpdateStock(id, newAmount, _context); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Update(int id, int statusID, int qty) { User user = HttpContext.Items["user"] as User; bool success = false; var q = from o in _context.Order where o.userId == user.id && o.id == id select o; Order order = await q.Include("stock").SingleAsync(); if (statusID != (int)order.status) { try { order.status = (Order.Status)statusID; if (statusID == 5) { int newStockAmount = order.stock.count + order.itemAmount; await StockHelper.UpdateStock(order.stockId, newStockAmount, _context); } await _context.SaveChangesAsync(); success = true; } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.id)) { return(NotFound()); } else { throw; } } } return(Json( new { success = success } )); }