Ejemplo n.º 1
0
        public async Task <ActionResult <ClassRoomDto> > GetClassRoom(Guid ClassRoomId)
        {
            var ClassRoom = await _classRoomRepository.GetClassRoomById(ClassRoomId);

            if (ClassRoom == null)
            {
                return(NotFound());
            }
            var ClassRoomDto = _Mapper.Map <ClassRoomDto>(ClassRoom);

            return(Ok(ClassRoomDto));
        }
Ejemplo n.º 2
0
        public void Post(PostNewCourseMessageRequest body)
        {
            var areArgumentsValid = body != null &&
                                    !string.IsNullOrEmpty(body.ClassRoomId) &&
                                    !string.IsNullOrEmpty(body.Message) &&
                                    !string.IsNullOrEmpty(body.UserProfileId);

            if (!areArgumentsValid)
            {
                return;
            }

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(body.UserProfileId, body.ClassRoomId, out userprofile);

            if (!canAccessToTheClassRoom)
            {
                return;
            }

            var isTeacherAccount = userprofile.Subscriptions.First(it => it.ClassRoomId == body.ClassRoomId).Role == UserProfile.AccountRole.Teacher;

            if (!isTeacherAccount)
            {
                return;
            }

            var selectedClassRoom = _classRoomRepo.GetClassRoomById(body.ClassRoomId);

            if (selectedClassRoom == null)
            {
                return;
            }

            selectedClassRoom.Message = body.Message;
            selectedClassRoom.LastUpdatedMessageDate = _dateTime.GetCurrentTime();
            _classRoomRepo.UpsertClassRoom(selectedClassRoom);
        }
Ejemplo n.º 3
0
        public GetCommentRespond Get(string targetUserId, string requestByUserId, string classRoomId)
        {
            var noDataRespond = new GetCommentRespond {
                Comments = Enumerable.Empty <CommentInformation>()
            };
            var areArgumentsValid = !string.IsNullOrEmpty(targetUserId) && !string.IsNullOrEmpty(requestByUserId);

            if (!areArgumentsValid)
            {
                return(noDataRespond);
            }

            var userprofile = _userprofileRepo.GetUserProfileById(requestByUserId);

            if (userprofile == null)
            {
                return(noDataRespond);
            }
            var isTeacher = (bool)userprofile.Subscriptions?.Any(it => !it.DeletedDate.HasValue && it.ClassRoomId == classRoomId && it.Role == UserProfile.AccountRole.Teacher);

            var isSelftRequest = requestByUserId == targetUserId;
            var isFriend       = false;

            if (!isSelftRequest && !isTeacher)
            {
                var friends = _friendRequestRepo.GetFriendRequestByUserProfileId(requestByUserId);
                if (friends == null || !friends.Any())
                {
                    return(noDataRespond);
                }

                isFriend = friends
                           .Where(it => !it.DeletedDate.HasValue)
                           .Where(it => it.Status == FriendRequest.RelationStatus.Friend)
                           .Any(it => it.ToUserProfileId.Equals(targetUserId));

                if (!isFriend && !isSelftRequest)
                {
                    var targetUserProfile = _userprofileRepo.GetUserProfileById(targetUserId);
                    if (requestByUserId == null)
                    {
                        return(noDataRespond);
                    }

                    if (targetUserProfile.IsPrivateAccount)
                    {
                        return new GetCommentRespond {
                                   IsPrivateAccount = true
                        }
                    }
                    ;
                }
            }

            var userComments = _commentRepo.GetCommentsByUserProfileId(targetUserId, classRoomId).ToList();

            if (userComments == null || !userComments.Any())
            {
                return(noDataRespond);
            }

            var selectedClassRoom = _classRoomRepo.GetClassRoomById(classRoomId);

            if (selectedClassRoom == null)
            {
                return(noDataRespond);
            }

            var lessonIds = userComments.Select(it => it.LessonId).Distinct();

            var lessonQry = from it in selectedClassRoom.Lessons
                            where it != null
                            where lessonIds.Contains(it.id)
                            select new
            {
                LessonId        = it.id,
                LessonCatalogId = it.LessonCatalogId,
                LessonCatalog   = _lessonCatalogRepo.GetLessonCatalogById(it.LessonCatalogId)
            };
            var lessons = lessonQry.Where(it => it.LessonCatalog != null).ToList();

            var comments = userComments
                           .Where(it => lessons.Any(lesson => lesson.LessonId == it.LessonId))
                           .Select(it =>
            {
                var selectedLessonCatalog = lessons.FirstOrDefault(l => l.LessonId == it.LessonId);
                if (selectedLessonCatalog == null)
                {
                    return(null);
                }
                var order = 1;
                return(new CommentInformation
                {
                    ClassRoomId = it.ClassRoomId,
                    CreatedByUserProfileId = it.CreatedByUserProfileId,
                    CreatedDate = it.CreatedDate,
                    CreatorDisplayName = it.CreatorDisplayName,
                    CreatorImageUrl = it.CreatorImageUrl,
                    Description = it.Description,
                    id = it.id,
                    Order = order++,
                    LessonId = it.LessonId,
                    LessonWeek = selectedLessonCatalog.LessonCatalog.Order,
                    TotalDiscussions = it.Discussions.Where(dc => !dc.DeletedDate.HasValue).Count(),
                    TotalLikes = it.TotalLikes
                });
            })
                           .Where(it => it != null)
                           .OrderByDescending(it => it.LessonWeek)
                           .ThenByDescending(it => it.CreatedDate)
                           .ToList();

            var canCreateADiscussion = isFriend || isSelftRequest || isTeacher;

            return(new GetCommentRespond
            {
                IsDiscussionAvailable = canCreateADiscussion,
                Comments = comments
            });
        }

        #endregion Methods

        //// GET: api/journal
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "value1", "value2" };
        //}

        //// GET: api/journal/5
        //public string Get(int id)
        //{
        //    return "value";
        //}

        //// POST: api/journal
        //public void Post([FromBody]string value)
        //{
        //}

        //// PUT: api/journal/5
        //public void Put(int id, [FromBody]string value)
        //{
        //}

        //// DELETE: api/journal/5
        //public void Delete(int id)
        //{
        //}
    }
Ejemplo n.º 4
0
        public LessonContentRespond Get(string id, string classRoomId, string userId)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    !string.IsNullOrEmpty(classRoomId) &&
                                    !string.IsNullOrEmpty(userId);

            if (!areArgumentsValid)
            {
                return(null);
            }

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(userId, classRoomId, out userprofile);

            if (!canAccessToTheClassRoom)
            {
                return(null);
            }

            var subscription = userprofile.Subscriptions
                               .Where(it => !it.DeletedDate.HasValue)
                               .Where(it => it.ClassRoomId.Equals(classRoomId, StringComparison.CurrentCultureIgnoreCase))
                               .FirstOrDefault();

            var now = _dateTime.GetCurrentTime();
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(classRoomId, id, now);

            if (!canAccessToTheClassLesson)
            {
                return(null);
            }

            var selectedClassRoom = _classRoomRepo.GetClassRoomById(classRoomId);

            if (selectedClassRoom == null)
            {
                return(null);
            }

            var selectedLesson = selectedClassRoom.Lessons.FirstOrDefault(it => it.id.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLesson == null)
            {
                return(null);
            }

            var selectedLessonCatalog = _lessonCatalogRepo.GetLessonCatalogById(selectedLesson.LessonCatalogId);

            if (selectedLessonCatalog == null)
            {
                return(null);
            }

            var selectedUserActivity = _userActivityRepo.GetUserActivityByUserProfileIdAndClassRoomId(userId, classRoomId);

            if (selectedUserActivity == null)
            {
                return(null);
            }
            var selectedLessonActivity = selectedUserActivity.LessonActivities.FirstOrDefault(it => it.LessonId.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLessonActivity == null)
            {
                return(null);
            }

            var selectedSubscription = userprofile.Subscriptions.FirstOrDefault(it => it.ClassRoomId == classRoomId);

            if (selectedSubscription == null)
            {
                return(null);
            }
            selectedSubscription.LastActiveDate = now;
            _userprofileRepo.UpsertUserProfile(userprofile);

            var shouldUpdateSawPrimaryContent = !selectedLessonActivity.SawContentIds.Contains(selectedLessonCatalog.PrimaryContentURL);

            if (shouldUpdateSawPrimaryContent)
            {
                var sawList = selectedLessonActivity.SawContentIds.ToList();
                sawList.Add(selectedLessonCatalog.PrimaryContentURL);
                selectedLessonActivity.SawContentIds = sawList;
                _userActivityRepo.UpsertUserActivity(selectedUserActivity);
            }

            var isTeacher           = subscription.Role == UserProfile.AccountRole.Teacher;
            var isDisplayTeacherMsg = selectedUserActivity.HideClassRoomMessageDate.HasValue ?
                                      selectedClassRoom.LastUpdatedMessageDate > selectedUserActivity.HideClassRoomMessageDate.Value :
                                      true;

            return(new LessonContentRespond
            {
                Advertisments = selectedLessonCatalog.Advertisments,
                CourseCatalogId = selectedLessonCatalog.CourseCatalogId,
                CreatedDate = selectedLessonCatalog.CreatedDate,
                ExtraContentUrls = selectedLessonCatalog.ExtraContentUrls,
                FullDescription = selectedLessonCatalog.FullDescription,
                FullTeacherLessonPlan = isTeacher ? selectedLessonCatalog.FullTeacherLessonPlan : string.Empty,
                id = id,
                Order = selectedLessonCatalog.Order,
                PrimaryContentURL = selectedLessonCatalog.PrimaryContentURL,
                SemesterName = selectedLessonCatalog.SemesterName,
                ShortDescription = selectedLessonCatalog.ShortDescription,
                ShortTeacherLessonPlan = isTeacher ? selectedLessonCatalog.ShortTeacherLessonPlan : string.Empty,
                Title = selectedLessonCatalog.Title,
                UnitNo = selectedLessonCatalog.UnitNo,
                CourseMessage = isDisplayTeacherMsg ? selectedClassRoom.Message : null,
                IsTeacher = isTeacher,
                TotalLikes = selectedLesson.TotalLikes
            });
        }
Ejemplo n.º 5
0
        public IEnumerable <GetFriendListRespond> Get(string id, string classRoomId)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    !string.IsNullOrEmpty(classRoomId);

            if (!areArgumentsValid)
            {
                return(Enumerable.Empty <GetFriendListRespond>());
            }

            var canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(id, classRoomId);

            if (!canAccessToTheClassRoom)
            {
                return(Enumerable.Empty <GetFriendListRespond>());
            }

            var selectedClassRoom = _classRoomRepo.GetClassRoomById(classRoomId);
            var isClassRoomValid  = selectedClassRoom != null &&
                                    !selectedClassRoom.DeletedDate.HasValue &&
                                    !selectedClassRoom.IsPublic;

            if (!isClassRoomValid)
            {
                return(Enumerable.Empty <GetFriendListRespond>());
            }

            var allStudentsInTheClassRoom = _userprofileRepo.GetUserProfilesByClassRoomId(classRoomId)
                                            .Where(it => it.Subscriptions.Any(s => !s.DeletedDate.HasValue && s.ClassRoomId == classRoomId))
                                            .ToList();

            if (!allStudentsInTheClassRoom.Any())
            {
                return(Enumerable.Empty <GetFriendListRespond>());
            }

            var friendRequests = _friendRequestRepo.GetFriendRequestByUserProfileId(id).ToList();
            var students       = allStudentsInTheClassRoom
                                 .Where(it => it.id != id)
                                 .OrderBy(it => it.id)
                                 .Select(it =>
            {
                var isTeacher = it.Subscriptions.Where(s => !s.DeletedDate.HasValue && s.ClassRoomId == classRoomId)
                                .Any(s => s.Role == UserProfile.AccountRole.Teacher);
                var selectedRequest = friendRequests.FirstOrDefault(req => req.ToUserProfileId.Equals(it.id));
                var status          = selectedRequest == null ? FriendRequest.RelationStatus.Unfriend : selectedRequest.Status;
                var result          = new GetFriendListRespond
                {
                    UserProfileId = it.id,
                    Name          = it.Name,
                    ImageUrl      = it.ImageProfileUrl,
                    Status        = status,
                    RequestId     = selectedRequest == null ? null : selectedRequest.id,
                    IsTeacher     = isTeacher
                };
                return(result);
            })
                                 .OrderBy(it => it.Name)
                                 .ToList();

            return(students);
        }
Ejemplo n.º 6
0
        public LessonContentRespond Get(string id, string classRoomId, string userId)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    !string.IsNullOrEmpty(classRoomId) &&
                                    !string.IsNullOrEmpty(userId);

            if (!areArgumentsValid)
            {
                return(null);
            }

            UserProfile userprofile;
            var         canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(userId, classRoomId, out userprofile);

            if (!canAccessToTheClassRoom)
            {
                return(null);
            }

            var subscriptions = userprofile.Subscriptions
                                .Where(it => !it.DeletedDate.HasValue)
                                .Where(it => it.ClassRoomId.Equals(classRoomId, StringComparison.CurrentCultureIgnoreCase));

            if (!subscriptions.Any())
            {
                return(null);
            }
            var now       = _dateTime.GetCurrentTime();
            var isTeacher = subscriptions.Any(it => it.Role == UserProfile.AccountRole.Teacher);
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(classRoomId, id, now, isTeacher);

            if (!canAccessToTheClassLesson)
            {
                return(null);
            }

            var selectedClassRoom = _classRoomRepo.GetClassRoomById(classRoomId);
            var isClassRoomValid  = selectedClassRoom != null && !selectedClassRoom.DeletedDate.HasValue;

            if (!isClassRoomValid)
            {
                return(null);
            }

            var selectedLesson = selectedClassRoom.Lessons.FirstOrDefault(it => it.id.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLesson == null)
            {
                return(null);
            }

            var selectedLessonCatalog = _lessonCatalogRepo.GetLessonCatalogById(selectedLesson.LessonCatalogId);

            if (selectedLessonCatalog == null)
            {
                return(null);
            }

            var selectedUserActivity = _userActivityRepo.GetUserActivityByUserProfileIdAndClassRoomId(userId, classRoomId);
            var isUserActivityValid  = selectedUserActivity != null && !selectedUserActivity.DeletedDate.HasValue;

            if (!isUserActivityValid)
            {
                return(null);
            }
            var selectedLessonActivity = selectedUserActivity.LessonActivities.FirstOrDefault(it => it.LessonId.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (selectedLessonActivity == null)
            {
                return(null);
            }

            var selectedSubscription = userprofile.Subscriptions.FirstOrDefault(it => it.ClassRoomId == classRoomId);

            if (selectedSubscription == null)
            {
                return(null);
            }
            selectedSubscription.LastActiveDate = now;
            _userprofileRepo.UpsertUserProfile(userprofile);

            var shouldUpdateSawPrimaryContent = !selectedLessonActivity.SawContentIds.Contains(selectedLessonCatalog.id);

            if (shouldUpdateSawPrimaryContent)
            {
                var sawList = selectedLessonActivity.SawContentIds.ToList();
                sawList.Add(selectedLessonCatalog.id);
                selectedLessonActivity.SawContentIds = sawList;
                _userActivityRepo.UpsertUserActivity(selectedUserActivity);
            }

            var isDisplayTeacherMsg = selectedUserActivity.HideClassRoomMessageDate.HasValue ?
                                      selectedClassRoom.LastUpdatedMessageDate > selectedUserActivity.HideClassRoomMessageDate.Value :
                                      true;

            var result = new LessonContentRespond
            {
                id              = id,
                Order           = selectedLessonCatalog.Order,
                SemesterName    = selectedLessonCatalog.SemesterName,
                UnitNo          = selectedLessonCatalog.UnitNo,
                CourseCatalogId = selectedLessonCatalog.CourseCatalogId,
                Title           = selectedLessonCatalog.Title,
                CreatedDate     = selectedLessonCatalog.CreatedDate,
                Advertisments   = selectedLessonCatalog.Advertisments,
                CourseMessage   = isDisplayTeacherMsg ? selectedClassRoom.Message : null,
                IsTeacher       = isTeacher,
                TotalLikes      = selectedLesson.TotalLikes,
                StudentItems    = selectedLessonCatalog.StudentItems ?? Enumerable.Empty <LessonCatalog.LessonItem>(),
                TeacherItems    = selectedLessonCatalog.TeacherItems ?? Enumerable.Empty <LessonCatalog.LessonItem>(),
                PostAssessments = selectedLessonCatalog.PostAssessments ?? Enumerable.Empty <LessonCatalog.AssessmentItem>(),
                PreAssessments  = selectedLessonCatalog.PreAssessments ?? Enumerable.Empty <LessonCatalog.AssessmentItem>(),
            };

            result.StudentItems    = result.StudentItems.OrderBy(it => it.Order);
            result.TeacherItems    = result.TeacherItems.OrderBy(it => it.Order);
            result.PostAssessments = result.PostAssessments.OrderBy(it => it.Order);
            result.PreAssessments  = result.PreAssessments.OrderBy(it => it.Order);
            return(result);
        }