示例#1
0
        public object GetMany(int id, int id2, int id3, int id4, int id5)
        {
            try
            {
                var quizzClassLessonId = id;
                var pageNum            = id2;
                var numPerPage         = id3;

                var quizzClass = _uow.QuizzClassLessons.GetAll()
                                 .Where(qcl => qcl.Id == quizzClassLessonId)
                                 .Select(qcl => qcl.QuizzClass)
                                 .ProjectTo <QuizzClassModel>(new { userId = _currentUser.Id })
                                 .FirstOrDefault();

                quizzClass.Member = _uow.QuizzClassMembers.GetAll()
                                    .Where(qcm => qcm.Id == quizzClass.QuizzClassMemberId)
                                    .ProjectTo <QuizzClassMemberModel>()
                                    .FirstOrDefault();

                var list = _uow.QuizzClassLessonMessages.GetAll()
                           .Where(qclm => qclm.QuizzClassLessonId == quizzClassLessonId && qclm.IsDeleted == false)
                           .OrderBy(qca => qca.PostedDate)
                           .Skip((pageNum - 1) * numPerPage)
                           .Take(numPerPage)
                           .ProjectTo <QuizzClassLessonMessageModel>(new { userId = _currentUser.Id })
                           .ToList();

                foreach (var item in list)
                {
                    item.PostedDate = item.PostedDate.ToLocalTime();
                }

                if (list.Count > 0)
                {
                    var quizzClassLessonIdx = list[0].QuizzClassLessonIdx;
                    _svcContainer.QuizzClassMemberUpdateSvc.RemoveClassLessonContent(quizzClass.Id, quizzClassLessonIdx, true);

                    var intArrayHelper = new IntArray(quizzClass.Member.NewLessonMessageCount);
                    var count          = intArrayHelper.GetAtIndex(quizzClassLessonIdx);

                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        var item = list[i];
                        item.IsNew = count-- > 0;
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(null);
            }
        }
示例#2
0
        public object Get(int id)
        {
            try
            {
                var model = _uow.QuizzClassLessons.GetAll()
                            .Where(qcl => qcl.Id == id && qcl.IsDeleted == false)
                            .ProjectTo <QuizzClassLessonModel>(new { userId = _currentUser.Id })
                            .FirstOrDefault();

                model.IsTeacher = model.TeacherId == _currentUser.Id;
                SetAge(model);
                if (model.IsTeacher)
                {
                    model.IsTeacherQuizzmate = true;
                }
                model.TeacherName     = model.IsTeacherQuizzmate ? model.TeacherFullName : model.TeacherUserName;
                model.TeacherUserName = "";
                model.TeacherFullName = "";

                model.Member = _uow.QuizzClassMembers.GetAll()
                               .Where(qcm => qcm.QuizzClassId == model.QuizzClassId && qcm.StudentId == _currentUser.Id)
                               .ProjectTo <QuizzClassMemberModel>(new { userId = _currentUser.Id })
                               .FirstOrDefault();

                if (model.Member != null)
                {
                    var intArrayHelper = new IntArray(model.Member.NewLessonMessageCount);
                    model.NewMessageCount = intArrayHelper.GetAtIndex(model.QuizzClassLesssonIdx);

                    intArrayHelper        = new IntArray(model.Member.NewLessonCommentCount);
                    model.NewCommentCount = intArrayHelper.GetAtIndex(model.QuizzClassLesssonIdx);

                    intArrayHelper      = new IntArray(model.Member.NewLessonQuizzCount);
                    model.NewQuizzCount = intArrayHelper.GetAtIndex(model.QuizzClassLesssonIdx);
                }

                return(model);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(null);
            }
        }
        public object GetMany(int id, int id2, int id3, int id4, int id5)
        {
            try
            {
                var qcLessonId = id;

                var quizzClass = _uow.QuizzClassLessons.GetAll()
                                 .Where(qcl => qcl.Id == qcLessonId)
                                 .Select(qcl => qcl.QuizzClass)
                                 .ProjectTo <QuizzClassModel>(new { userId = _currentUser.Id })
                                 .FirstOrDefault();

                quizzClass.Member = _uow.QuizzClassMembers.GetAll()
                                    .Where(qcm => qcm.Id == quizzClass.QuizzClassMemberId)
                                    .ProjectTo <QuizzClassMemberModel>()
                                    .FirstOrDefault();

                var list = _uow.QuizzClassLessonQuizzes.GetAll()
                           .Where(qcq => qcq.QuizzClassLessonId == qcLessonId)
                           .OrderBy(qcq => qcq.PostedDate)
                           .Select(qcq => qcq.Quizz)
                           .ProjectTo <QuizzOverviewModel>(new { userId = _currentUser.Id })
                           .ToList();

                foreach (var item in list)
                {
                    SetAge(item);

                    if (item.OwnerId == _currentUser.Id)
                    {
                        item.IsQuizzmate = true;
                    }

                    item.OwnerName     = item.IsQuizzmate ? item.OwnerFullName : item.OwnerUserName;
                    item.OwnerFullName = "";
                    item.OwnerUserName = "";
                }

                if (list.Count > 0)
                {
                    var quizzClassLessonIdx = _uow.QuizzClassLessons.GetAll()
                                              .Where(qcl => qcl.Id == qcLessonId && qcl.IsDeleted == false)
                                              .Select(qcl => qcl.QuizzClassLesssonIdx)
                                              .FirstOrDefault();

                    _svcContainer.QuizzClassMemberUpdateSvc.RemoveClassLessonQuizz(quizzClass.Id, quizzClassLessonIdx);

                    var intArrayHelper = new IntArray(quizzClass.Member.NewLessonQuizzCount);
                    var count          = intArrayHelper.GetAtIndex(quizzClassLessonIdx);
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        var item = list[i];
                        item.IsNew = count-- > 0;
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(null);
            }
        }
        public object GetMany(int id, int id2, int id3, int id4, int id5)
        {
            try
            {
                var quizzClassLessonId = id;
                var pageNum            = id2;
                var numPerPage         = id3;

                var quizzClass = _uow.QuizzClassLessons.GetAll()
                                 .Where(qcl => qcl.Id == quizzClassLessonId)
                                 .Select(qcl => qcl.QuizzClass)
                                 .ProjectTo <QuizzClassModel>(new { userId = _currentUser.Id })
                                 .FirstOrDefault();

                quizzClass.Member = _uow.QuizzClassMembers.GetAll()
                                    .Where(qcm => qcm.Id == quizzClass.QuizzClassMemberId)
                                    .ProjectTo <QuizzClassMemberModel>()
                                    .FirstOrDefault();

                var list = _uow.QuizzClassLessonComments.GetAll()
                           .Where(qclm => qclm.QuizzClassLessonId == quizzClassLessonId && qclm.IsDeleted == false)
                           .OrderByDescending(qca => qca.PostedDate)
                           .Skip((pageNum - 1) * numPerPage)
                           .Take(numPerPage)
                           .ProjectTo <QuizzClassLessonCommentModel>(new { userId = _currentUser.Id })
                           .ToList();

                foreach (var item in list)
                {
                    if (item.IsAuthor)
                    {
                        item.IsQuizzmate = true;
                    }
                    item.AuthorName = item.IsQuizzmate ? item.AuthorFullName : item.AuthorUserName;
                    item.PostedDate = item.PostedDate.ToLocalTime();

                    SetAge(item);
                }

                var quizzClassLessonIdx = _uow.QuizzClassLessons.GetAll()
                                          .Where(qcl => qcl.Id == quizzClassLessonId)
                                          .Select(qcl => qcl.QuizzClassLesssonIdx)
                                          .FirstOrDefault();


                var intArrayHelper = new IntArray(quizzClass.Member.NewLessonCommentCount);
                var count          = intArrayHelper.GetAtIndex(quizzClassLessonIdx);
                if (count > 0)
                {
                    _svcContainer.QuizzClassMemberUpdateSvc.RemoveClassLessonDiscussion(quizzClass.Id, quizzClassLessonIdx, count, true);
                }
                foreach (var item in list)
                {
                    item.IsNew = count-- > 0;
                }

                return(list);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(null);
            }
        }