Exemple #1
0
        public async Task <bool> CreateSoupList(UserPlSchedulers model)
        {
            bool msg = false;



            var checkExist = await _context.UserPlScheduler.FirstOrDefaultAsync(x => x.UserId == model.UserId);

            if (checkExist == null)
            {
                var result = new UserPlSchedulers
                {
                    SoupList      = model.SoupList,
                    SoupFrequency = model.SoupFrequency,
                };
                await _context.UserPlScheduler.AddAsync(result);

                if (await _context.SaveChangesAsync() > 0)
                {
                    msg = true;
                }
            }

            return(msg);
        }
Exemple #2
0
        public async Task <List <string> > StartSoupFrequencyProcess(string userName, int item)
        {
            var postSoupFrequency = new UserPlSchedulers
            {
                SoupFrequency = item,
                UserId        = userName,
                showSF        = false
            };
            var createFoodList = await ÙpdateSoupFrequency(postSoupFrequency);

            var order = await OrderOne(userName);

            string combinedString = string.Join("|", order);

            var postSoupList = new UserPlSchedulers
            {
                SoupList = combinedString,
                UserId   = userName
            };
            var FoodList = await ÙpdateSoupList(postSoupList);

            List <string> passValue = new List <string>();

            return(passValue);
        }
Exemple #3
0
        public async Task <bool> ÙpdateSoupFrequency(UserPlSchedulers model)
        {
            var checkExist = await _context.UserPlScheduler.FirstOrDefaultAsync(x => x.UserId == model.UserId);

            if (checkExist != null)
            {
                checkExist.SoupFrequency = model.SoupFrequency;
                await _context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
Exemple #4
0
        public async Task <IActionResult> Create(DateTime dateTime)
        {
            AppUser appUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var FoodList = new UserPlSchedulers
            {
                UserId    = appUser.Id,
                StartTime = dateTime
            };
            var createStartTime = await _scheduleoperation.ÙpdateStartDateTime(FoodList);


            return(RedirectToAction("Index", "FoodSchedulerTimeStarts"));
        }
Exemple #5
0
        public async Task <bool> CreateFood(UserPlSchedulers model, string users)
        {
            var checkExist = await _context.UserPlScheduler.FirstOrDefaultAsync(x => x.UserId == model.UserId);

            if (checkExist != null)
            {
                checkExist.FoodList = model.FoodList;



                await _context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
Exemple #6
0
        public async Task <UserPlSchedulers> FetchFoodByUserId(string userId)
        {
            var model = new UserPlSchedulers();

            model = await _context.UserPlScheduler.FirstOrDefaultAsync(x => x.UserId == userId);

            if (model != null)
            {
                var result = new UserPlSchedulers
                {
                    FoodList = model.FoodList,
                    UserId   = model.UserId,
                    Id       = model.Id
                };
                return(result);
            }
            return(model);
        }
Exemple #7
0
        public async Task <bool> ÙpdateStartDateTime(UserPlSchedulers model)
        {
            bool msg = false;

            var checkExist = await _context.UserPlScheduler.FirstOrDefaultAsync(x => x.UserId == model.UserId);

            if (checkExist == null)
            {
                var result = new UserPlSchedulers
                {
                    UserId    = model.UserId,
                    StartTime = model.StartTime
                };
                await _context.UserPlScheduler.AddAsync(result);

                if (await _context.SaveChangesAsync() > 0)
                {
                    msg = true;
                }
            }

            return(msg);
        }
Exemple #8
0
        public async Task <List <string> > randomResult(UserPlSchedulers model, List <string> chosengraindish, List <string> resultgraindish)
        {
            var soupcount = _context.UserPlScheduler.Where(x => x.UserId == model.UserId).Select(x => x.SoupFrequency).ToList();

            //to group the item in the list chosen into key and value
            Dictionary <string, int> keyValues = chosengraindish.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());

            //to loop through the value gotten from keyvalue
            foreach (KeyValuePair <string, int> entry in keyValues)
            {
                //to stop the item in the list from going more than 7
                if (resultgraindish.Count < soupcount[0])
                {
                    //to check if the value of the item in the list is not grater than 2
                    if (entry.Value < 3)
                    {
                        //to add the item if it is not greater than 2
                        resultgraindish.Add(entry.Key);
                    }
                }
            }

            return(resultgraindish);
        }
        public async Task <IActionResult> DailyScheduler(string id)
        {
            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>();

            IdentityRole role = await roleManager.FindByIdAsync(id);

            List <AppUser> members    = new List <AppUser>();
            List <AppUser> nonMembers = new List <AppUser>();
            AppUser        user       = await _userManager.FindByNameAsync(User.Identity.Name);

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

            if (checkExistUserInUserPSIDb.Contains(user.Id) == false)
            {
                _toastNotification.AddErrorToastMessage("Time for when sheduling to start should be selected first");
                return(RedirectToAction("Create", "FoodSchedulerTimeStarts"));
            }
            var gettingfoodfromlightfood = await _context.UserLightFoodSelection.Where(x => x.UserId == user.Id).Select(x => x.Id).ToListAsync();

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

            var gettingfoodfromswallow = await _context.UserSwallowSelection.Where(x => x.UserId == user.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(user.Id);

            combinedlist = randomise;
            var comperuser = await _context.UserPlScheduler.Where(x => x.UserId == user.Id).Select(x => x.FoodList).ToListAsync();

            if (comperuser[0] == 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);
            }



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



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

            combinedlistsplit = newlist;



            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
            {
                var Monday = combinedlistsplit[0].Split(new char[] { '|' });
                ViewBag.dayofweek = "Monday";
                ViewBag.Monday0   = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];
            }
            if (DateTime.Now.DayOfWeek == DayOfWeek.Tuesday)
            {
                var Monday = combinedlistsplit[1].Split(new char[] { '|' });
                ViewBag.dayofweek = "Tuesday";
                ViewBag.Monday0   = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];
            }
            if (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday)
            {
                var Monday = combinedlistsplit[2].Split(new char[] { '|' });
                ViewBag.dayofweek = "Wednesday";
                ViewBag.Monday0   = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];
            }
            if (DateTime.Now.DayOfWeek == DayOfWeek.Thursday)
            {
                var Monday = combinedlistsplit[3].Split(new char[] { '|' });
                ViewBag.dayofweek = "Thursday";
                ViewBag.Monday0   = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];
            }
            if (DateTime.Now.DayOfWeek == DayOfWeek.Friday)
            {
                var Monday = combinedlistsplit[4].Split(new char[] { '|' });
                ViewBag.dayofweek = "Friday";
                ViewBag.Monday0   = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];
            }
            if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
            {
                var Monday = combinedlistsplit[5].Split(new char[] { '|' });
                ViewBag.dayofweek = "Saturday";
                ViewBag.Monday0   = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];
            }
            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                var Monday = combinedlistsplit[6].Split(new char[] { '|' });
                ViewBag.dayofweek = "Sunday";
                ViewBag.Monday0   = Monday[0]; ViewBag.Monday1 = Monday[1]; ViewBag.Monday2 = Monday[2];
            }



            return(View());
        }
        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());
            }
        }
Exemple #11
0
 public Task <bool> PostCreateSoupList(UserPlSchedulers model)
 {
     throw new NotImplementedException();
 }