Exemplo n.º 1
0
        public static string UpdatePrice(FastFoodDbContext context, string itemName, decimal newPrice)
        {
            var item = context.Items.FirstOrDefault(i => i.Name == itemName);

            if (item == null)
            {
                return($"Item {itemName} not found!");
            }

            var oldPrice = item.Price;

            context.Attach(item);
            item.Price = newPrice;
            context.SaveChanges();

            return($"{item.Name} Price updated from ${oldPrice:F2} to ${newPrice:F2}");
        }