public bool UpdateStatus(string order_id, Status status, string LoginUserId) { string decryptedId = protector.Unprotect(order_id); int decryptedIntId = Convert.ToInt32(decryptedId); var order = context.Order .FirstOrDefault(x => x.order_id == decryptedIntId); if (order != null) { if (order.status == status) { return(true); } if (status == Status.Pending || status == Status.Processing && order.status == Status.Completed) { return(false); } else if (status == Status.Completed) { var ProductsList = order.Products.Select(x => new Products() { id = x.id, price = x.price, Quantity = x.Quantity, modelId = x.modelId, order_id = x.order_id }).Where(x => x.order_id == order.order_id).ToList(); List <Tuple <int, bool> > quantityCheck = util.checkingquantity(ProductsList, order.store_id); if (quantityCheck.Any(x => x.Item2 == false)) { return(false); } bool res = util.updatequan(ProductsList, order.store_id, "Subtract"); if (res == false) { return(false); } } order.status = status; order.TakenBy = LoginUserId; context.Order.Update(order); context.SaveChanges(); return(true); } return(false); }