public async Task <ActionResult <ProductBand> > PostProductBand(ProductBand productBand)
        {
            _context.ProductBands.Add(productBand);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductBand", new { id = productBand.Id }, productBand));
        }
        public async Task <IActionResult> PutProductBand(int id, ProductBand productBand)
        {
            if (id != productBand.Id)
            {
                return(BadRequest());
            }

            _context.Entry(productBand).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductBandExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public static void DisplayCount(ProductBand productBand)
 {
     if (productBand.Count() == 1)
     {
         Console.WriteLine("Band contains 1 product.");
     }
     else
     {
         Console.WriteLine("Band contains {0} products.", productBand.Count());
     }
 }
Example #4
0
        public void InitializeConstructors()
        {
            twixBand        = new ProductBand();
            paymentTerminal = new PaymentTerminal();
            dispenser       = new Dispenser();

            twixItem = ProductFactory.CreateTwixProduct();
            twixBand.Add(twixItem);
            ProductBand.Instance().Add(twixItem);

            paymentTerminal.Attach(dispenser);
        }
        static void Main()
        {
            var paymentTerminal = new PaymentTerminal();

            try
            {
                // Vending Machine Out Of Service
                var pringlesItem = ProductFactory.CreatePringlesProduct();
                ProductBand.Instance().Add(pringlesItem);
                var dispenser = new Dispenser();
                paymentTerminal.Attach(dispenser);
            }
            catch (Exception exception)
            {
                if (exception is BandIsFullException)
                {
                    Console.WriteLine("Band is full! It can't store any items.");
                }
            }

            try
            {
                // New Customer Requests for a Pringles
                var visaCard = new CreditCard("4012888888881881");
                paymentTerminal.Pay(visaCard, 1, "Pringles");
            }
            catch (Exception exception)
            {
                if (exception is FormatException)
                {
                    Console.WriteLine("You entered a wrong value! Press any key and try again!");
                }
                if (exception is CardNotValidException)
                {
                    Console.WriteLine("This credit card is not valid! Try another payment method.");
                }
                if (exception is CardNotFoundException)
                {
                    Console.WriteLine("Card was not found! Payment canceled!");
                }
                if (exception is BandIsEmptyException)
                {
                    Console.WriteLine("Band is empty! You can't {0} any item!", exception.Message);
                }
            }

            Console.ReadKey();
        }
Example #6
0
 public void InitializeConstructors()
 {
     oreoItem = ProductFactory.CreateOreoItem();
     oreoBand = new ProductBand();
 }
Example #7
0
 public void InitializeConstructors()
 {
     skittlesItem = ProductFactory.CreateSkittlesProduct();
     skittlesBand = new ProductBand();
     dispenser    = new Dispenser();
 }