Esempio n. 1
0
 /// <summary>
 /// Constructor of Meal Control class
 /// </summary>
 /// <param name="dailyMeal">Daily Meal</param>
 /// <param name="user">User</param>
 public MealControl(DailyMeal dailyMeal, User user)
 {
     this.dailyMeal = dailyMeal;
     this.user      = user;
     InitializeComponent();
     UpdateLabels(null, EventArgs.Empty);
 }
Esempio n. 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="dailyMeal">Daily Meal</param>
 /// <param name="user">User</param>
 public UpdateDailyMealForm(DailyMeal dailyMeal, User user)
 {
     this.user      = user;
     this.dailyMeal = dailyMeal;
     InitializeComponent();
     LoadToComboBox();
 }
 /// <summary>
 /// Add meal to localDB
 /// </summary>
 /// <param name="dailyMeal"></param>
 /// <returns>void</returns>
 public void AddMeal(DailyMeal dailyMeal)
 {
     if (dailyMeal == null)
     {
         throw new ArgumentNullException(nameof(dailyMeal));
     }
     _context.DailyMeals.Add(dailyMeal);
 }
Esempio n. 4
0
        /// <summary>
        /// On Button click Method
        /// </summary>
        private void buttonOk_Click(object sender, EventArgs e)
        {
            Meal     meal = comboBox1.SelectedItem as Meal;
            Database db   = new Database();

            dailyMeal = new DailyMeal(meal, dateTime);
            db.DailyMealsDataAdd(dailyMeal, user);
            this.Close();
        }
Esempio n. 5
0
        private async Task AddDailyMealWithUserId(DailyMeal dMealToAdd, int userId)
        {
            dMealToAdd.TimeOfLastMeal     = DateTime.Now;
            dMealToAdd.CreatedBy          = userId;
            dMealToAdd.CaloriesPerPortion =
                await _calc.CalculaCaloriesPerPortion(dMealToAdd.Id, dMealToAdd.Grams);

            _repoUser.AddMeal(dMealToAdd);
            await _repoUser.SaveChangesAsync();
        }
Esempio n. 6
0
 private async Task UpdateGramsTitleRemarksInDailyMeal(DailyMealToAddDto dailyMealToAddDto, DailyMeal dMeal)
 {
     dMeal.Grams       = dailyMealToAddDto.Grams;
     dMeal.Title       = dailyMealToAddDto.Title;
     dMeal.UserRemarks = dailyMealToAddDto.UserRemarks;
     _repoUser.UpdateMeal(dMeal);
     await _repoUser.SaveChangesAsync();
 }
 public void UpdateMeal(DailyMeal meal)
 => _context.DailyMeals.Update(meal);
Esempio n. 8
0
        private static Dictionary <DailyMeal, List <string> > ParseMenu(string rawMenu)
        {
            var items = new Dictionary <DailyMeal, List <string> >();

            //var removedItems = new List<string>();

            string[] allLines = rawMenu.Split(Environment.NewLine.ToCharArray());

            List <string> bannedWords = new List <string> {
                "chef", "subject", "entree"
            };

            bannedWords.AddRange(Enum.GetNames(typeof(DayOfWeek)).Select(d => d.ToLower()));

            DailyMeal lastSection = DailyMeal.Other;

            for (int i = 0; i < allLines.Length; i++)
            {
                string input = allLines[i];

                input = input.Replace(" X", "").Replace(" x", "").Trim();

                if (bannedWords.Any(d => input.ToLower().Contains(d)))
                {
                    //removedItems.Add(input);
                    continue;
                }

                if (String.IsNullOrWhiteSpace(input.Trim()))
                {
                    continue;
                }

                string endWord = input.Split(' ').Last().ToLower().Trim();

                if ((endWord == "and" || endWord == "with") && i != allLines.Length - 1)
                {
                    input = input + " " + allLines[i + 2].Trim();
                    i    += 2;
                }

                foreach (string meal in Enum.GetNames(typeof(DailyMeal)).Select(d => d.ToLower()))
                {
                    if (input.ToLower().Contains(meal))
                    {
                        var inputWords = input.ToLower().Split(':', ' ');
                        foreach (string word in inputWords)
                        {
                            if (word != meal)
                            {
                                continue;
                            }

                            lastSection = (DailyMeal)Enum.Parse(typeof(DailyMeal), word, true);
                            break;
                        }
                    }
                }

                if (items.ContainsKey(lastSection))
                {
                    items[lastSection].Add(input.ToLower());
                }
                else
                {
                    items.Add(lastSection, new List <string> {
                    });
                }
            }

            return(items);
        }