示例#1
0
        private static List <string> GetUUIDs(NweekMenu weekmenu, DateTime time, string type)
        {
            var           week  = time.DayOfWeek;
            List <string> uuids = new List <string>();

            if (weekmenu == null)
            {
                return(uuids);
            }
            string sids = "";

            switch (week)
            {
            case DayOfWeek.Monday:
                if (type == "morn")
                {
                    sids = weekmenu.MonMon;
                }
                else if (type == "noon")
                {
                    sids = weekmenu.MonNoon;
                }
                else if (type == "night")
                {
                    sids = weekmenu.MonNight;
                }
                break;

            case DayOfWeek.Tuesday:
                if (type == "morn")
                {
                    sids = weekmenu.TuesMon;
                }
                else if (type == "noon")
                {
                    sids = weekmenu.TuesNoon;
                }
                else if (type == "night")
                {
                    sids = weekmenu.TuesNight;
                }
                break;

            case DayOfWeek.Wednesday:
                if (type == "morn")
                {
                    sids = weekmenu.WedMon;
                }
                else if (type == "noon")
                {
                    sids = weekmenu.WedNoon;
                }
                else if (type == "night")
                {
                    sids = weekmenu.WedNight;
                }
                break;

            case DayOfWeek.Thursday:
                if (type == "morn")
                {
                    sids = weekmenu.ThursMon;
                }
                else if (type == "noon")
                {
                    sids = weekmenu.ThursNoon;
                }
                else if (type == "night")
                {
                    sids = weekmenu.ThursNight;
                }
                break;

            case DayOfWeek.Friday:
                if (type == "morn")
                {
                    sids = weekmenu.FriMon;
                }
                else if (type == "noon")
                {
                    sids = weekmenu.FriNoon;
                }
                else if (type == "night")
                {
                    sids = weekmenu.FriNight;
                }
                break;

            case DayOfWeek.Saturday:
                if (type == "morn")
                {
                    sids = weekmenu.SatMon;
                }
                else if (type == "noon")
                {
                    sids = weekmenu.SatNoon;
                }
                else if (type == "night")
                {
                    sids = weekmenu.SatNight;
                }
                break;

            case DayOfWeek.Sunday:
                if (type == "morn")
                {
                    sids = weekmenu.SunMon;
                }
                else if (type == "noon")
                {
                    sids = weekmenu.SunNoon;
                }
                else if (type == "night")
                {
                    sids = weekmenu.SunNight;
                }
                break;

            default:
                break;
            }
            uuids = sids.ToUpper().Split(',').ToList();
            return(uuids);
        }
示例#2
0
        public IActionResult ToSync()
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var schoollist = _dbContext.School.Where(x => x.IsDelete == 0).ToList();
                var schoolEnt  = schoollist.Find(x => x.SchoolName == "萧山三中");
                //var schoolEnt = schoollist.Find(x => x.SchoolName == "xxxx1");
                schoollist.Remove(schoolEnt);
                var ingredients = _dbContext.Ingredient.Where(x => x.SchoolUuid == schoolEnt.SchoolUuid && x.IsDelete == 0).ToList();
                for (int n = 0; n < schoollist.Count; n++)
                {
                    for (int i = 0; i < ingredients.Count; i++)
                    {
                        if (!_dbContext.Ingredient.Any(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && x.FoodName == ingredients[i].FoodName))
                        {
                            var ing = new Entities.Ingredient()
                            {
                                IngredientUuid = Guid.NewGuid(),
                                SchoolUuid     = schoollist[n].SchoolUuid,
                                AddTime        = DateTime.Now.ToString("yyyy-MM-dd"),
                                AddPeople      = "",
                                FoodName       = ingredients[i].FoodName,
                                TypeUuid       = ingredients[i].TypeUuid,
                                IsDelete       = 0,
                                HeatEnergy     = ingredients[i].HeatEnergy,
                                Protein        = ingredients[i].Protein,
                                Fat            = ingredients[i].Fat,
                                Va             = ingredients[i].Va,
                                Saccharides    = ingredients[i].Saccharides,
                                Accessory      = ingredients[i].Accessory,
                            };


                            _dbContext.Ingredient.Add(ing);
                        }
                    }
                    //_dbContext.Ingredient.AddRange(ingredients);
                    _dbContext.SaveChanges();
                }
                var cuisines = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoolEnt.SchoolUuid && x.IsDelete == 0).ToList();
                for (int n = 0; n < schoollist.Count; n++)
                {
                    for (int i = 0; i < cuisines.Count; i++)
                    {
                        if (!_dbContext.Cuisine.Any(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && x.CuisineName == cuisines[i].CuisineName))
                        {
                            var cui = new Entities.Cuisine()
                            {
                                CuisineUuid = Guid.NewGuid(),
                                SchoolUuid  = schoollist[n].SchoolUuid,
                                AddTime     = DateTime.Now.ToString("yyyy-MM-dd"),
                                AddPeople   = "",
                                LikeNum     = 0,
                                IsDelete    = 0,
                                CuisineName = cuisines[i].CuisineName,
                                Price       = cuisines[i].Price,
                                Burdening   = cuisines[i].Burdening,
                                Ingredient  = cuisines[i].Ingredient,
                                Abstract    = cuisines[i].Abstract,
                                CuisineType = cuisines[i].CuisineType,
                                Accessory   = cuisines[i].Accessory,
                            };



                            _dbContext.Cuisine.Add(cui);
                        }
                    }
                    //_dbContext.Cuisine.AddRange(cuisines);
                    _dbContext.SaveChanges();
                }
                var nweekmenus = _dbContext.NweekMenu.Where(x => x.SchoolUuid == schoolEnt.SchoolUuid && x.IsDelete == 0).OrderByDescending(x => x.Datetimes).Take(3).ToList();
                for (int n = 0; n < schoollist.Count; n++)
                {
                    for (int i = 0; i < nweekmenus.Count; i++)
                    {
                        if (!_dbContext.NweekMenu.Any(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.Datetimes == nweekmenus[0].Datetimes && x.IsDelete == 0))
                        {
                            var ids1     = nweekmenus[i].MonMon.ToLower().Split(',');
                            var names1   = _dbContext.Cuisine.Where(x => ids1.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var MonMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names1
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var MonMon = string.Join(",", MonMonLs);

                            var ids2      = nweekmenus[i].MonNoon.ToLower().Split(',');
                            var names2    = _dbContext.Cuisine.Where(x => ids2.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var MonNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names2
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var MonNoon = string.Join(",", MonNoonLs);

                            var ids3       = nweekmenus[i].MonNight.ToLower().Split(',');
                            var names3     = _dbContext.Cuisine.Where(x => ids3.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var MonNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names3
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var MonNight = string.Join(",", MonNightLs);

                            var ids4      = nweekmenus[i].TuesMon.ToLower().Split(',');
                            var names4    = _dbContext.Cuisine.Where(x => ids4.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var TuesMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names4
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var TuesMon = string.Join(",", TuesMonLs);

                            var ids5       = nweekmenus[i].TuesNoon.ToLower().Split(',');
                            var names5     = _dbContext.Cuisine.Where(x => ids5.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var TuesNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names5
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var TuesNoon = string.Join(",", TuesNoonLs);

                            var ids6        = nweekmenus[i].TuesNight.ToLower().Split(',');
                            var names6      = _dbContext.Cuisine.Where(x => ids6.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var TuesNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names6
                                                                       .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var TuesNight = string.Join(",", TuesNightLs);

                            var ids7     = nweekmenus[i].WedMon.ToLower().Split(',');
                            var names7   = _dbContext.Cuisine.Where(x => ids7.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var WedMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names7
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var WedMon = string.Join(",", WedMonLs);

                            var ids8      = nweekmenus[i].WedNoon.ToLower().Split(',');
                            var names8    = _dbContext.Cuisine.Where(x => ids8.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var WedNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names8
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var WedNoon = string.Join(",", WedNoonLs);

                            var ids9       = nweekmenus[i].WedNight.ToLower().Split(',');
                            var names9     = _dbContext.Cuisine.Where(x => ids9.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var WedNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names9
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var WedNight = string.Join(",", WedNightLs);

                            var ids10      = nweekmenus[i].ThursMon.ToLower().Split(',');
                            var names10    = _dbContext.Cuisine.Where(x => ids10.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var ThursMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names10
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var ThursMon = string.Join(",", ThursMonLs);

                            var ids11       = nweekmenus[i].ThursNoon.ToLower().Split(',');
                            var names11     = _dbContext.Cuisine.Where(x => ids11.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var ThursNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names11
                                                                       .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var ThursNoon = string.Join(",", ThursNoonLs);

                            var ids12        = nweekmenus[i].ThursNight.ToLower().Split(',');
                            var names12      = _dbContext.Cuisine.Where(x => ids12.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var ThursNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names12
                                                                        .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var ThursNight = string.Join(",", ThursNightLs);

                            var ids13    = nweekmenus[i].FriMon.ToLower().Split(',');
                            var names13  = _dbContext.Cuisine.Where(x => ids13.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var FriMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names13
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var FriMon = string.Join(",", FriMonLs);

                            var ids14     = nweekmenus[i].FriNoon.ToLower().Split(',');
                            var names14   = _dbContext.Cuisine.Where(x => ids14.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var FriNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names14
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var FriNoon = string.Join(",", FriNoonLs);

                            var ids15      = nweekmenus[i].FriNight.ToLower().Split(',');
                            var names15    = _dbContext.Cuisine.Where(x => ids15.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var FriNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names15
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var FriNight = string.Join(",", FriNightLs);

                            var ids16    = nweekmenus[i].SatMon.ToLower().Split(',');
                            var names16  = _dbContext.Cuisine.Where(x => ids16.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SatMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names16
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SatMon = string.Join(",", SatMonLs);

                            var ids17     = nweekmenus[i].SatNoon.ToLower().Split(',');
                            var names17   = _dbContext.Cuisine.Where(x => ids17.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SatNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names17
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SatNoon = string.Join(",", SatNoonLs);

                            var ids18      = nweekmenus[i].SatNight.ToLower().Split(',');
                            var names18    = _dbContext.Cuisine.Where(x => ids18.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SatNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names18
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SatNight = string.Join(",", SatNightLs);

                            var ids19    = nweekmenus[i].SunMon.ToLower().Split(',');
                            var names19  = _dbContext.Cuisine.Where(x => ids19.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SunMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names19
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SunMon = string.Join(",", SunMonLs);

                            var ids20     = nweekmenus[i].SunNoon.ToLower().Split(',');
                            var names20   = _dbContext.Cuisine.Where(x => ids20.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SunNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names20
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SunNoon = string.Join(",", SunNoonLs);

                            var ids21      = nweekmenus[i].SunNight.ToLower().Split(',');
                            var names21    = _dbContext.Cuisine.Where(x => ids21.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SunNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names21
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SunNight = string.Join(",", SunNightLs);

                            var menu = new NweekMenu()
                            {
                                NweekMenuUuid = Guid.NewGuid(),
                                SchoolUuid    = schoollist[n].SchoolUuid,
                                MonMon        = MonMon,
                                MonNight      = MonNight,
                                MonNoon       = MonNoon,
                                TuesMon       = TuesMon,
                                TuesNight     = TuesNight,
                                TuesNoon      = TuesNoon,
                                WedMon        = WedMon,
                                WedNight      = WedNight,
                                WedNoon       = WedNoon,
                                ThursMon      = ThursMon,
                                ThursNight    = ThursNight,
                                ThursNoon     = ThursNoon,
                                FriMon        = FriMon,
                                FriNight      = FriNight,
                                FriNoon       = FriNoon,
                                SatMon        = SatMon,
                                SatNight      = SatNight,
                                SatNoon       = SatNoon,
                                SunMon        = SunMon,
                                SunNight      = SunNight,
                                SunNoon       = SunNoon,
                                AddTime       = DateTime.Now.ToString("yyyy-MM-dd"),
                                AddPeople     = "",
                                IsDelete      = 0,
                                Datetimes     = nweekmenus[0].Datetimes,
                            };

                            _dbContext.NweekMenu.Add(menu);
                        }
                    }
                    _dbContext.SaveChanges();
                }
            }
            return(Ok(response));
        }