Esempio n. 1
0
        public static int SaveWeeklyMenu(WeeklyMenu weeklyMenu)
        {
            using (DBKOMPDataContext db = new DBKOMPDataContext())
            {
                if (weeklyMenu.Id == 0)
                {
                    db.WeeklyMenus.InsertOnSubmit(weeklyMenu);
                }
                else
                {
                    var obj = db.WeeklyMenus.Where(w => w.Id == weeklyMenu.Id).First();
                    obj.Monday    = weeklyMenu.Monday;
                    obj.Tuesday   = weeklyMenu.Tuesday;
                    obj.Wednesday = weeklyMenu.Wednesday;
                    obj.Thursday  = weeklyMenu.Thursday;
                    obj.Friday    = weeklyMenu.Friday;
                    obj.Saturday  = weeklyMenu.Saturday;
                    obj.Sunday    = weeklyMenu.Sunday;
                }

                db.SubmitChanges();
                CacheHelper.Clear("WEEKLYMENU");
                CacheHelper.Clear("WEEKLYMENUA");
            }

            return(weeklyMenu.Id);
            // }
        }
Esempio n. 2
0
        private static void InitializeApp()
        {
            var menus = LoadDataAndRandomize("Menus", 15);
            var len   = Enum.GetValues(typeof(ChoiceEnum)).Length;

            WeeklyMenus = new WeeklyMenu[len];
            for (int i = 0; i < len; i++)
            {
                var wm = WeeklyMenus[i] = new WeeklyMenu();
                wm.MenuMark      = (ChoiceEnum)i;
                wm.MondayMenu    = menus[5 * i];
                wm.TuesdayMenu   = menus[5 * i + 1];
                wm.WednesdayMenu = menus[5 * i + 2];
                wm.ThursdayMenu  = menus[5 * i + 3];
                wm.FridayMenu    = menus[5 * i + 4];
            }
            if (!Directory.Exists(GetPath("Documents")))
            {
                Directory.CreateDirectory(GetPath("Documents"));
            }
            try
            {
                Directory.EnumerateFiles(GetPath("Documents")).ToList().ForEach(it => File.Delete(it));
            }
            catch { }
        }
        public WeeklyMenu NewMenu(UserProfile userProfile)
        {
            WeeklyMenu result = new WeeklyMenu(this);
            Random     rnd    = new Random();

            foreach (DailyMenu dm in result)
            {
                int num = rnd.Next(1, 4);
                for (int i = 0; i < num; i++)
                {
                    List <Serving> servings = new List <Serving>();
                    int            num2     = rnd.Next(1, 3);
                    for (int j = 0; j < num2; j++)
                    {
                        servings.Add(new Serving(KitchenManager.Dishes.RandomElement(), new Random().Next(120)));
                    }
                    NonEmptyList <Serving> nonempty = new NonEmptyList <Serving>(servings[0]);
                    for (int j = 1; j < servings.Count; j++)
                    {
                        nonempty.Add(servings[j]);
                    }
                    dm.Meals.Add(new Meal("pasto " + i, new DateTime(2000, 1, 1, rnd.Next(24), rnd.Next(60), 0), nonempty));
                }
            }
            return(result);
        }
        public Response GetMenuOrder_SUZHYC(string token, [FromBody] WeeklyMenu param)
        {
            Response response = new Response();

            if (string.IsNullOrEmpty(token) || !token.Equals(_token))
            {
                response.code    = "404";
                response.message = "Invild token";
            }
            else
            {
                var lstMenuOrders = MenuOrderHelper.GetMenuOrder_SUZHYC(param);

                if (lstMenuOrders == null || lstMenuOrders.Count == 0)
                {
                    response.code    = "500";
                    response.message = "No Data";
                }
                else
                {
                    response.code    = "200";
                    response.content = lstMenuOrders.ToDynamicList("330F333F-E651-48D4-A8B6-535890ABF336");
                }
            }
            return(response);
        }
        public Response SaveMenuOrder_SUZHYC(string token, [FromBody] WeeklyMenu param)
        {
            ;
            Response response = new Response();

            if (string.IsNullOrEmpty(token) || !token.Equals(_token))
            {
                response.code    = "404";
                response.message = "Invild token";
            }
            else
            {
                int result = MenuOrderHelper.SaveMenuOrder_SUZHYC(param);
                if (result == 0)
                {
                    response.code    = "500";
                    response.message = "No Data";
                }
                else
                {
                    response.code    = "200";
                    response.content = result;
                }
            }
            return(response);
        }
Esempio n. 6
0
        public void Show(WeeklyMenu weekly_menu)
        {
            SetAllExpansion(false);
            SetAllSelection(false);

            weekly_menu.Select();
        }
Esempio n. 7
0
        public ActionResult <IEnumerable <WeeklyMenu> > GetWeeklyMenu()
        {
            var items = new List <WeeklyMenu>();

            try
            {
                using (con = new MySqlConnection(conStr))
                {
                    if (con.State != ConnectionState.Open)
                    {
                        con.Open();
                        MySqlCommand    cmd    = new MySqlCommand("select * from weekly_menu", con);
                        MySqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            var item = new WeeklyMenu();
                            item.id           = reader.GetInt16("id");
                            item.day          = reader.GetString("type");
                            item.menu_id      = reader.GetInt16("menu_id");
                            item.meal_type_id = reader.GetInt16("meal_type_id");

                            items.Add(item);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(items);
        }
 public UserProfile(UserProfile other)
 {
     _preferences = new List<Ingredient>(other._preferences);
     _goal = other._goal;
     _diet = new WeeklyMenu(other._diet);
     _details = new PersonalDetails(other._details);
 }
 public static bool IsOk(this WeeklyMenu menu)
 {
     /*foreach (DailyMenu d in menu.DailyMenus)
      *  if (!d.IsOk())
      *      return false;
      * WriteLine("WeeklyMenuValidator");*/
     return(true);
 }
        private void PaintUpperPanel(WeeklyMenu diet)
        {
            UpperPanel.Controls.Clear();
            RadLabel radLabel = new RadLabel();

            radLabel.Text          = diet.DietCalculator.Description;
            radLabel.Font          = new Font("Arial", 18, FontStyle.Bold);
            radLabel.TextAlignment = ContentAlignment.MiddleCenter;
            radLabel.Dock          = DockStyle.Fill;
            radLabel.BackColor     = Color.Transparent;
            UpperPanel.Controls.Add(radLabel);
        }
Esempio n. 11
0
 public static WeeklyMenuViewModel toWeeklyViewModel(this WeeklyMenu menu)
 {
     return(new WeeklyMenuViewModel
     {
         Id = menu.Id,
         Recipe = menu.Recipe,
         RecipeId = menu.RecipeId,
         UserId = menu.UserId,
         Day = menu.Day,
         User = menu.User
     });
 }
        private void PaintDiet(WeeklyMenu diet)
        {
            ((System.ComponentModel.ISupportInitialize)DietPanel).BeginInit();
            DietPanel.SuspendLayout();
            DietPanel.Controls.Clear();

            RadListView dailyMenusListView = new DailyMenusListView();

            dailyMenusListView.DataSource = diet.DailyMenus;
            DietPanel.Controls.Add(dailyMenusListView);

            ((System.ComponentModel.ISupportInitialize)DietPanel).EndInit();
            DietPanel.ResumeLayout(true);
        }
Esempio n. 13
0
        public void Add(string userId, string day, int recipeId)
        {
            var recipe = RecipeRepo.GetById(recipeId);
            var Menu   = new WeeklyMenu();

            Menu.Day    = day;
            Menu.Recipe = recipe;
            //Menu.RecipeId = recipeId;
            Menu.Day    = day;
            Menu.UserId = userId;

            MenuRepo.Add(Menu);
            recipe.WeeklyMenus.Add(Menu);
            //RecipeRepo.Edit(recipe);
        }
Esempio n. 14
0
        public ActionResult Add(WeeklyMenuModel model)
        {
            foreach (var item in model.WeeklyMenuList)
            {
                var WeeklyMenuENtry = new WeeklyMenu()
                {
                    DayName = item.DayName,
                    MenuId  = item.MenuId
                };


                context.weeklyMenus.Add(WeeklyMenuENtry);
                context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public void Remove(WeeklyMenu menu)
        {
            var userId = menu.UserId;

            Context.WeeklyMenus.Remove(menu);
            var recipe      = menu.Recipe;
            var Ingredients = recipe.Ingredients;

            foreach (var ingredient in Ingredients)
            {
                var checking = Context.Checkings.FirstOrDefault(x => x.IngredientId == ingredient.Id && x.UserId == userId);
                if (checking != null)
                {
                    Context.Checkings.Remove(checking);
                }
            }
            Context.SaveChanges();
        }
Esempio n. 16
0
        public static ScaniaRestaurant ConvertFrom(Restaurant restaurant, WeeklyMenu menu)
        {
            ScaniaRestaurant scaniaRestaurant = new ScaniaRestaurant();

            scaniaRestaurant.RestaurantId = restaurant.Id;
            scaniaRestaurant.Name         = restaurant.Name;

            scaniaRestaurant.Weeks = new List <ScaniaWeek>();

            int index = 0;

            foreach (var week in menu.Weeks)
            {
                if (index == 0)
                {
                    scaniaRestaurant.DisplayName = week.MenuName;
                }

                var scaniaWeek = new ScaniaWeek();
                scaniaWeek.WeekNumber = week.WeekNumber;
                scaniaWeek.Menus      = new List <ScaniaDay>();

                foreach (var day in week.Days)
                {
                    ScaniaDay scaniaDay = new ScaniaDay();
                    scaniaDay.Date  = DateTime.ParseExact(day.DayMenuDate, "yyyyMMdd", CultureInfo.InvariantCulture);
                    scaniaDay.Meals = new List <ScaniaMeal>();

                    foreach (var dayMenu in day.DayMenus)
                    {
                        ScaniaMeal meal = new ScaniaMeal();
                        meal.AlternativeName = dayMenu.MenuPresentation.MenuAlternativeName;
                        meal.Name            = dayMenu.MenuPresentation.DayMenuName;
                        scaniaDay.Meals.Add(meal);
                    }
                    scaniaWeek.Menus.Add(scaniaDay);
                }
                scaniaRestaurant.Weeks.Add(scaniaWeek);

                index++;
            }

            return(scaniaRestaurant);
        }
Esempio n. 17
0
        public ActionResult WeeklyMenu()
        {
            PageModel.Title            = "Contact About Boostrap Project";
            PageModel.Description      = "Bootstrap Template Project";
            PageModel.Author           = "Bootstrap";
            PageModel.Keywords         = "Boostrap project, starter project, soe keywords, keywords";
            PageModel.ActiveTopNavLink = "MainNavContact";

            WeeklyMenu Model = new WeeklyMenu();

            using (var db = new DIYFE.EF.DIYFEEntities())
            {
                Model.ShoppingList    = db.IngredientShoppings.ToList();
                Model.DailyRecipes    = db.DailyRecipes.ToList();
                Model.SeasonalRecipes = db.SeasonalRecipes.ToList();
            }

            return(View(Model));
        }
 /// <summary>
 /// 获取取SUZHYC周单数据
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static List <WeeklyMenu> GetMenuOrder_SUZHYC(WeeklyMenu param)
 {
     try
     {
         List <WeeklyMenu> lstMenuOrders = weeklyFactory.GetMenuOrder_SUZHYC(param);
         if (lstMenuOrders.Count == 0)
         {
             throw new Exception("DAL.MenuOrder.WeeklyMenuFactory..GetMenuOrder_SUZCHY()==null");
         }
         return(lstMenuOrders);
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(new Log()
         {
             message = ex.Message
         }, "lstMenuOrders");
         return(null);
     }
 }
 /// <summary>
 /// 存数据SUZHYC
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static int SaveMenuOrder_SUZHYC(WeeklyMenu param)
 {
     try
     {
         int result = weeklyFactory.SaveMenuOrder_SUZHYC(param);
         if (result == 0)
         {
             throw new Exception("DAL.MenuOrder.WeeklyMenuFactory.SaveMenuOrder_SUZHYC()==0");
         }
         return(result);
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(new Log()
         {
             message = ex.Message
         }, "result");
         return(0);
     }
 }
Esempio n. 20
0
 public void Open(WeeklyMenu week_menu)
 {
     ViewModel.Show(week_menu);
     ContentSource = new Uri("/Views/OverviewPage.xaml", UriKind.Relative);
     Open();
 }
Esempio n. 21
0
 public int SaveWeeklyMenu(WeeklyMenu weeklyMenu)
 {
     return(DataAccess.DBAccess.SaveWeeklyMenu(weeklyMenu));
 }
 public void Add(WeeklyMenu menu)
 {
     Context.WeeklyMenus.Add(menu);
     Context.SaveChanges();
 }
        private void LoadProfilesFromXml(string filename)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(filename);
            XmlNodeList usersNodes = xml.SelectNodes("/users/user");

            foreach (XmlElement userNode in usersNodes)
            {
                UserProfile     up = new UserProfile();
                PersonalDetails pd = new PersonalDetails();
                foreach (XmlElement detail in userNode.SelectNodes("/personaldetails/*"))
                {
                    var propertyInfo = pd.GetType().GetProperty(detail.LocalName);
                    if (propertyInfo != null)
                    {
                        propertyInfo.SetValue(pd, System.Convert.ChangeType(detail.InnerText, propertyInfo.PropertyType));
                    }
                }
                up.Details = pd;

                up.Goal = (Goal)System.Enum.Parse(typeof(Goal), userNode.SelectSingleNode("/goal").InnerText, true);

                List <Ingredient> preferences = new List <Ingredient>();
                foreach (XmlElement ingredientNode in userNode.SelectNodes("/preferences/ingredient"))
                {
                    preferences.Add(ingredientNode.InnerText);
                }
                up.Preferences = preferences;

                WeeklyMenu wm = new WeeklyMenu(userNode.SelectSingleNode("/menu").Attributes["dietCalculator"].InnerText);
                foreach (XmlElement dayNode in userNode.SelectNodes("/menu/day"))
                {
                    preferences.Add(dayNode.InnerText);
                    DailyMenu dm = wm[(System.DayOfWeek)System.Enum.Parse(typeof(System.DayOfWeek), dayNode.Attributes["day"].InnerText, true)];
                    foreach (XmlElement mealNode in dayNode.SelectNodes("/meal"))
                    {
                        string         name     = mealNode.Attributes["name"].InnerText;
                        string         hour     = mealNode.Attributes["hour"].InnerText;
                        string         minute   = mealNode.Attributes["minute"].InnerText;
                        DateTime       time     = new DateTime(2000, 1, 1, int.Parse(hour), int.Parse(minute), 0);
                        List <Serving> servings = new List <Serving>();

                        foreach (XmlElement servingNode in mealNode.SelectNodes("/serving"))
                        {
                            Dish dish = null;
                            // una ricerca migliore??
                            foreach (Dish d in _dishes)
                            {
                                if (d.Name == servingNode.Attributes["quantity"].InnerText)
                                {
                                    dish = d;
                                    break;
                                }
                            }
                            int quantity = int.Parse(servingNode.Attributes["quantity"].InnerText);
                            servings.Add(new Serving(dish, quantity));
                        }

                        NonEmptyList <Serving> nonEmpty = new NonEmptyList <Serving>(servings[0]);
                        for (int i = 1; i < servings.Count; i++)
                        {
                            nonEmpty.Add(servings[i]);
                        }
                        dm.Meals.Add(new Meal(name, time, nonEmpty));
                    }
                }
                up.Diet = wm;

                _profiles.Add(up);
            }
        }