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()); }
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))); }
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))); } }
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)); } }
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()); } }
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()); } } }
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))); } }