Example #1
0
        public POCO.Meal create(POCO.Meal meal)
        {
            if (meal == null)
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrEmpty(meal.Name))
            {
                throw new ArgumentOutOfRangeException();
            }

            var m = new Meals
            {
                Name        = meal.Name,
                Information = meal.Information,
                DietPlanId  = meal.DietPlanId,
                Alarm       = meal.Alarm,
                Reminder    = meal.Reminder
            };

            m       = _genericAccess.Add(m);
            meal.Id = m.Id;

            return(meal);
        }
        public static string GetMeal(Meals meal)
        {
            switch (meal)
            {
            case Meals.Hamburger: return("Hamburger");

            case Meals.VeggieBurger: return("Veggie Burger");

            case Meals.Burrito: return("Burrito");

            case Meals.Cheeseburger: return("Cheeseburger");

            case Meals.ChickenSandwich: return("Chicken Sandwich");

            case Meals.FriedChicken: return("Fried Chicken");

            case Meals.HotDog: return("Hot Dog");

            case Meals.Kebab: return("Kebab");

            case Meals.Oatmeal: return("Oatmeal");

            case Meals.Taco: return("Taco");

            default: return("");
            }
        }
Example #3
0
        public bool UpdateMealById(Meals meal, int Id)
        {
            bool status = false;
            var  dbMeal = GetMealById(Id);

            if (dbMeal != null)
            {
                dbMeal.Name     = meal.Name;
                dbMeal.MealType = meal.MealType;
            }
            else
            {
                dbMeal = new Meals
                {
                    Name         = meal.Name,
                    MealType     = meal.MealType,
                    IsActive     = true,
                    CreatedOnUtc = DateTime.UtcNow
                };
                _airlineContext.Meals.Add(dbMeal);
            }

            try
            {
                _airlineContext.SaveChanges();
                status = true;
            }
            catch { }
            return(status);
        }
Example #4
0
        public bool AddMealData(AddMealRequest request)
        {
            if (request != null)
            {
                Meals Meal = new Meals();
                Meal.MealName      = request.Name;
                Meal.Image         = request.Image;
                Meal.CountryId     = request.CountryId;
                Meal.ingredientsId = request.IngredientsId;
                _db.Meals.Add(Meal);
                _db.SaveChanges();
                int maxm = _db.Meals.Max(p => p.Id);

                Requirements IngredientsData = new Requirements();

                IngredientsData.Components        = request.components;
                IngredientsData.ImagesIngredients = request.ImageIngredients;
                IngredientsData.Instructions      = request.Instructions;
                IngredientsData.MealsId           = maxm;
                _db.Requirements.Add(IngredientsData);
                _db.SaveChanges();
                return(true);
            }

            return(false);
        }
 public void ChangeMeal(string fname, string lname, Meals m)
 {
     if (ChangeMealEvent != null)
     {
         ChangeMealEvent(this, new ChangeMealEventArgs(fname, lname, m));
     }
 }
 public static void SetMealsToEatOut(params Meals[] meals)
 {
     foreach (var m in meals)
     {
         MealsToEatOut |= m;  // similar to doing this  MealsToEatOut = Meals.Breakfast | Meals.Snack | Meals.Dinner;
     }
 }
Example #7
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;

            try
            {
                Notes.Clear();
                Meals.Clear();
                var notes = await PluralsightDataStore.GetNotesAsync();

                var meals = await PluralsightDataStore.GetMealsAsync();

                foreach (var note in notes)
                {
                    Notes.Add(note);
                }
                foreach (var meal in meals)
                {
                    Meals.Add(meal);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #8
0
 public Meal(Meals meal)
 {
     this.Id           = meal.Id;
     this.Name         = meal.Name;
     this.Servings     = meal.Servings;
     this.Instructions = meal.Instructions;
 }
Example #9
0
        public void AssignMealsToEatOutUsingFlags()
        {
            // single pipe, "|", in C# is a logic operator, not conditional.
            // used at binary level to OR each position of the binary values.
            // with an OR, the result is true when at least one condition is true;
            // otherwise the result is false.

            /*
             * EXAMPLE:
             *
             * MealsToEatOut  = Meals.Breakfast | Meals.Snack | Meals.Dinner;
             *
             * Breakfast    0	0	0	0	0	0	1
             |	|	|	|	|	|	|
             | Snack    0	0	0	0	1	0	0
             |	|	|	|	|	|	|
             | Dinner	0	0	0	1	0	0	0
             |  ________________________________________
             |  Result	0	0	0	1	1	0	1
             |
             | Use the logical AND operator "&" to see if the result has a flag set.
             |
             | if((MealsToEatOut & Meals.Breakfast) == Meals.Breakfast)
             |  {
             |      // has Breakfast
             |  }
             |  else
             |  {
             |      // DOES NOT have Breakfast
             |  }
             |
             |  MealsToEatOut	0	0	0	1	1	0	1
             |                      &	&	&	&	&	&	&
             |      Breakfast	0	0	0	0	0	0	1
             |    ________________________________________
             |        Result	0	0	0	0	0	0	1   --> has breakfast
             |
             */

            //
            // Array Initializers
            //
            var exepectedMealsToEatOut = new[] { Meals.Breakfast, Meals.Lunch, Meals.LateNight };
            // another way... exepectedMealsToEatOut[] = {Meals.Breakfast, Meals.Lunch, Meals.LateNight};
            var actualMealsToEatOut = new Meals[3];                  // creates an array for three elements

            EatingOut.SetMealsToEatOut(exepectedMealsToEatOut);      // using params here!

            var meals = Enum.GetValues(typeof(Meals)).Cast <Enum>(); // cast to Enum in order to do the Where...below

            var index = 0;

            foreach (var appointment in meals.Where(EatingOut.MealsToEatOut.HasFlag))
            {
                actualMealsToEatOut[index] = (Meals)appointment;
                index++;
            }

            Assert.IsTrue(actualMealsToEatOut.SequenceEqual(exepectedMealsToEatOut)); // https://www.dotnetperls.com/sequenceequal
        }
Example #10
0
        public async Task <IActionResult> PutMeals(int id, Meals meals)
        {
            if (id != meals.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, [Bind("MealId,StaffId,CustomerId,DateOfMeal,CostOfMeal,IsActive,CreatedBy,CreatedOn,UpdatedBy,UpdatedOn")] Meals meals)
        {
            if (id != meals.MealId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(meals);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MealsExists(meals.MealId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(meals));
        }
Example #12
0
        public ActionResult Create([Bind(Include = "Id,OrdId,DishId,Status")] Meals meals)
        {
            if (ModelState.IsValid)
            {

                Ord CurrentOrder = db.Ord.Find(meals.OrdId);
                if (CurrentOrder != null) {

                ViewBag.IsOrdClosed = false;
                if ( CurrentOrder.TimeEnd != null)
                    {
                        db.Meals.Add(meals);
                        CurrentOrder.TotalCost += db.Dish.Find(meals.DishId).Price;
                        db.Entry(CurrentOrder).State = EntityState.Modified;
                        db.SaveChanges();
                        ViewBag.IsOrdClosed = true;
                    }
            }
                //return RedirectToAction("Create", "Meals", new { ordId = meals.OrdId });
            }
            IEnumerable<Meals> MenuMeals = db.Meals.Where(u => u.OrdId == meals.OrdId).AsEnumerable();
            ViewBag.dishes = MenuMeals;
            ViewBag.DishId = new SelectList(db.Dish, "Id", "Name", meals.DishId);
            return View(meals);
        }
Example #13
0
        public async Task <bool> DeleteMeal(Meals meal)
        {
            try
            {
                //Need to remove history if it exists before removing the meal itself
                var results = await mhData.Get <Meals>(x => x.MealsFK == meal.ID);

                var tEntry = await thData.Get(x => x.EntryDate == DateTime.Today);

                foreach (var item in results)
                {
                    await mhData.Delete(item);

                    if (tEntry == null)
                    {
                        Debug.WriteLine("**IRREGULARITY** - No TotalHistory found for today under DeleteMeal.");
                    }
                    else
                    {
                        tEntry.CaloriesTotal -= meal.Calories;
                        await thData.Update(tEntry);
                    }
                }

                await mealData.Delete(meal);

                return(true);
            }
            catch
            {
                Debug.WriteLine("DeleteMeal failed.");

                return(false);
            }
        }
Example #14
0
        static void SetMeals(string filename)
        {
            var lines = File.ReadAllLines(filename);

            for (var i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                //var value = line.Split(';');

                string name = line;
                Console.WriteLine(name);
                //string name = value[0];
                //double weight = Convert.ToDouble(value[1].Replace('.', ','));
                //double kcal = Convert.ToDouble(value[2].Replace('.', ','));
                //double protein = Convert.ToDouble(value[3].Replace('.', ','));
                //double fat = Convert.ToDouble(value[4].Replace('.', ','));
                //double carbs = Convert.ToDouble(value[5].Replace('.', ','));
                //string type = value[6];

                var newMeal = new Meals(name /*, weight, kcal, protein, fat, carbs, type*/);

                Console.WriteLine($"{i}.");

                MealsRepos.Insert(newMeal);
            }
        }
 public bool AddMeal(AddMealRequestByAdmin requestByAdmin)
 {
     if (requestByAdmin != null)
     {
         Meals meals = new Meals();
         meals.MealName             = requestByAdmin.MealName;
         meals.MealImageUrl         = requestByAdmin.MealImageUrl;
         meals.MealDescription      = requestByAdmin.MealDescription;
         meals.SubIngredientOne     = requestByAdmin.SubIngredientOne;
         meals.SubIngredientOneUrl  = requestByAdmin.SubIngredientOneUrl;
         meals.SubIngredientTwo     = requestByAdmin.SubIngredientTwo;
         meals.SubIngredientThree   = requestByAdmin.SubIngredientThree;
         meals.SubIngredientFour    = requestByAdmin.SubIngredientFour;
         meals.SubIngredientFourUrl = requestByAdmin.SubIngredientFourUrl;
         meals.SubIngredientFive    = requestByAdmin.SubIngredientFive;
         meals.SubIngredientFiveUrl = requestByAdmin.SubIngredientFiveUrl;
         meals.SubIngredientSix     = requestByAdmin.SubIngredientSix;
         meals.SubIngredientSixUrl  = requestByAdmin.SubIngredientSixUrl;
         meals.CountrysId           = requestByAdmin.CountrysId;
         meals.MainIngredientsId    = requestByAdmin.MainIngredientsId;
         _db.Meals.Add(meals);
         _db.SaveChanges();
         return(true);
     }
     return(false);
 }
        private async void goToRecipe(Recipe recipe)
        {
            IsBusy = true;
            try
            {
                var json = await RestService.GetRecipeByIdJsonAsync(recipe.idMeal.ToString());

                Meals meals = JsonConvert.DeserializeObject <Meals>(json);

                if (meals.meals != null)
                {
                    foreach (Recipe theRecipe in meals.meals)
                    {
                        recipe = theRecipe;
                    }
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Error", "There was an error with the connection.", "OK");
                }
            }
            finally
            {
                IsBusy = false;
            }

            await Navigation.PushAsync(new RecipePage(recipe));
        }
Example #17
0
        public static bool SaveMeal(Meals meal)
        {
            try
            {
                using (var db = new mennuContext())
                {
                    if (false)//!meal.Id.HasValue())
                    {
                        //meal.Id = Guid.NewGuid();
                    }

                    db.Meals.Add(meal);
                    var rowsChanged = db.SaveChanges();

                    if (rowsChanged > 0)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                // todo logging
                return(false);
            }
            return(false);
        }
Example #18
0
        /// <summary>
        /// // 1. Create Meals
        /// </summary>
        private void CreateNewMeal()
        {
            Console.Clear();
            Meals mealMenu = new Meals();

            //MealNumber
            Console.WriteLine("What is the Meal Number");
            mealMenu.MealNumber = int.Parse(Console.ReadLine());


            //MealName
            Console.WriteLine("What is the Name of the Meal");
            mealMenu.MealName = Console.ReadLine();


            //Meal Description
            Console.WriteLine("What is the Description of this Meal");
            mealMenu.Description = Console.ReadLine();

            //List of Ingrediants
            Console.WriteLine("List of Ingredients");
            mealMenu.ListOfIngredients = Console.ReadLine();

            //Meal Price
            Console.WriteLine("List the Price of the Meal");
            mealMenu.MealPrice = double.Parse(Console.ReadLine());

            _meals.AddMealsToList(mealMenu);
        }
Example #19
0
        async Task ExecuteLoadMealsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var items = await DataStore.GetItemsAsync(true);

                foreach (var item in items)
                {
                    Meals.Add(new MealViewModel(item));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #20
0
 public BaseTour(int price, string country, Meals mealType, int hotelRank)
 {
     Price     = price;
     Country   = country;
     MealType  = mealType;
     HotelRank = hotelRank;
 }
Example #21
0
 public void EditMode(Meals meals)
 {
     Name     = meals.Name;
     MealType = meals.MealType;
     Id       = meals.Id;
     Title    = "Edit Meal";
 }
Example #22
0
        public void AddMeal()
        {
            var req = HttpContext.Current.Request;

            if (req.Files.Count > 0)
            {
                foreach (string ph in req.Files)
                {
                    var postedFile = req.Files[ph];
                    var filePath   = HttpContext.Current.Server.MapPath("~/Content/images/" + postedFile.FileName);
                    postedFile.SaveAs(filePath);
                }

                var nameValueCollection = HttpContext.Current.Request.Form;
                var m = new Meals
                {
                    Name     = nameValueCollection["Name"],
                    Price    = Convert.ToDouble(nameValueCollection["Price"]),
                    Category = nameValueCollection["Category"],
                    Photo    = nameValueCollection["Photo"],
                };

                _context.Meals.Add(m);
                _context.SaveChanges();
            }
        }
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            IsBusy = true;

            try
            {
                var json = await RestService.GetRecipesByCategoriesJsonAsync(category.strCategory);

                Meals meals = JsonConvert.DeserializeObject <Meals>(json);

                if (meals.meals != null)
                {
                    foreach (var recipe in meals.meals)
                    {
                        list.Add(recipe);
                    }
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Error", "No results were found.", "OK");
                }
            }
            finally
            {
                IsBusy = false;
            }

            recipesByCategoryList.ItemsSource   = list;
            recipesByCategoryList.ItemSelected += delegate {
                var seleccionado = recipesByCategoryList.SelectedItem as Recipe;
                goToRecipe(seleccionado);
            };
        }
Example #24
0
 public Excursion(int price, string country, Meals mealType, int hotelRank)
     : base(price, country, mealType, hotelRank)
 {
     Price     = price;
     Country   = country;
     MealType  = mealType;
     HotelRank = hotelRank;
 }
        private bool DetailFilter(Guid timeofday, DateTime dateResult, Meals meal)
        {
            var guidToTest = new Guid("00000000-0000-0000-0000-000000000001");

            //var guid = Guid.Parse(timeofday);
            //var dateResult = DateTime.Parse(date);
            return(guidToTest == meal.ProfileId && meal.Day.Year == dateResult.Year && meal.Day.DayOfYear == dateResult.DayOfYear && timeofday == meal.TimeOfDayId && meal.IsDeleted == false);
        }
Example #26
0
 public void ChangeMeal(string fname, string lname, Meals m)
 {
     //ChangeMealEventHandeler change = ChangeMealEvent;
     if (ChangeMealEvent != null)
     {
         ChangeMealEvent(this, new ChangeMealEventArgs(fname, lname, m));
     }
 }
        private void LoadDataAsync()
        {
            void Action()
            {
                Meals.AddRange(_mealRepository.GetAll());
            }

            Task.Run(Action);
        }
Example #28
0
        static void UpdateMeals()
        {
            var mealsRepos = MealsRepos.GetAll();

            foreach (var meal in mealsRepos)
            {
                var ingredientsRepos = IngredientsRepos.GetByID(meal.ID.Value);

                int n = ingredientsRepos.Count;

                int?   ID     = meal.ID;
                string Name   = meal.Name;
                double Kcal   = 0;
                double Prot   = 0;
                double Fat    = 0;
                double Carbs  = 0;
                double Weight = 0;
                int[]  Type   = new int[n];

                Console.WriteLine($"Meal no. {meal.ID.Value} - {Name}");

                for (int j = 0; j < n; j++)
                {
                    var weight = ingredientsRepos[j].Weight;

                    Kcal   += ingredientsRepos[j].Kcal * weight * 0.01;
                    Prot   += ingredientsRepos[j].Protein * weight * 0.01;
                    Fat    += ingredientsRepos[j].Fat * weight * 0.01;
                    Carbs  += ingredientsRepos[j].Carbs * weight * 0.01;
                    Weight += ingredientsRepos[j].Weight;

                    var t = ingredientsRepos[j].Type;

                    if (t == Projekt.Properties.Resources.normal)
                    {
                        Type[j] = 0;
                    }
                    if (t == Projekt.Properties.Resources.vegetarian)
                    {
                        Type[j] = 1;
                    }
                    if (t == Projekt.Properties.Resources.vegan)
                    {
                        Type[j] = 2;
                    }

                    //Console.WriteLine(Type[j]);
                }
                var type = Type.Min().ToString();

                //Console.WriteLine($"min: {type}");

                var newMeal = new Meals(Name, Weight, Kcal, Prot, Fat, Carbs, type);

                MealsRepos.Update(newMeal, ID);
            }
        }
Example #29
0
        public void DeleteHotMealAsync()
        {
            var request = new HttpRequestMessage(HttpMethod.Delete, $"api/hotmeals");

            request.Content = new StringContent(JsonConvert.SerializeObject(HotMealsDeleteItem), Encoding.UTF8, "application/json");
            var response = this.client.SendAsync(request).Result;

            Meals.Remove(this.HotMealsDeleteItem);
        }
Example #30
0
        private void OnRemoveMeal(object p)
        {
            Meal meal = p as Meal;

            Meals.Remove(meal);
            mealRepository.Remove(meal);
            mealRepository.SaveChangesAsync();
            CalcTotalNutritionFact();
        }
        static Dictionary<string, object> getValue(Meals m)
        {
            Dictionary<string, object> data = new Dictionary<string, object>();
            data["AvgMealsPerDay"] = m.AvgMealsPerDay;
            data["AvgNonVegPerMTypeId"] = m.AvgNonVegPerMTypeId;
            data["FoodSourceTypes"] = m.FoodSourceTypes;
            data["CEGrains"] = m.CEGrains;
            data["CEPulse"] = m.CEPulse;
            data["CEVegetables"] = m.CEVegetables;
            data["MilkAsideAmount"] = m.MilkAsideAmount;
            data["PKGPerMTypeId"] = m.PKGPerMTypeId;
            data["OrigEntryDate"] = FormatHelper.FormatOrigDate(m.OrigEntryDate);

            return data;
        }