Exemple #1
0
        public ActionResult UserCourseInfoPost(UserCourseInfo model)
        {
            UserCourseInfoService.EnableTracking();
            var info    = GetUserCourseInfo(model.Course_TC);
            var isEmpty = model.Description.IsEmpty();

            if (info == null)
            {
                if (!isEmpty)
                {
                    model.UserID = User.UserID;
                    UserCourseInfoService.InsertAndSubmit(model);
                }
            }
            else
            {
                if (isEmpty)
                {
                    UserCourseInfoService.DeleteAndSubmit(info);
                }
                else
                {
                    info.Update(model, x => x.Description);
                    UserCourseInfoService.SubmitChanges();
                }
            }

            return(OkJson());
        }
Exemple #2
0
        public GroupVM GetGroup(decimal groupID)
        {
            var group = GroupService.GetByPK(groupID);

            if (group == null)
            {
                return(null);
            }
            var            user           = AuthService.CurrentUser;
            var            sglList        = new List <StudentInGroupLecture>();
            StudentInGroup studentInGroup = null;

            if (user.GetOrDefault(x => x.IsStudent))
            {
                studentInGroup = GetSig(groupID);
                if (studentInGroup != null)
                {
                    sglList = GetSqlList(studentInGroup);
                }
            }



            var lectureOffset = 0;
            var lecturesGroup = group.IsOpenLearning
                        ? GroupService.GetByPK(group.MegaGroup_ID.Value) : group;
            var lectures   = lecturesGroup.Lectures.OrderBy(l => l.LectureDateBeg).ToList();
            var lecturesVM = lectures.Select(l => {
                var lectureHours = GetLectureHours(l);
                lectureOffset   += lectureHours;
                return(new GroupVM.LectureVM
                {
                    Lecture = l,
                    Contents = GetContent(group.Course, lectureOffset - lectureHours,
                                          lectureHours),
                    StudentLecture = sglList.FirstOrDefault(
                        sgl => sgl.Lecture_ID == l.Lecture_ID)
                });
            }).ToList();

            var groupFiles     = @group.GroupFiles.Select(g => g.UserFile).ToList();
            var groupUserFiles = groupFiles.Select(x => x.UserFileID);
            var fileList       = new FileListVM {
                Group     = group,
                Files     = groupFiles,
                UserFiles = FileVMService.GetUserFiles(null)
                            .Where(x => !groupUserFiles.Contains(x.UserFileID)).ToList()
            };
            var tests             = SiteObjectService.GetByRelationObject <Test>(group.Course).ToList();
            var testAfterComplete = new List <Test>();

            if (studentInGroup != null)
            {
                var isBegin = group.DateBeg.GetValueOrDefault() + group.TimeBeg.GetValueOrDefault().TimeOfDay <= DateTime.Now;
                if (group.Course_TC == CourseTC.DpCons && isBegin)
                {
                    testAfterComplete = TestService.CourseTests()
                                        .GetValueOrDefault(studentInGroup.Track_TC) ?? new List <Test>();
                }
                else
                {
                    testAfterComplete = TestService.CourseTests()
                                        .GetValueOrDefault(@group.Course_TC) ?? new List <Test>();
                }
            }
            var trainerUserId = group.Teacher.GetOrDefault(x =>
                                                           x.User.GetOrDefault(y => y.UserID));
            var trainerCourseInfo = UserCourseInfoService.FirstOrDefault(x =>
                                                                         x.UserID == trainerUserId && x.Course_TC == group.Course_TC)
                                    .GetOrDefault(x => x.Description);
            var sigId        = studentInGroup.GetOrDefault(x => x.StudentInGroup_ID);
            var IsCertExists = CertificateService.GetAll(x =>
                                                         x.StudentInGroup_ID == sigId).Any();
            var isUnlimit      = studentInGroup.GetOrDefault(x => x.IsUnlimit);
            var r              = GetHideVideo(studentInGroup, sglList, group);
            var hideVideo      = r.Item1;
            var hideForUnlimit = r.Item2;
            var canAccessVideo = r.Item3;


            return(new GroupVM
            {
                Group = group,
                TrainerCourseInfo = trainerCourseInfo,
                Lectures = lecturesVM,
                LastMessages = GetLastMessages(groupID),
                FileList = fileList,
                CanAccessVideo = canAccessVideo,
                Tests = tests,
                TestsAfterComplete = testAfterComplete,
                StudentInGroup = studentInGroup,
                IsCertExists = IsCertExists,
                User = user,
                HideForUnlimit = hideForUnlimit,
                HideVideo = hideVideo,
                IsUnlimit = isUnlimit,
                Progress = GetProgress(lectures, group, studentInGroup)
            });
        }
Exemple #3
0
 private UserCourseInfo GetUserCourseInfo(string courseTC)
 {
     return(UserCourseInfoService.FirstOrDefault(x => x.UserID == User.UserID &&
                                                 x.Course_TC == courseTC));
 }