public ParticipantVM GetParticipant(string dictaatName, string email)
        {
            var user = _context.Users.FirstOrDefault(u => u.Email == email);

            var session = _context.DictaatSession
                          .FirstOrDefault(d => d.DictaatDetailsId == dictaatName && d.EndedOn == null);

            var assignmentIds = getAssignmentIds(dictaatName);

            DictaatSessionUser participant = _context.DictaatSessionUser
                                             .FirstOrDefault(p => p.DictaatSessionId == session.Id && p.UserId == user.Id);

            //completed assignments
            var myAssignments = _context.AssignmentSubmissions
                                .Where(a => assignmentIds.Contains(a.AssignmentId) && a.UserId == user.Id)
                                .ToList();

            var myCompletion = myAssignments.Where(a => a.Accepted).Count();
            var myPending    = myAssignments.Where(a => !a.Accepted).Count();

            var myPoints = myAssignments.Where(a => a.Accepted).Sum(a => a.PointsRecieved);

            //count sumbissions
            double submissionCount = _context.AssignmentSubmissions
                                     .Where(a => assignmentIds.Contains(a.AssignmentId))
                                     .Count();

            var dictaatSessionId = _context.DictaatSession
                                   .FirstOrDefault(ds => ds.DictaatDetailsId == dictaatName && ds.EndedOn == null).Id;

            //count participants
            double participantCount = _context.DictaatSessionUser
                                      .Where(dsu => dsu.DictaatSessionId == dictaatSessionId).Count();

            double averageCompletion = submissionCount / participantCount;


            //completed quizes
            //not yet added, we first need to rework quizes

            return(new ParticipantVM(user)
            {
                Group = participant != null ? participant.Group : null,
                AssignmentIds = assignmentIds,
                RecievedPoints = myPoints,
                CompletedAssignments = myCompletion,
                PendingAssignments = myPending,
                AverageCompletion = averageCompletion,
                ComparedToAverage = ((myCompletion - averageCompletion) / averageCompletion) * 100
            });
        }
        /// <summary>
        /// Join the current session of a dictaat
        /// </summary>
        /// <param name="dictaatName"></param>
        /// <param name="groupName"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool Join(string dictaatName, string groupName, string userId)
        {
            var currentSession = _context.DictaatSession
                                 .Include(s => s.Participants)
                                 .FirstOrDefault(s => s.EndedOn == null && s.DictaatDetailsId == dictaatName);

            var group = _context.DictaatGroup.FirstOrDefault(dg => dg.DictaatName == dictaatName && dg.Name == groupName);

            var participant = currentSession.Participants.FirstOrDefault(p => p.UserId == userId);

            if (participant == null)
            {
                participant = new DictaatSessionUser()
                {
                    UserId = userId
                };
                currentSession.Participants.Add(participant);
            }

            participant.Group       = group != null ? group.Name : null;
            participant.DictaatName = group != null ? currentSession.DictaatDetailsId : null;
            _context.SaveChanges();
            return(true); //Joined this ditaat :D
        }
Beispiel #3
0
 public UserVM(DictaatSessionUser p) : this(p.User)
 {
 }