public IActionResult ChangeAmountAssetOwned([FromBody] QChangeStockVM asset) { //can just use the same one as stock as the data that we need is the same if (!ModelState.IsValid) { return(Json(new JSONResponseVM { success = false, message = "No id" })); } Asset ass = context.Assets.Where(a => a.assetId == asset.id).FirstOrDefault(); if (ass != null) { ass.quanityOwned = ass.quanityOwned + asset.quantity < 0 ? 0 : ass.quanityOwned + asset.quantity; context.SaveChanges(); return(Json(new JSONResponseVM { success = true, message = "Asset changed" })); } return(Json(new JSONResponseVM { success = false, message = "Something went wrong..." })); }
public IActionResult ChangeStockQuantityOwned([FromBody] QChangeStockVM stockChange) { if (!ModelState.IsValid) { return(Json(new JSONResponseVM { success = false, message = "Model state is not valid" })); } Stock stock = context.Stocks.Where(s => s.stockId == stockChange.id).FirstOrDefault(); if (stock != null) { stock.quantityOwned = stock.quantityOwned + stockChange.quantity < 0 ? 0 : stock.quantityOwned + stockChange.quantity; context.SaveChanges(); return(Json(new JSONResponseVM { success = true, message = "Quantity Changed" })); } return(Json(new JSONResponseVM { success = false, message = "Could not find this stock" })); }