Beispiel #1
0
        public Goal CreateGoal(Guid UserId, Goal goal)
        {
            //_context.Goals.Add(goal);

            goal.UserId = UserId;
            User user = _context.User.FirstOrDefault(x => x.Id == UserId);

            user.Goals.Add(goal);
            _context.SaveChanges();
            return(goal);
        }
Beispiel #2
0
        public Mission AddProgress(Guid TaskId, int Minutes, Guid UserId)
        {
            Mission task = _context.Tasks
                           .FirstOrDefault(x => x.Id == TaskId);

            User user = _context.User
                        .Include(x => x.Tasks)
                        .Include(x => x.Achievements)
                        .FirstOrDefault(x => x.Id == UserId);

            int totalProgress = user.Tasks.Select(x => x.Progress).Sum();

            if (totalProgress >= 1000)
            {
                Achievement existingAchievement = user.Achievements.FirstOrDefault(x => x.Index == 9);
                if (existingAchievement == null)
                {
                    // putem sa adaugam achievement-ul
                    AddAchievement(user, 9);
                }
            }
            if (totalProgress >= 1500)
            {
                Achievement existingAchievement = user.Achievements.FirstOrDefault(x => x.Index == 11);
                if (existingAchievement == null)
                {
                    // putem sa adaugam achievement-ul
                    AddAchievement(user, 11);
                }
            }

            if (task != null)
            {
                task.Progress += Minutes;
            }
            _context.SaveChanges();
            return(task);
        }
        public ProgressOnDate AddProgress(ProgressOnDate progressOnDate)
        {
            progressOnDate.ShortDate = progressOnDate.Date.ToShortDateString();

            ProgressOnDate foundProgress = _context.ProgressOnDates.FirstOrDefault(x => x.ShortDate == progressOnDate.ShortDate);

            if (foundProgress == null)
            {
                // nu am gasit
                _context.ProgressOnDates.Add(progressOnDate);
            }
            else
            {
                // exista deja
                foundProgress.Minutes += progressOnDate.Minutes;
            }

            _context.SaveChanges();
            return(progressOnDate);
        }
Beispiel #4
0
 public void Create(User user)
 {
     _context.User.Add(user);
     _context.SaveChanges();
 }