コード例 #1
0
        public List <int> GetProgress(ProgressDTO data)
        {
            var userId   = db.Users.FirstOrDefault(x => x.Username == data.Username).Id;
            var progress = db.Progress.FirstOrDefault(p => p.UserId == userId);
            var list     = new List <int>();

            if (progress != null)
            {
                list.Add(progress.Workouts);
                list.Add(progress.Tasks);
                list.Add(progress.Nutrition);
            }
            return(list);
        }
コード例 #2
0
        public Dictionary <string, List <int> > GetProgressOfAllUsers(ProgressDTO data)
        {
            var dict = new Dictionary <string, List <int> >();

            for (int i = 0; i < data.MyList.Count; i++)
            {
                var list     = new List <int>();
                var userId   = db.Users.FirstOrDefault(p => p.Username == data.MyList[i]).Id;
                var progress = db.Progress.FirstOrDefault(i => i.UserId == userId);
                list.Add(progress.Workouts);
                list.Add(progress.Tasks);
                list.Add(progress.Nutrition);
                dict.Add(data.MyList[i], list);
            }
            return(dict);
        }
コード例 #3
0
        public IActionResult UpdateProgressNutrition(ProgressDTO data)
        {
            var user     = db.Users.Include(x => x.Progress).FirstOrDefault(u => u.Username == data.Username);
            var progress = db.Progress.FirstOrDefault(p => p.UserId == user.Id);

            if (progress != null)
            {
                progress.Nutrition += 2;
                db.Progress.Update(progress);
            }
            var nutrition = db.Nutrition.FirstOrDefault(t => t.UserId == user.Id);

            if (nutrition != null)
            {
                db.Nutrition.Remove(nutrition);
                db.SaveChanges();
            }
            return(Ok());
        }
コード例 #4
0
        public IActionResult UpdateProgressWorkouts(ProgressDTO data)
        {
            var user     = db.Users.Include(x => x.Progress).FirstOrDefault(u => u.Username == data.Username);
            var progress = db.Progress.FirstOrDefault(p => p.UserId == user.Id);

            if (progress != null)
            {
                progress.Workouts += 2;
                db.Progress.Update(progress);
            }
            var workouts = db.TrainingProgram.FirstOrDefault(t => t.UserId == user.Id);

            if (workouts != null)
            {
                db.TrainingProgram.Remove(workouts);
                db.SaveChanges();
            }
            return(Ok());
        }
コード例 #5
0
        public IActionResult UpdateProgressTask(ProgressDTO data)
        {
            var user     = db.Users.Include(x => x.Progress).FirstOrDefault(u => u.Username == data.Username);
            var progress = db.Progress.FirstOrDefault(p => p.UserId == user.Id);

            if (progress != null)
            {
                progress.Tasks += 2;
                db.Progress.Update(progress);
            }
            var task = db.Task.FirstOrDefault(t => t.Text == data.TaskText);

            if (task != null)
            {
                db.Task.Remove(task);
                db.SaveChanges();
            }
            return(Ok());
        }