Exemple #1
0
        public void Seed(ModelBuilder modelBuilder)
        {
            var userSysAdmin = User.CreateInstance(DefaultData.SysAdminId, "Ali", "Jahanbin", DefaultData.SysAdminPassword, "*****@*****.**", DefaultData.SysAdminUsername, UserRoleEnum.SysAdmin, "09224957626", LevelEnum.Intermediate, true, string.Empty);
            var userTeacher  = User.CreateInstance(DefaultData.TeacherUserId, "Ali", "Jahanbin", DefaultData.TeacherPassword, "*****@*****.**", DefaultData.TeacherUsername, UserRoleEnum.Teacher, "09224957626", LevelEnum.Advanced, true, string.Empty);
            var userStudent  = User.CreateInstance(DefaultData.StudentId, "Ali", "Jahanbin", DefaultData.SysAdminPassword, "*****@*****.**", DefaultData.SysAdminUsername, UserRoleEnum.Student, "09224957626", LevelEnum.Begginer, true, string.Empty);

            var defaultInstitute = Institute.CreateInstance(DefaultData.InstituteId, "TestInstitute", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), true, Guid.NewGuid().ToString());

            var defaultField = Field.CreateInstance(DefaultData.FieldId, "DefaultField", defaultInstitute.Id, true, string.Empty);

            var defaultCourse = Course.CreateInstance(DefaultData.CourseId, "DefaultCourse", AgeRangeEnum.Adults, defaultField.Id, true, string.Empty);

            var defaultTerm = Term.CreateInstance(DefaultData.TermId, "DefaultTerm", defaultCourse.Id, true, string.Empty);

            var defaultLessonPlan = LessonPlan.CreateInstance(DefaultData.LessonPlanId, LevelEnum.Begginer, DefaultData.SessionId, true, string.Empty);

            var defaultSession = Session.CreateInstance(DefaultData.SessionId, "DefaultSession", defaultLessonPlan.Id, defaultTerm.Id, true, string.Empty);

            var defaultPost = Post.CreateInstance(DefaultData.PostId, "DefaultPost", 1, ContentTypeEnum.Text, "Sample Content", defaultLessonPlan.Id, true, string.Empty);

            modelBuilder.Entity <Institute>().HasData(defaultInstitute);
            modelBuilder.Entity <Field>().HasData(defaultField);
            modelBuilder.Entity <Course>().HasData(defaultCourse);
            modelBuilder.Entity <Term>().HasData(defaultTerm);
            modelBuilder.Entity <LessonPlan>().HasData(defaultLessonPlan);
            modelBuilder.Entity <Session>().HasData(defaultSession);
            modelBuilder.Entity <Post>().HasData(defaultPost);
            modelBuilder.Entity <User>().HasData(userSysAdmin, userTeacher, userStudent);
        }
        public async Task <bool> Do(RegisterLessonPlanEvent message)
        {
            try
            {
                LessonPlan lessonPlan = _unitOfWork.lessonPlanRepository.Get(message.Id);
                if (lessonPlan != null)
                {
                    lessonPlan.AssignDescription(message.Description);
                    lessonPlan.AssignIsActive(message.IsActive);
                    lessonPlan.AssignIsDeleted(message.IsDeleted);
                    lessonPlan.AssignModifiedDate(DateTime.Now);
                    lessonPlan.IncreaseRowVersion();
                    lessonPlan.AssignSession(message.SessionId);
                    lessonPlan.AssignLevel(message.Level);

                    _unitOfWork.lessonPlanRepository.Update(lessonPlan);
                    await _unitOfWork.CommitAsync();

                    return(true);
                }
                LessonPlan newLessonPlan = LessonPlan.CreateInstance(null, message.Level, message.SessionId, message.IsActive, message.Description);

                await _unitOfWork.lessonPlanRepository.AddAsync(newLessonPlan);

                await _unitOfWork.CommitAsync();

                return(true);
            }
            catch (Exception)
            {
                _unitOfWork.Dispose();
                return(false);
            }
        }
        public UpdateLessonPlanResponse Update(UpdateLessonPlanRequest request)
        {
            try
            {
                request.Validate();

                var lessonPlan = LessonPlan.CreateInstance(request.Id, (LevelEnum)request.Level, request.SessionId, request.IsActive, request.Description);
                this._unitOfWork.lessonPlanRepository.Update(lessonPlan);
                this._unitOfWork.Commit();
                _busControl.Publish <RegisterLessonPlanEvent>(new RegisterLessonPlanEvent()
                {
                    Description  = "Updated in CourseManagement module",
                    Id           = lessonPlan.Id,
                    IsActive     = lessonPlan.IsActive,
                    Level        = (short)lessonPlan.Level,
                    CreateDate   = lessonPlan.CreateDate,
                    ModifiedDate = lessonPlan.ModifyDate,
                    IsDeleted    = lessonPlan.IsDeleted,
                    SessionId    = lessonPlan.SessionId
                });

                return(new UpdateLessonPlanResponse(true, "به روز رسانی با موفقیت انجام شد"));
            }
            catch (BusinessException e)
            {
                this._logger.Warning("Course Management-LessonPlan Service-Update LessonPlan ", e.Message);
                return(new UpdateLessonPlanResponse(false, "به روز رسانی با مشکل مواجه شد.", e.Message.ToString()));
            }
            catch (Exception e)
            {
                this._logger.Error("Course Management-LessonPlan Service-Update LessonPlan ", e.Message);
                return(new UpdateLessonPlanResponse(false, "به روز رسانی با مشکل مواجه شد.", e.Message.ToString()));
            }
        }
        public void Seed(ModelBuilder modelBuilder)
        {
            var defaultInstitute = Institute.CreateInstance(DefaultData.InstituteId, "TestInstitute", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), true, Guid.NewGuid().ToString());

            var defaultField = Field.CreateInstance(DefaultData.FieldId, "DefaultField", defaultInstitute.Id, true, string.Empty);

            var defaultCourse = Course.CreateInstance(DefaultData.CourseId, "DefaultCourse", AgeRangeEnum.Adults, defaultField.Id, true, string.Empty);

            var defaultTerm = Term.CreateInstance(DefaultData.TermId, "DefaultTerm", defaultCourse.Id, true, string.Empty);

            var defaultLessonPlan = LessonPlan.CreateInstance(DefaultData.LessonPlanId, LevelEnum.Begginer, DefaultData.SessionId, true, string.Empty);

            var defaultSession = Session.CreateInstance(DefaultData.SessionId, "DefaultSession", defaultLessonPlan.Id, defaultTerm.Id, true, string.Empty);

            var defaultPost = Post.CreateInstance(DefaultData.PostId, "DefaultPost", 1, ContentTypeEnum.Text, Guid.NewGuid().ToString(), defaultLessonPlan.Id, true, string.Empty);

            modelBuilder.Entity <Institute>().HasData(defaultInstitute);
            modelBuilder.Entity <Field>().HasData(defaultField);
            modelBuilder.Entity <Course>().HasData(defaultCourse);
            modelBuilder.Entity <Term>().HasData(defaultTerm);
            modelBuilder.Entity <LessonPlan>().HasData(defaultLessonPlan);
            modelBuilder.Entity <Session>().HasData(defaultSession);
            modelBuilder.Entity <Post>().HasData(defaultPost);
        }