public async Task <ActionResult> DeleteOrder(int ID) { using (Comessa5Context repository = factory.GetContext()) { var toRemove = repository.corder.Where(order => order.id == ID).SingleOrDefault(); if (toRemove == null) { return(Json(false)); } repository.corder.Remove(toRemove); await repository.SaveChangesAsync(); } // Delete the item in the database return(Json(true)); // or if there is an error, return Json(null); to indicate failure }
public async Task <ActionResult> SaveOrder(int itemID, int userID, decimal quantity, string comments) { //ToDo: check if it's possible to do that using 1 operation instead of 2 using EF //...or parse the whole citem as argument here using (Comessa5Context repository = factory.GetContext()) { citem item = repository.citem.Where(citem => citem.id == itemID).FirstOrDefault(); cuser server = repository.cuser.Where(cuser => cuser.isServer && !cuser.isMasterServer).FirstOrDefault(); repository.corder.Add(new corder { itemId = itemID, quantity = quantity, comment = comments, userId = userID, itemName = item.name, price = item.price, date = DateTime.Now, status = (int)OrderStatus.Ordered, sellerId = server == null ? -1 : server.id }); await repository.SaveChangesAsync(); } return(Json(true)); }