public HttpResponseMessage UpdateItems(int id, [FromBody] RestaurantItems items)
 {
     using (GlobalDesignEntities entities = new GlobalDesignEntities())
     {
         try
         {
             var entity = entities.RestaurantItems.FirstOrDefault(e => e.Id == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Tables not found"));
             }
             else
             {
                 entity.ItemCategory = items.ItemCategory;
                 entity.ItemName     = items.ItemName;
                 entity.ItemPrice    = items.ItemPrice;
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
        public async void OnNavigatingTo(INavigationParameters parameters)
        {
            Debug.WriteLine($"**** {this.GetType().Name}.{nameof(OnNavigatingTo)}");

            if (parameters != null && parameters.ContainsKey("ItemAdded"))
            {
                if (RestaurantItems == null)
                {
                    RestaurantItems = new ObservableCollection <Restaurant2SideItem>();
                }
                var itemToAdd = (Restaurant2SideItem)parameters["ItemAdded"];
                RestaurantItems.Add(itemToAdd);

                TotalItems = itemToAdd.ToString();
            }
            await RefreshItemList();
        }
        public ActionResult RegisterTableAndWorker(RestaurantItems item)
        {
            if (ModelState.IsValid)
            {
                HttpClient hc = new HttpClient();
                hc.BaseAddress = new Uri("https://localhost:44382/api/Restaurant");

                var insertrec = hc.PostAsJsonAsync <RestaurantItems>("RegisterTableAndWorker", item);
                insertrec.Wait();

                var saverec = insertrec.Result;
                if (saverec.IsSuccessStatusCode)
                {
                    ViewBag.message = "The user " + item.ItemName + "is inserted succesfully";
                }
            }

            return(View());
        }
 public HttpResponseMessage Post(RestaurantItems items)
 {
     try
     {
         GlobalDesignEntities db = new GlobalDesignEntities();
         db.RestaurantItems.Add(new RestaurantItems()
         {
             RestaurantMail = items.RestaurantMail,
             ItemCategory   = items.ItemCategory,
             ItemName       = items.ItemName,
             ItemPrice      = items.ItemPrice
         });
         db.SaveChanges();
         var message = Request.CreateResponse(HttpStatusCode.Created, items);
         message.Headers.Location = new Uri(Request.RequestUri + items.Id.ToString());
         return(message);
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
예제 #5
0
        enum RestaurantItems { Brisket, Burgers, Fries, Coleslaw, PotatoSalad, Ribs, SmokedChicken, } // Enum variable and types should always be PascalCased and not camelCased
        static void Main(string[] args)
        {
            string  restaurantName   = "B's Briskets and Burgers";
            string  food1            = "brisket";
            double  food1price       = 5.95d;
            double  sidePrice        = 1.75d;
            int     numberofFood     = 5;
            decimal totalCost        = 29.75m;
            bool    isFoodGood       = true;
            bool    doTheyServeTacos = false;

            Console.WriteLine(restaurantName);
            Console.WriteLine(food1);
            Console.WriteLine(food1price);
            Console.WriteLine(sidePrice);
            Console.WriteLine(numberofFood);
            Console.WriteLine(totalCost);
            Console.WriteLine(isFoodGood);
            Console.WriteLine(doTheyServeTacos);

            RestaurantItems order1     = RestaurantItems.Brisket;
            RestaurantItems sideOrder1 = RestaurantItems.Fries;
            //reference types

            //composite
            string color          = "gold";
            string welcomeMessage = string.Format("Welcome {0} star member you have been granted {0} access to premium services.", color);
            string spamEmail      = string.Format("Click on the box below to recieve all the {0} you could want. {0} is increasing in value everyday. So get all the {0} while you still can.", color);
            string randomMessage  = string.Format("I have six {0} teeth. How many {0} teeth do you have?", color);

            Console.WriteLine(welcomeMessage);
            Console.WriteLine(spamEmail);
            Console.WriteLine(randomMessage);

            //interporlation
            string cheese         = "string cheese";
            string pasta          = "mac and cheese";
            string beans          = "kidney beans";
            string randomSentence = $"I love my girlfriend as much as I like {pasta}, I am not sure she feels the same way. But she keeps {cheese}ing me along. I was like, You have to be {beans} not to love me back!";

            Console.WriteLine(randomSentence);

            //concatenation
            string word         = "Hello";
            string concatenated = word + " world! " + word + " class! Welcome to the Gold Badge.";
            //composite
            string composite = string.Format("{0} World! {0} Class! Welcome to the Gold Badge", word);
            //interporlation
            string interpolated = $"{word} World! {word} Class! Welcome to the Gold Badge.";

            Console.WriteLine(concatenated);
            Console.WriteLine(composite);
            Console.WriteLine(interpolated);

            //Array
            char[] charArray = { 'l', 'm', 'z', 'p', 't' };
            Console.WriteLine(charArray[2]);

            //lists
            List <string> listOfFruits = new List <string>();// how do I add more than item to a list at a time, is there a special way to alphabitize them with out doing it manually, also can you print to console more than one list itme at a time, how is that done.

            listOfFruits.Add("apple");
            listOfFruits.Add("lemon");
            listOfFruits.Add("mango");
            listOfFruits.Add("pineapple");
            listOfFruits.Add("rasberry");
            listOfFruits.Add("strawberries");

            Console.WriteLine(listOfFruits[1]);


            //operators
            int a = 42;
            int b = 5;
            //multiplication
            int product = a * b;
            //addition
            int addition = a + b;
            //division
            int division = a * b;
            //double addition
            int sum1 = a + b + b;
            int sum2 = a + a + b;
            //elaborate operators
            int additon1 = a + b * 2;
            int sum3     = a * 2 + b;

            //bool day comparison skipped

            //Conditionals

            //if
            Console.WriteLine("How many hours did you sleep");
            int sleep = Convert.ToInt32(Console.ReadLine());

            if (sleep <= 8)
            {
                Console.WriteLine("I am tired");
            }
            if (sleep >= 20)
            {
                Console.WriteLine("Are you in a coma");
            }

            //if-else
            bool carIsOn   = true;
            bool carHasGas = true;

            if (carIsOn)
            {
                if (carHasGas)
                {
                    Console.WriteLine("Let the Adventure Begin");
                }
            }
            else // can never have condition, however more if statements can be nested inside of it
            {
                if ((carIsOn != true) || (carHasGas != true))
                {
                    Console.WriteLine("Looks like your aren't going anywhere.");
                }
            }

            Console.WriteLine("What Hogwarts house do you belong to?");
            string answer        = Console.ReadLine();
            string hogwartsHouse = answer.ToLower();//converts string answer to lower case

            //switch
            switch (hogwartsHouse)
            {
            case ("hufflepuff"):
                Console.WriteLine("That's nice you belong to Hufflepuff");
                break;

            case ("slytherin"):
                Console.WriteLine("You dirty scoundrel");
                break;

            case ("ravenclaw"):
                Console.WriteLine("You are a raven");
                break;

            case ("Gryffindor"):
                Console.WriteLine("Have you met ................ Harry");
                break;

            default:
                Console.WriteLine("You dont belong to any house? How sad.");
                break;
            }

            //ternaries
            int    volumeLevel = 5;
            string volume      = (volumeLevel == 10) ? "Turn volume down" : "Turn volume up";

            Console.WriteLine(volume);


            bool   canSee     = true;
            string visibility = (canSee == true) ? "Turn lights off" : "Turn lights on";

            Console.WriteLine(visibility);



            //Loops

            int num = 0;

            while (num < 50)//while check condition, while condition is true
            {
                if ((num % 2) != 0)
                {
                    Console.WriteLine(num);
                }
                num++;// increments should not be within if condition in while loops they must be while condition but below the if condition
            }
            //this example checks the while condition to see if it is true, then checks the (if condition) if (if condition) is met then it writes to the console the number. if not it skips down to num++ and adds a number rechecks while condition to see if it is true if it is true goes back to if condition. if while condition is not true the loop stops.

            //for loops
            for (int num2 = 0; num2 < 50; num2 += 5) // (starting value, condition, what is done at the end of each loop)
            {
                Console.WriteLine(num2);
            }


            //foreach loop
            double[] niceNumbers = { 5d, 42d, 3d, 3d, 3d, 3, 3d, 3.14159d };
            foreach (double number in niceNumbers) // (new variable | collection type )
            {
                Console.WriteLine(number);
            }

            //do while loops (do whiles loop at least once, then checks to see if while condition is still true if so it loops until while condtions result is false.)
            int whileCondition = 0;

            do
            {
                Console.WriteLine("The console is finished");
            }while (whileCondition > 1);

            int iterator = 0;

            do
            {
                Console.WriteLine("Hurray for cheeseburgers");
                iterator++;
            }while (iterator < 10);
        }