Ejemplo n.º 1
0
        public void AddSubjectToLesson(Yw_CourseLesson lesson, int subjectId)
        {
            Yw_CourseSubjectRelation rel = Repository.GetDirectRelation(lesson.Ycl_Id, subjectId);

            if (rel == null)
            {
                SubjectBll subjectBll = new SubjectBll();
                Yw_Subject subject    = subjectBll.GetSubject(subjectId);

                rel = new Yw_CourseSubjectRelation();
                rel.Ysr_CourseId        = lesson.Ycl_CourseId;
                rel.Ysr_CreateTime      = DateTime.Now;
                rel.Ysr_DirectSubjectId = 0;
                rel.Ysr_IsDirect        = true;
                rel.Ysr_LessonId        = lesson.Ycl_Id;
                rel.Ysr_LessonIndex     = lesson.Ycl_Index;
                rel.Ysr_SubjectId       = subjectId;
                rel.Ysr_SubjectType     = subject.Ysj_SubjectType;
                Repository.Add(rel);

                SubjectGroupBll groupBll = new SubjectGroupBll();
                Yw_SubjectGroup group    = groupBll.GetBySubjectId(subjectId);
                if (group != null && !string.IsNullOrEmpty(group.Ysg_RelSubjectId))
                {
                    int[] subjectIds = group.Ysg_RelSubjectId.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
                    Repository.CreateInDirectRelation(rel.Ysr_Id, subjectIds);
                }
            }
        }
Ejemplo n.º 2
0
        public void AddRelation(int subjectId, int relationSubjectId, int currentUser)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    if (subjectId == relationSubjectId)
                    {
                        throw new AbhsException(
                                  ErrorCodeEnum.CanNotAddRelationToSelf,
                                  AbhsErrorMsg.CanNotAddRelationToSelf);
                    }

                    var subjectBll = new SubjectBll();
                    var subjects   = subjectBll.GetSubjectsByIds(
                        new List <int> {
                        subjectId, relationSubjectId
                    });
                    foreach (var subject in subjects)
                    {
                        subject.EnableAudit();
                        subject.Ysj_GroupItemCount = subject.Ysj_GroupItemCount + 1;
                        subjectBll.UpdateSubject(subject);
                    }

                    var subjectGroup = SubjectGroupRepository.GetBySubjectId(subjectId);
                    if (subjectGroup == null)
                    {
                        subjectGroup = new Yw_SubjectGroup
                        {
                            Ysg_SubjectId    = subjectId,
                            Ysg_RelSubjectId = relationSubjectId.ToString(),
                            Ysg_CreateTime   = Clock.Now,
                            Ysg_Creator      = currentUser,
                            Ysg_UpdateTime   = Clock.Now,
                            Ysg_Editor       = currentUser
                        };
                        SubjectGroupRepository.Insert(subjectGroup);
                    }
                    else
                    {
                        if (subjectGroup.Ysg_RelSubjectId.Contains(relationSubjectId.ToString()))
                        {
                            throw new AbhsException(
                                      ErrorCodeEnum.CanNotAddRelation,
                                      AbhsErrorMsg.CanNotAddRelation);
                        }
                        subjectGroup.Ysg_RelSubjectId = subjectGroup.Ysg_RelSubjectId + ","
                                                        + relationSubjectId.ToString();
                        SubjectGroupRepository.Update(subjectGroup);
                    }

                    var subjectGroup2 = SubjectGroupRepository.GetBySubjectId(relationSubjectId);
                    if (subjectGroup2 == null)
                    {
                        subjectGroup2 = new Yw_SubjectGroup
                        {
                            Ysg_SubjectId    = relationSubjectId,
                            Ysg_RelSubjectId = subjectId.ToString(),
                            Ysg_CreateTime   = Clock.Now,
                            Ysg_Creator      = currentUser,
                            Ysg_UpdateTime   = Clock.Now,
                            Ysg_Editor       = currentUser
                        };
                        SubjectGroupRepository.Insert(subjectGroup2);
                    }
                    else
                    {
                        subjectGroup2.Ysg_RelSubjectId = subjectGroup2.Ysg_RelSubjectId + ","
                                                         + subjectId.ToString();
                        SubjectGroupRepository.Update(subjectGroup2);
                    }

                    scope.Complete();
                }
                catch
                {
                    RollbackTran();
                    throw;
                }
            }
            new CourseSubjectRelBll().AddSubjectToGroup(subjectId, relationSubjectId);
        }