Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] FoodSupplier foodSupplier)
        {
            if (id != foodSupplier.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(foodSupplier);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FoodSupplierExists(foodSupplier.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(foodSupplier));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] FoodSupplier foodSupplier)
        {
            if (ModelState.IsValid)
            {
                _context.Add(foodSupplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(foodSupplier));
        }
        public static IParsingStrategy GetParser(FoodSupplier supplier)
        {
            switch (supplier)
            {
            case FoodSupplier.Cafe:
                return(new KafeParsingStrategy());

            case FoodSupplier.Glagol:
                return(new GlagolParsingStrategy());

            default:
                throw new ArgumentException();
            }
        }
Exemple #4
0
        public static void Memento()
        {
            //Here's a new supplier for our restaurant
            FoodSupplier s = new FoodSupplier();

            s.Name  = "Harold Karstark";
            s.Phone = "(482) 555-1172";

            // Let's store that entry in our database.
            SupplierMemory m = new SupplierMemory();

            m.Memento = s.SaveMemento();

            // Continue changing originator
            s.Address = "548 S Main St. Nowhere, KS";

            // Crap, gotta undo that entry, I entered the wrong address
            s.RestoreMemento(m.Memento);
        }
 public FoodSupplierMemento(FoodSupplier supplier)
 {
     Name    = supplier.Name;
     Phone   = supplier.Phone;
     Address = supplier.Address;
 }