コード例 #1
0
        //post
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Index(int item)
        {
            AppUser appUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var checkExistUserInUserPSIDb = await _context.UserPlScheduler.Select(x => x.UserId).ToListAsync();

            if (checkExistUserInUserPSIDb.Contains(appUser.Id) == false)
            {
                _toastNotification.AddErrorToastMessage("Time for when sheduling to start should be selected first");
                return(RedirectToAction("Create", "FoodSchedulerTimeStarts"));
            }
            var Check     = _context.UserPlScheduler.Where(x => x.UserId == appUser.Id).Select(x => x.SoupFrequency).ToList();
            var CheckBool = _context.UserPlScheduler.Where(x => x.UserId == appUser.Id).Select(x => x.showSF).ToList();

            if (item == 0 & CheckBool[0] == true)
            {
                return(RedirectToAction("Create", "WeeklySoupSchedule"));
            }
            if (item == 0 & CheckBool[0] == false & Check[0] == 0)
            {
                return(RedirectToAction("Create", "WeeklySoupSchedule"));
            }

            if (Check[0] == 0)
            {
                var startSoupFrquency = await _soupfrequencymanager.StartSoupFrequencyProcess(appUser.Id, item);

                var getSoupListWith = await _context.UserPlScheduler.Where(x => x.UserId == appUser.Id).Select(x => x.SoupList).ToListAsync();

                List <string> passValue = new List <string>();
                var           Monday    = getSoupListWith[0].Split(new char[] { '|' });
                foreach (var value in Monday)
                {
                    passValue.Add(value);
                }
                ViewBag.soupList1 = passValue;
            }
            var getSoupList = await _context.UserPlScheduler.Where(x => x.UserId == appUser.Id).Select(x => x.showSF).ToListAsync();

            ViewBag.showOrNotShow = getSoupList[0];

            if (Check[0] != 0)
            {
                var getFromDb = await _context.UserPlScheduler.Where(x => x.UserId == appUser.Id).Select(x => x.SoupList).ToListAsync();

                var Monday = getFromDb[0].Split(new char[] { '|' });
                ViewBag.soupList1 = Monday;
            }



            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> WeeklyScheduler()
        {
            List <string>   Checkfoodlist     = new List <string>();
            List <string>   combinedlist      = new List <string>();
            List <string>   timeresult        = new List <string>();
            List <string>   combinedlistsplit = new List <string>();
            List <DateTime> savetime          = new List <DateTime>();
            AppUser         users             = await _userManager.FindByNameAsync(User.Identity.Name);

            var gettingfoodfromlightfood = await _context.UserLightFoodSelection.Where(x => x.UserId == users.Id).Select(x => x.Id).ToListAsync();

            var gettingfoodfromgraindish = await _context.UserGrainDishSelection.Where(x => x.UserId == users.Id).Select(x => x.Id).ToListAsync();

            var gettingfoodfromswallow = await _context.UserSwallowSelection.Where(x => x.UserId == users.Id).Select(x => x.Id).ToListAsync();


            if (gettingfoodfromgraindish.Count < 4)
            {
                _toastNotification.AddErrorToastMessage("The selected grain dishes should not be less than 4");
                return(View());
            }
            if (gettingfoodfromlightfood.Count < 4)
            {
                _toastNotification.AddErrorToastMessage("The selected light food should not be less than 4");
                return(View());
            }
            if (gettingfoodfromswallow.Count < 4)
            {
                _toastNotification.AddErrorToastMessage("The selected swallow should not be less than 4");
                return(View());
            }
            var randomise = await _scheduleManager.OrderOne(users.Id);

            combinedlist = randomise;

            var Check = await _context.UserPlScheduler.Where
                        (
                x => x.UserId == users.Id
                        ).Select(x => x.SoupFrequency
                                 ).ToListAsync();

            var comperuser = await _scheduleoperation.FetchFoodByTime(users.Id);

            if (comperuser.FoodList == null)
            {
                string combinedFoodList =
                    (combinedlist[0] + "#" + combinedlist[1] + "#" + combinedlist[2] + "#" + combinedlist[3] + "#" + combinedlist[4] + "#" + combinedlist[5] + "#" + combinedlist[6]);

                AppUser user = await _userManager.FindByNameAsync(User.Identity.Name);

                var starttime = await _context.FoodSchedulerTimeStarts.ToListAsync();

                foreach (var item in starttime)
                {
                    savetime.Add(item.Name.Date);
                }
                DateTime t        = savetime[0];
                var      FoodList = new UserPlSchedulers
                {
                    FoodList  = combinedFoodList,
                    UserId    = user.Id,
                    StartTime = t
                };
                var createFoodList = await _scheduleoperation.CreateFood(FoodList, user.Id);

                var newlist = await _scheduleManager.SplitFoodList(user.Id);

                combinedlistsplit = newlist;


                var Monday    = combinedlistsplit[0].Split(new char[] { '|' });
                var Tuesday   = combinedlistsplit[1].Split(new char[] { '|' });
                var Wednesday = combinedlistsplit[2].Split(new char[] { '|' });
                var Thursday  = combinedlistsplit[3].Split(new char[] { '|' });
                var Friday    = combinedlistsplit[4].Split(new char[] { '|' });
                var Saturday  = combinedlistsplit[5].Split(new char[] { '|' });
                var Sunday    = combinedlistsplit[6].Split(new char[] { '|' });


                ViewBag.Monday0 = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];

                ViewBag.Tuesday0 = Tuesday[0]; ViewBag.Tuesday1 = Tuesday[1]; ViewBag.Tuesday2 = Tuesday[2];

                ViewBag.Wednesday0 = Wednesday[0]; ViewBag.Wednesday1 = Wednesday[1]; ViewBag.Wednesday2 = Wednesday[2];

                ViewBag.Thursday0 = Thursday[0]; ViewBag.Thursday1 = Thursday[1]; ViewBag.Thursday2 = Thursday[2];

                ViewBag.Friday0 = Friday[0]; ViewBag.Friday1 = Friday[1]; ViewBag.Friday2 = Friday[2];

                ViewBag.Saturday0 = Saturday[0]; ViewBag.Saturday1 = Saturday[1]; ViewBag.Saturday2 = Saturday[2];

                ViewBag.Sunday0 = Sunday[0]; ViewBag.Sunday1 = Sunday[1]; ViewBag.Sunday2 = Sunday[2];

                return(View());
            }

            var time = await _scheduleManager.ComperTime(User.Identity.Name);



            timeresult = time;
            var timecheck = timeresult[0].Split(new char[] { '|' });


            var databasetime = timecheck[0]; var presenttime = timecheck[1];



            DateTime intdatabasetime = DateTime.Parse(databasetime);
            DateTime intpresenttime  = DateTime.Parse(presenttime);


            if (intdatabasetime < intpresenttime)
            {
                var timeupdate = DateTime.Now;

                var FoodList = new UserPlSchedulers
                {
                    StartTime = timeupdate,
                };
                var updateFoodList = await _scheduleoperation.ÙpdateFood(FoodList);
            }

            if (databasetime == presenttime)
            {
                var startSoupFrquency = await _soupfrequencymanager.StartSoupFrequencyProcess(users.Id, Check[0]);

                string combinedFoodList =
                    (combinedlist[0] + "#" + combinedlist[1] + "#" + combinedlist[2] + "#" + combinedlist[3] + "#" + combinedlist[4] + "#" + combinedlist[5] + "#" + combinedlist[6]);

                //var user = _userManager.FindByNameAsync(User.Identity.Name);


                var timeupdate = intdatabasetime.AddDays(6);

                var FoodList = new UserPlSchedulers
                {
                    FoodList  = combinedFoodList,
                    StartTime = timeupdate,
                    showSF    = true
                };
                var updateFoodList = await _scheduleoperation.ÙpdateFood(FoodList);

                var newlist = await _scheduleManager.SplitFoodList(User.Identity.Name);

                combinedlistsplit = newlist;


                var Monday    = combinedlistsplit[0].Split(new char[] { '|' });
                var Tuesday   = combinedlistsplit[1].Split(new char[] { '|' });
                var Wednesday = combinedlistsplit[2].Split(new char[] { '|' });
                var Thursday  = combinedlistsplit[3].Split(new char[] { '|' });
                var Friday    = combinedlistsplit[4].Split(new char[] { '|' });
                var Saturday  = combinedlistsplit[5].Split(new char[] { '|' });
                var Sunday    = combinedlistsplit[6].Split(new char[] { '|' });


                ViewBag.Monday0 = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];

                ViewBag.Tuesday0 = Tuesday[0]; ViewBag.Tuesday1 = Tuesday[1]; ViewBag.Tuesday2 = Tuesday[2];

                ViewBag.Wednesday0 = Wednesday[0]; ViewBag.Wednesday1 = Wednesday[1]; ViewBag.Wednesday2 = Wednesday[2];

                ViewBag.Thursday0 = Thursday[0]; ViewBag.Thursday1 = Thursday[1]; ViewBag.Thursday2 = Thursday[2];

                ViewBag.Friday0 = Friday[0]; ViewBag.Friday1 = Friday[1]; ViewBag.Friday2 = Friday[2];

                ViewBag.Saturday0 = Saturday[0]; ViewBag.Saturday1 = Saturday[1]; ViewBag.Saturday2 = Saturday[2];

                ViewBag.Sunday0 = Sunday[0]; ViewBag.Sunday1 = Sunday[1]; ViewBag.Sunday2 = Sunday[2];
            }
            else
            {
                AppUser user = await _userManager.FindByNameAsync(User.Identity.Name);

                var newlist = await _scheduleManager.SplitFoodList(user.Id);

                combinedlistsplit = newlist;


                var Monday    = combinedlistsplit[0].Split(new char[] { '|' });
                var Tuesday   = combinedlistsplit[1].Split(new char[] { '|' });
                var Wednesday = combinedlistsplit[2].Split(new char[] { '|' });
                var Thursday  = combinedlistsplit[3].Split(new char[] { '|' });
                var Friday    = combinedlistsplit[4].Split(new char[] { '|' });
                var Saturday  = combinedlistsplit[5].Split(new char[] { '|' });
                var Sunday    = combinedlistsplit[6].Split(new char[] { '|' });


                ViewBag.Monday0 = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];

                ViewBag.Tuesday0 = Tuesday[0]; ViewBag.Tuesday1 = Tuesday[1]; ViewBag.Tuesday2 = Tuesday[2];

                ViewBag.Wednesday0 = Wednesday[0]; ViewBag.Wednesday1 = Wednesday[1]; ViewBag.Wednesday2 = Wednesday[2];

                ViewBag.Thursday0 = Thursday[0]; ViewBag.Thursday1 = Thursday[1]; ViewBag.Thursday2 = Thursday[2];

                ViewBag.Friday0 = Friday[0]; ViewBag.Friday1 = Friday[1]; ViewBag.Friday2 = Friday[2];

                ViewBag.Saturday0 = Saturday[0]; ViewBag.Saturday1 = Saturday[1]; ViewBag.Saturday2 = Saturday[2];

                ViewBag.Sunday0 = Sunday[0]; ViewBag.Sunday1 = Sunday[1]; ViewBag.S3unday2 = Sunday[2];
            }


            {
                return(View());
            }
        }