Ejemplo n.º 1
0
        public async Task <IActionResult> EditAppetizer([FromBody] AppetizerInfo appetizerInfo)
        {
            string emailAddress = HttpContext.User.Identity.Name;

            var restaurant = await _context.Restaurant
                             .Where(rest => rest.EmailAddress.Equals(emailAddress))
                             .FirstOrDefaultAsync();

            string appetizerName = Request.Headers["appetizerName"];

            Appetizer appetizerToUpdate = await _context.Appetizer
                                          .Where(d => d.Name.Equals(appetizerName))
                                          .FirstOrDefaultAsync();

            appetizerToUpdate.Name         = appetizerInfo.Name;
            appetizerToUpdate.Price        = appetizerInfo.Price;
            appetizerToUpdate.Description  = appetizerInfo.Description;
            appetizerToUpdate.HouseSpecial = appetizerInfo.HouseSpecial;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(appetizerToUpdate);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
            }

            HttpContext.Response.StatusCode = 200;
            return(new JsonResult("Appetizer successfully updated"));
        }
Ejemplo n.º 2
0
        public async Task CreateNewAppetizerUnauthorized()
        {
            // Arrange
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5002/Appetizer/Restaurant/create");
 
            Appetizer appetizer = new Appetizer
            {
                RestaurantId = 1,
                Name = "Awesome appetizer",
                Price = 45,
                HouseSpecial = false,
                Description = "aweesomee appetizer"
            };
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(appetizer);
            var content = new StringContent(json,
            Encoding.UTF8,
            "application/x-www-form-urlencoded"
            );


            // Try to do a post without authorization header, should fail with 401 error
            HttpResponseMessage response = await _client.PostAsync("http://localhost:5002/Appetizer/Restaurant/create", content);
            
            // ASSERT TEST TO FAIL
            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);

        }
Ejemplo n.º 3
0
        //[ValidateAntiForgeryToken]
        public async Task <JsonResult> CreateAppetizer([FromBody] AppetizerInfo appetiezerInfo)
        {
            string emailAddress = HttpContext.User.Identity.Name;

            var restaurant = await _context.Restaurant
                             .Where(rest => rest.EmailAddress.Equals(emailAddress))
                             .FirstOrDefaultAsync();

            if (checkAppetizerNameInSameRestaurant(appetiezerInfo.Name, restaurant.Id))
            {
                HttpContext.Response.StatusCode = 400;
                return(new JsonResult("Appetiezer " + appetiezerInfo.Name + " already exists in restaurant"));
            }

            Appetizer newAppetizer = new Appetizer
            {
                Name         = appetiezerInfo.Name,
                Description  = appetiezerInfo.Description,
                Price        = appetiezerInfo.Price,
                HouseSpecial = appetiezerInfo.HouseSpecial
            };

            if (ModelState.IsValid)
            {
                newAppetizer.RestaurantId = restaurant.Id;

                _context.Add(newAppetizer);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index), new { id = id });
            }

            HttpContext.Response.StatusCode = 200;
            return(new JsonResult("Appetizer successfully created"));
        }
Ejemplo n.º 4
0
        public async Task UpdateAppetizerWithAuthorization()
        {
            // Arrange
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5002/Appetizer/Restaurant/edit");
            request.Headers.Add("Authorization", "Basic " + authorizationValue);
            request.Headers.Add("appetizerName", "Awesome appetizer");
            Appetizer appetizer = new Appetizer
            {
                RestaurantId = 1,
                Name = "More awesome appetizer",
                Price = 48,
                HouseSpecial = true,
                Description = "aweesomee appetizer"
            };
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(appetizer);

            // Try to do a put request
            request.Content = new StringContent(json,
                                    Encoding.UTF8,
                                    "application/json");

            var response = await _client.SendAsync(request);

            // ASSERT TEST TO BE 200
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

        }
Ejemplo n.º 5
0
 private void showAppetizer(Appetizer i_Appetizer)
 {
     errorText.Text        = "";
     quantityText.Text     = "";
     severalDinerText.Text = "";
     currentListBox.Items.Insert(currentListBox.Items.Count, i_Appetizer);
 }
Ejemplo n.º 6
0
        async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44332/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = null;

                // way 1
                //Task<string> stringTask = client.GetStringAsync("api/Dish");
                //Task<string> stringTask = client.GetStringAsync("api/Dish/3");
                string content = JsonConvert.SerializeObject(DishParameters);



                //Task<HttpResponseMessage> stringTask = client.GetAsync("api/Dish/3",new StringContent( content,Encoding.UTF8));
                Task <HttpResponseMessage> stringTask = client.PostAsync("api/Dish", new StringContent(content, Encoding.UTF8, "application/json"));
                response = await stringTask;
                Console.WriteLine(response);

                var appetizer1 = await response.Content.ReadAsStringAsync();

                appetizer = JsonConvert.DeserializeObject <Appetizer>(appetizer1);
                //appetizer = JsonConvert.DeserializeObject<Appetizer>( response.Content.ToString());
            }
        }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            Appetizer appetizer = db.Appetizers.Find(id);

            db.Appetizers.Remove(appetizer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public Dish Post([FromBody] DishParameters dish)
        {
            InitializeDishes initializeDishes = new InitializeDishes();

            //DishParameters dish =   JsonConvert.DeserializeObject<DishParameters>(value);
            Appetizer appetizer = initializeDishes.InitializeAppetizer(dish.Name, dish.Quantity, dish.DinerSerialNumber, eAppetizerTypes.ChickenSkewers);

            return(appetizer);
        }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "AppetizerId,AppetizerName,AppetizerShortDescription,AppetizerLongDescription,AppetizerPrice,AppetizerImage")] Appetizer appetizer)
 {
     if (ModelState.IsValid)
     {
         // db.Entry(appetizer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Admin"));
     }
     return(View(appetizer));
 }
Ejemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "Id,Category,Name,ShortDescription,LongDescription,ThumbnailImage,FullImage,Price")] Appetizer appetizer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(appetizer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(appetizer));
 }
Ejemplo n.º 11
0
        public ActionResult Create([Bind(Include = "AppetizerId,AppetizerName,AppetizerShortDescription,AppetizerLongDescription,AppetizerPrice,AppetizerImage")] Appetizer appetizer)
        {
            if (ModelState.IsValid)
            {
                db.Appetizers.Add(appetizer);
                db.SaveChanges();
                return(RedirectToAction("Admin"));
            }

            return(View(appetizer));
        }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "Id,Category,Name,ShortDescription,LongDescription,ThumbnailImage,FullImage,Price")] Appetizer appetizer)
        {
            if (ModelState.IsValid)
            {
                db.Appetizers.Add(appetizer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appetizer));
        }
Ejemplo n.º 13
0
        // GET: Appetizers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Appetizer appetizer = db.Appetizers.Find(id);

            if (appetizer == null)
            {
                return(HttpNotFound());
            }
            return(View(appetizer));
        }
Ejemplo n.º 14
0
 private void createAppetizer(string i_Name)
 {
     if (severalDinerText.Text == "")
     {
         errorText.Text = "Several Diner Has Not Been Chosen Yet!";
     }
     else if (quantityText.Text == "")
     {
         errorText.Text = "Quantity Has Not Been Chosen Yet!";
     }
     else
     {
         Appetizer appetizer = InitializeFoods.InitializeAppetizer(i_Name, Int32.Parse(quantityText.Text), severalDinerText.Text);
         showAppetizer(appetizer);
     }
 }
Ejemplo n.º 15
0
        public void InitializeAppetizer_ChickenWings()
        {
            string     name              = "Chicken Wings";
            int        quantity          = 2;
            int        dinerSerialNumber = 1;
            eAppetizer appetizerType     = eAppetizer.ChickenWings;
            Appetizer  appetizer         = InitializeDishes.InitializeAppetizer(name, quantity, dinerSerialNumber, appetizerType);

            Assert.AreEqual(appetizerType, appetizer.AppetizerType);
            Assert.AreEqual(dinerSerialNumber, appetizer.DinerSerialNumber);
            Assert.AreEqual(DishRanks.DishesRank[eDishTypes.Appetizer], appetizer.MainRank);
            Assert.AreEqual(name, appetizer.Name);
            Assert.AreEqual(DishPrices.AppetizerPrices[appetizerType], appetizer.Price);
            Assert.AreEqual(quantity, appetizer.Quantity);
            Assert.AreEqual(1, appetizer.SecondRank);
            Assert.AreEqual(DishRanks.AppetizerRanks[appetizerType], appetizer.ThirdRank);
        }
Ejemplo n.º 16
0
        public void OrderTests_SortOrder()
        {
            Order order = new Order();

            string    name              = "Spring Chicken";
            int       quantity          = 2;
            int       dinerSerialNumber = 1;
            eMainDish mainDishType      = eMainDish.SpringChicken;
            MainDish  mainDish2         = InitializeDishes.InitializeMainDish(name, quantity, dinerSerialNumber, mainDishType);

            order.Dishes.Add(mainDish2);


            name              = "Chicken Nuggets";
            quantity          = 2;
            dinerSerialNumber = 1;
            eAppetizer appetizerType = eAppetizer.ChickenNuggets;
            Appetizer  appetizer     = InitializeDishes.InitializeAppetizer(name, quantity, dinerSerialNumber, appetizerType);

            order.Dishes.Add(appetizer);

            name              = "Schnitzel";
            quantity          = 2;
            dinerSerialNumber = 1;
            mainDishType      = eMainDish.Schnitzel;
            MainDish mainDish = InitializeDishes.InitializeMainDish(name, quantity, dinerSerialNumber, mainDishType);

            order.Dishes.Add(mainDish);

            name              = "Chicken Skewers";
            quantity          = 2;
            dinerSerialNumber = 1;
            appetizerType     = eAppetizer.ChickenSkewers;
            Appetizer appetizer2 = InitializeDishes.InitializeAppetizer(name, quantity, dinerSerialNumber, appetizerType);

            order.Dishes.Add(appetizer2);

            order.SortOrder();

            Assert.AreEqual(order.Dishes[0].Name, appetizer.Name);
            Assert.AreEqual(order.Dishes[1].Name, appetizer2.Name);
            Assert.AreEqual(order.Dishes[2].Name, mainDish.Name);
            Assert.AreEqual(order.Dishes[3].Name, mainDish2.Name);
        }
        protected void TableNumber_SelectedIndexChanged(object sender, EventArgs e)
        {
            Appetizer.DataSource = _reservationDao.GetAvailableItems(Course.Appetizer);
            Appetizer.DataBind();
            Appetizer.Visible = true;
            Main.DataSource   = _reservationDao.GetAvailableItems(Course.Main);
            Main.DataBind();
            Main.Visible       = true;
            Dessert.DataSource = _reservationDao.GetAvailableItems(Course.Dessert);
            Dessert.DataBind();
            Dessert.Visible        = true;
            TxtNumOfGuests.Visible = true;
            List <int> nums = new List <int>();

            for (int i = 0; i < 8; i++)
            {
                nums.Add(i + 1);
            }
        }
        public IActionResult AddAppertizer(Appetizer model)
        {
            if (ModelState.IsValid)
            {
                //Läs in JSON-fil
                var JsonStr = System.IO.File.ReadAllText("appetizer.json");
                //Gör om object i JSON-filen till objekt från modellen.
                var JsonObj = JsonConvert.DeserializeObject <List <Appetizer> >(JsonStr);
                //Konvertera till Json-sträng
                JsonObj.Add(model);
                System.IO.File.WriteAllText("appetizer.json", JsonConvert.SerializeObject(JsonObj, Formatting.Indented));

                //Rensar formuläret
                ModelState.Clear();

                ViewData["output"] = "Förrätt tillagd";
            }
            ViewData["Title"] = "Lägg till förrätt";
            return(View());
        }
Ejemplo n.º 19
0
        public void InitializeAppetizer()
        {
            //Appetizer appetizer = initializeDishes.InitializeAppetizer("chicken", 2, 1, eAppetizerTypes.ChickenNuggets);
            //Assert.AreEqual(eAppetizerTypes.ChickenNuggets, appetizer.Type);


            string          name              = "Chicken Nuggets";
            int             quantity          = 2;
            int             dinerSerialNumber = 1;
            eAppetizerTypes appetizerType     = eAppetizerTypes.ChickenNuggets;
            Appetizer       appetizer         = initializeDishes.InitializeAppetizer(name, quantity, dinerSerialNumber, appetizerType);

            Assert.AreEqual(appetizerType, appetizer.Type);
            Assert.AreEqual(dinerSerialNumber, appetizer.DinerSerialNumber);
            Assert.AreEqual(dishesRank.DishTypesRank[eDishTypes.Appetizer], appetizer.MainRank);
            Assert.AreEqual(name, appetizer.Name);
            Assert.AreEqual(dishesPrices.AppetizerPrices[appetizerType], appetizer.Price);
            Assert.AreEqual(quantity, appetizer.Quantity);
            Assert.AreEqual(1, appetizer.SecondRank);
            Assert.AreEqual(dishesRank.AppetizerRanks[appetizerType], appetizer.ThirdRank);
        }
Ejemplo n.º 20
0
        public async Task <JsonResult> DeleteAppetizer()
        {
            string appetizerName = Request.Headers["appetizerName"];

            // check if appetizer exists in database
            if (!AppetizerNameExists(appetizerName))
            {
                // mainCourse not found
                HttpContext.Response.StatusCode = 400;
                return(new JsonResult("Appetizer doesn't exist"));
            }

            Appetizer appetizerToDelete = await _context.Appetizer
                                          .Where(d => d.Name.Equals(appetizerName))
                                          .FirstOrDefaultAsync();

            _context.Appetizer.Remove(appetizerToDelete);
            await _context.SaveChangesAsync();

            HttpContext.Response.StatusCode = 200;
            return(new JsonResult("Appetizer successfully deleted"));
        }
Ejemplo n.º 21
0
 public Drink(string brand, int quantity, Appetizer appetizer)
 {
     this.Brand     = brand;
     this.Quantity  = quantity;
     this.Appetizer = appetizer;
 }
Ejemplo n.º 22
0
 public Whiskey(string name, int quantity, Appetizer appetizer)
     : base(name, quantity, appetizer)
 {
 }
        public void InitializeAppetizer()
        {
            Appetizer appetizer = InitializeDishes.InitializeAppetizer("chicken", 2, 1, eAppetizer.ChickenNuggets);

            Assert.AreEqual(eAppetizer.ChickenNuggets, appetizer.AppetizerType);
        }