Exemplo n.º 1
0
        public IHttpActionResult GetForUser()
        {
            var user_id   = APIUtils.GetUserFromClaim(ClaimsPrincipal.Current);
            var curr_user = UserHelper.GetById(user_id);

            using (var dc = new ArmsContext())
            {
                dc.Configuration.LazyLoadingEnabled = false;
                if (curr_user.Type == "student")
                {
                    var participations = dc.Participants.Include(x => x.Course).Include(x => x.Course.Creator)
                                         .Include(x => x.User)
                                         .Where(x => x.UserID == curr_user.UserID);
                    return(Ok(participations.ToList()));
                }

                if (curr_user.Type == "teacher")
                {
                    var supervisions = dc.Supervisors.Include(x => x.Course).Include(x => x.Course.Creator)
                                       .Include(x => x.User)
                                       .Where(x => x.UserID == curr_user.UserID);
                    return(Ok(supervisions.ToList()));
                }
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public IHttpActionResult GetParticipantAttendance(int course_id)
        {
            var user_id    = APIUtils.GetUserFromClaim(ClaimsPrincipal.Current);
            var attendance = ParticipantHelper.GetParticipantAttendance(user_id, course_id);

            return(Ok(new ApiCallbackMessage(attendance.ToString(), true)));
        }
Exemplo n.º 3
0
        public IHttpActionResult ApplyParticipant(int course_id)
        {
            var user_id = APIUtils.GetUserFromClaim(ClaimsPrincipal.Current);

            using (var dc = new ArmsContext())
            {
                //TODO: Add check if exists
                Participant part = new Participant(user_id, course_id, "pending");
                part.Insert();
                return(Ok(new ApiCallbackMessage("Success", true)));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult GetActiveLectureForTeacher()
        {
            var curr_user = UserHelper.GetById(APIUtils.GetUserFromClaim(ClaimsPrincipal.Current));

            using (var dc = new ArmsContext())
            {
                dc.Configuration.LazyLoadingEnabled = false;
                var supervisions = dc.Supervisors.Where(x => x.UserID == curr_user.UserID)
                                   .Select(x => x.CourseID).ToList();
                var active_lectures = dc.Lectures.Include(x => x.Course).FirstOrDefault(x =>
                                                                                        supervisions.Contains(x.CourseID) && x.To.CompareTo(DateTime.Now) >= 0 &&
                                                                                        x.From.CompareTo(DateTime.Now) <= 0);
                return(Ok <Lecture>(active_lectures));
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult UserAttendedLecture(int lecture_id, string bluetooth_address)
        {
            var user_id = APIUtils.GetUserFromClaim(ClaimsPrincipal.Current);

            using (var dc = new ArmsContext())
            {
                dc.Configuration.LazyLoadingEnabled = false;
                var attendance = dc.Attendees.Where(x => x.LectureID == lecture_id && x.UserID == user_id).Count();
                if (attendance == 1)
                {
                    return(Ok(new ApiCallbackMessage("Success", true)));
                }

                return(NotFound());
            }
        }
Exemplo n.º 6
0
        public IHttpActionResult IsParticipant(int course_id)
        {
            var user_id = APIUtils.GetUserFromClaim(ClaimsPrincipal.Current);

            using (var dc = new ArmsContext())
            {
                dc.Configuration.LazyLoadingEnabled = false;
                var results = dc.Participants.Count(x => x.CourseID == course_id && x.UserID == user_id);
                if (results == 1)
                {
                    return(Ok(new ApiCallbackMessage("Success", true)));
                }
                else
                {
                    return(NotFound());
                }
            }
        }
Exemplo n.º 7
0
        public IHttpActionResult UserAttend(int lecture_id, string bluetooth_address)
        {
            var user_id = APIUtils.GetUserFromClaim(ClaimsPrincipal.Current);

            using (var dc = new ArmsContext())
            {
                dc.Configuration.LazyLoadingEnabled = false;
                var existing_attendance = dc.Attendees
                                          .Where(x => x.LectureID == lecture_id && x.BluetoothAddress == bluetooth_address).Count();
                if (existing_attendance >= 1)
                {
                    return(Ok(new ApiCallbackMessage("This device was already used to check-in.", true)));
                }

                var attendace = new Attendee(user_id, lecture_id, bluetooth_address);
                attendace.Insert(BonusEnum.UpsertType.Insert);

                return(Ok(new ApiCallbackMessage("Success", true)));
            }
        }