public async Task <IActionResult> Edit(int id, [Bind("ID,Children,Adults,Date")] Breakfast breakfast)
        {
            if (id != breakfast.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(breakfast);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BreakfastExists(breakfast.Date))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(breakfast));
        }
Пример #2
0
    public IActionResult Update([FromBody] Breakfast item)
    {
        var session       = HttpContext.Get <LoggableEntities>(_context);
        var current_User  = session == null ? null : session.User;
        var current_Admin = session == null ? null : session.Admin;
        var allowed_items = ApiTokenValid ? _context.Breakfast : _context.Breakfast;

        if (!allowed_items.Any(i => i.Id == item.Id))
        {
            return(Unauthorized());
        }
        var new_item = item;

        var can_edit_by_token = ApiTokenValid || true;

        if (item == null || !can_edit_by_token)
        {
            return(Unauthorized());
        }
        // throw new Exception("Unauthorized edit attempt");
        _context.Update(new_item);
        _context.Entry(new_item).Property(x => x.CreatedDate).IsModified = false;
        _context.SaveChanges();
        return(Ok());
    }
Пример #3
0
        public void GetCost_Method_Calculates_Cost_Of_Bookings_Correctly()
        {
            Booking aBooking = new Booking();

            // Booking for 2 nights
            aBooking.ArrivalDate   = DateTime.Parse("2000-01-01");
            aBooking.DepartureDate = DateTime.Parse("2000-01-03");

            //Create 2 guests
            Guest guest1 = new Guest();

            guest1.Age = 12; //Create a guest (child charged at £30.00/night)
            aBooking.AddGuest(guest1);
            Guest guest2 = new Guest();

            guest2.Age = 32; //Create a guest (adult charged at £50.00/night)
            aBooking.AddGuest(guest2);

            //Create Extras
            Breakfast breakfast1 = new Breakfast(); //Breakfast charged at £5.00 per guest per night
            CarHire   carhire1   = new CarHire();   //CarHire charged at £50.00/day

            //Car hire booked for 1 day
            carhire1.StartDate  = DateTime.Parse("2000-01-01");
            carhire1.ReturnDate = DateTime.Parse("2000-01-02");
            aBooking.AddExtra(breakfast1);
            aBooking.AddExtra(carhire1);


            double expected   = 230.00;             //expected cost for booking
            double calculated = aBooking.GetCost(); //Cost returned from the GetCost method

            Assert.AreEqual(expected, calculated, "GetCost method calculated booking costs correctly!");
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,Date,Children,Adults")] Breakfast breakfast)
        {
            _context.Add(breakfast);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Expected)));
        }
        public void TestFryingEggsLength()
        {
            var eggs = Breakfast.FryEggs(2);

            Assert.Equal(2, eggs.Count);
            Assert.Equal("2 eggs", eggs.Print());
        }
Пример #6
0
        static void Main(string[] args)
        {
            var coffee = Breakfast.PourCoffee();

            while (!coffee.Temperature.Equals("Cold"))
            {
                Console.WriteLine("Coffee temperature: " + coffee.Temperature);
            }
            Console.WriteLine("Coffee temperature: " + coffee.Temperature);

            var bacon = Breakfast.FryBacon(5);

            Breakfast.EatBacon(ref bacon, 2);

            var eggs = Breakfast.FryEggs(4);

            eggs.Print();

            var toasts = Breakfast.ToastBread(6);

            Breakfast.ApplyButter(toasts[1]);
            Breakfast.ApplyButter(toasts[4]);

            for (int i = 0; i < toasts.Length; i++)
            {
                var buttered = toasts[i].ButterApplied;
                var jamed    = toasts[i].JamApplied;

                Console.WriteLine("Butter on Toast #" + i + ": " + buttered);
                Console.WriteLine("Jam on Toast #" + i + ": " + jamed);
            }
        }
Пример #7
0
 public void TestFryingBaconLength()
 {
     var bacon = Breakfast.FryBacon(3);
     Assert.AreEqual(3, bacon.Length);
     Breakfast.EatBacon(ref bacon, 2);
     Assert.AreEqual(1, bacon.Length);
 }
        public async Task <IActionResult> Edit(int id, [Bind("Id,BreakfastName,BreakfastDescription,BreakfastStreet,BreakfastCity,BreakfastZIP,BreakfastLink")] Breakfast breakfast)
        {
            if (id != breakfast.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(breakfast);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BreakfastExists(breakfast.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(breakfast));
        }
        public ActionResult Index(int id)
        {
            Login            login         = Login.Find(id);
            List <Breakfast> allBreakfasts = Breakfast.GetAllBreakfast();

            ViewBag.Breakfast = allBreakfasts;
            return(View("Index", login));
        }
        public void TestFryingBaconLength()
        {
            var bacon = Breakfast.FryBacon(3);

            Assert.Equal(3, bacon.Count);
            Breakfast.EatBacon(bacon, 2);
            Assert.Equal(1, bacon.Count);
        }
Пример #11
0
        // Should add an extra successfuly given an extra object
        public void AddExtra_Method_Works_Correctly()
        {
            Booking aBooking = new Booking();
            //Create Guest
            Extra Extra1 = new Breakfast();

            aBooking.AddExtra(Extra1); //Should add the extra to the list of extras correctly
            Assert.AreEqual(aBooking.Extras.Count, 1, "Guest was removed successfuly");
        }
        // Button clicks navigate to new page
        private void Button_Clicked(object sender, EventArgs e)
        {
            var page = new Breakfast();

            //NavigationPage.SetHasNavigationBar(page, true);
            //NavigationPage.SetBackButtonTitle(page, "Back");
            Navigation.PushAsync(page);
            //NavigationPage.SetHasBackButton(page, true);
        }
Пример #13
0
 public void prepareBreakfast()
 {
     Console.WriteLine("\n Breakfast is going to be prepared synchronously ....");
     Breakfast breakfast = new Breakfast();
     Coffee    c         = breakfast.prepareCoffee();
     Bacon     b         = breakfast.prepareBacon();
     Juice     j         = breakfast.prepareJuice();
     Toast     t         = breakfast.prepareToast();
 }
Пример #14
0
    public void DebugNineTwo()
    {
        Breakfast special = new Breakfast("French toast", 4.99);

        //Display the info about breakfast
        WriteLine(special.INFO);
        // then display today's special
        WriteLine("Today we are having {0} for {1}",
                  special.Name, special.Price.ToString("C2"));
    }
Пример #15
0
    static void Main()
    {
        //Display the info about breakfast
        Breakfast special = new Breakfast("French toast", 4.99);

        WriteLine(special.INFO);
        // then display today's special
        WriteLine("Today we are having {0} for {1}",
                  special.Name, special.Price.ToString("C2", CultureInfo.GetCultureInfo("en-US")));
    }
Пример #16
0
    public static void FixedDebugNine()
    {
        Breakfast special = new Breakfast("French Toast", 4.99);

        //Display the info about breakfast
        WriteLine(special.INFO);
        // then display today's special
        WriteLine("Today we are having {0} for {1}",
                  special.INFO, special.price.ToString());
    }
Пример #17
0
 public void TestCoffeeTemperature()
 {
     var coffee = Breakfast.PourCoffee();
     Assert.AreEqual("Hot", coffee.Temperature);
     Thread.Sleep(500);
     Assert.AreEqual("Quite hot", coffee.Temperature);
     Thread.Sleep(500);
     Assert.AreEqual("Not so hot", coffee.Temperature);
     Thread.Sleep(500);
     Assert.AreEqual("Cold", coffee.Temperature);
 }
        public async Task <IActionResult> Create([Bind("Id,BreakfastName,BreakfastDescription,BreakfastStreet,BreakfastCity,BreakfastZIP,BreakfastLink")] Breakfast breakfast)
        {
            if (ModelState.IsValid)
            {
                _context.Add(breakfast);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(breakfast));
        }
Пример #19
0
        static void ExampleBreakfast()
        {
            Breakfast bf = new Breakfast();

            bf.Prepare();

            Task tbf = bf.PrepareAsync();
            // todo: what should be here?
            // do something esle
            // todo: Is this a correct invocation? What is the problem? Fix it.
        }
        public async Task <IActionResult> Create([Bind("ID,Children,Adults,Date")] Breakfast breakfast)
        {
            if (ModelState.IsValid)
            {
                _context.Add(breakfast);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(breakfast));
        }
        public ActionResult Create(string food, string sugarLevel, DateTime stampTime, string carb, int loginId)
        {
            Login     foundLogin   = Login.Find(loginId);
            Breakfast newBreakfast = new Breakfast(food, stampTime, float.Parse(sugarLevel), float.Parse(carb), loginId);

            newBreakfast.Save();
            List <Breakfast> newList = Breakfast.GetAllBreakfast();

            ViewBag.Breakfast = newList;
            return(View("Index", foundLogin));
        }
        public ActionResult DeleteBreakfast(int id, int breakfastId)
        {
            Breakfast breakfast = Breakfast.Find(breakfastId);

            breakfast.Delete();
            Login            login         = Login.Find(id);
            List <Breakfast> allBreakfasts = Breakfast.GetAllBreakfast();

            ViewBag.Breakfast = allBreakfasts;
            return(View("Index", login));
        }
Пример #23
0
        public void CanMakeBreakfast()
        {
            var eggs       = Enumerable.Range(0, 6).Select(n => new Egg()).ToList();
            var spam       = Enumerable.Range(0, 12).Select(n => new Spam()).ToList();
            var totalItems = eggs.Count + spam.Count;
            var breakfast  = new Breakfast();

            breakfast.Make(spam, eggs);

            Assert.IsNotNull(breakfast);
            Assert.AreEqual(totalItems, breakfast.Items.Count);
        }
        public void TestApplyingToToast()
        {
            var toasts = Breakfast.ToastBread(2);

            Breakfast.ApplyButter(toasts[0]);
            Breakfast.ApplyJam(toasts[1]);

            Assert.False(toasts[0].JamApplied);
            Assert.False(toasts[1].ButterApplied);
            Assert.True(toasts[1].JamApplied);
            Assert.True(toasts[0].ButterApplied);
        }
Пример #25
0
        // Throws exception if extra with the provided index does not exist
        public void RemoveExtra_Method_Throws_Exception_If_Extra_Does_Not_Exist()
        {
            Booking aBooking = new Booking();
            //Create extra
            Extra extra1 = new Breakfast();

            //Add extra to booking list
            aBooking.AddExtra(extra1);

            int index = 2;

            aBooking.RemoveExtra(index); // Should throw exception since extra at index 2 does not exist
        }
        static async Task <Toast[]> MakeToastWithButterAndJamAsync(int number)
        {
            var toasts = await Breakfast.ToastBreadAsync(number);

            foreach (var toast in toasts)
            {
                Breakfast.ApplyButter(toast);
            }

            foreach (var toast in toasts)
            {
                Breakfast.ApplyJam(toast);
            }

            return(toasts);
        }
Пример #27
0
        public void RemoveExtra_Method_Removes_Guest_If_Guest_Does_Exist()
        {
            Booking aBooking = new Booking();
            //Create Extras
            Extra Extra1 = new Breakfast();
            Extra Extra2 = new CarHire();

            //Add Extras to booking list
            aBooking.AddExtra(Extra1);
            aBooking.AddExtra(Extra2);

            int index = 1;

            aBooking.RemoveExtra(index); // Should remove the Extra at index 1
            Assert.AreEqual(aBooking.Extras.Count, 1, "Extra was removed successfuly");
        }
Пример #28
0
        // Returns a null extra if extra cannot be found in the list
        public void GetExtra_Method_Returns_Null_If_Extra_Does_Not_Exist()
        {
            Booking aBooking = new Booking();
            //Create Extras
            Extra Extra1 = new Breakfast();
            Extra Extra2 = new CarHire();

            //Add Extras to booking list
            aBooking.AddExtra(Extra1);
            aBooking.AddExtra(Extra2);

            int   index  = 2;
            Extra extra3 = aBooking.GetExtra(index); //Should return a null Extra

            Assert.AreEqual(extra3, null, "Guest can not be found! (null)");
        }
Пример #29
0
        public void CanSerializeInterfacePropertyWithoutSpecifyingMapping()
        {
            var serializer = new JsonSerializer <Breakfast>();

            var food = new Breakfast
            {
                Menu = new Spam
                {
                    Eggs = 123
                }
            };

            var json = serializer.Serialize(food);

            Assert.That(json, Is.EqualTo(@"{""Menu"":{""Eggs"":123}}"));
        }
Пример #30
0
    public static void NineTwo()
    {
        Breakfast special = new Breakfast("French toast", 4.99);
        Breakfast words   = new Breakfast("Breakfast is the most important meal of the day.");

        System.Console.WriteLine(special.INFO);
        //Display the info about breakfast
        WriteLine(words.Info);//ch to special
        // then display today's special
        //WriteLine("Today we are having {0} for {1}",
        //   special.Name, special.Price.ToString("C2"));//ch lower n to upper

        WriteLine($"Today we are having {special.Name} for {special.Price.ToString("C2")}");


        ReadLine();
    }
        public void CanSerializeInterfacePropertyWithoutSpecifyingMapping()
        {
            var serializer = new JsonSerializer<Breakfast>();

            var food = new Breakfast
            {
                Menu = new Spam
                {
                    Eggs = 123
                }
            };

            var json = serializer.Serialize(food);

            Assert.That(json, Is.EqualTo(@"{""Menu"":{""Eggs"":123}}"));
        }