コード例 #1
0
ファイル: CourseArrangeController.cs プロジェクト: jeryhu/bk
        //[ValidateAntiForgeryToken]
        public JsonResult AddTeacherCourseArrange(CreateTeacherCourseArrangeInput input)
        {
            var teacherCourseArrangeResult = _teacherCourseArrangeAppService.TeacherArrangeCourse(input);

            return(AbpJson(teacherCourseArrangeResult));
            //return AbpJson((teacherCourseArrange!=null&&!string.IsNullOrEmpty(teacherCourseArrange.Id))?true:false);
        }
コード例 #2
0
        private string GenerateStudentIds(CreateTeacherCourseArrangeInput input)
        {
            var students   = input.StudentId.Trim().Split(',');
            var studentIds = "";

            foreach (var stu in students)
            {
                studentIds += _studentAppService.GetStudent(new StudentInput()
                {
                    CnName = stu
                }).Id + ",";
            }
            return(studentIds.TrimEnd(','));
        }
コード例 #3
0
        private bool validDate(CreateTeacherCourseArrangeInput input)
        {
            var crossTimes = 0.0M;

            if (input.CrossWeek != null && input.CrossWeek.Value)
            {
                var lastDate = CalendarHelper.LastDayOfMonth(input.BeginTime);
                crossTimes = Math.Floor(Convert.ToDecimal((lastDate.Day - input.BeginTime.Day) / 7));
            }
            var        arranges = _teacherCourseArrangeRepository.GetAll();
            List <int> days     = new List <int>()
            {
                input.BeginTime.Day
            };

            if (crossTimes > 1)
            {
                for (int i = 1; i < crossTimes; i++)
                {
                    days.Add(input.BeginTime.AddDays(7 * i).Day);
                }
            }

            var  day  = input.BeginTime.Day;
            bool flag = true;

            foreach (var item in arranges)
            {
                if (item.BeginTime.Value != null && days.IndexOf(item.BeginTime.Value.Day) != -1)//同一天
                {
                    if ((input.BeginTime >= item.BeginTime && input.BeginTime <= item.EndTime) ||
                        (input.BeginTime <= item.BeginTime && (input.EndTime >= item.BeginTime && input.EndTime <= item.EndTime))
                        )
                    {
                        flag = false;
                    }
                }
            }
            return(flag);
        }
コード例 #4
0
        /// <summary>
        /// 排课
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool TeacherArrangeCourse(CreateTeacherCourseArrangeInput input)
        {
            Logger.Info("AddTeacherCourseArrange: " + input);
            var arrange = input.MapTo <TeacherCourseArrange>();

            arrange.StudentName = input.StudentId;
            string studentIds = GenerateStudentIds(input);

            arrange.StudentId = studentIds;
            bool result = true;

            if (!string.IsNullOrEmpty(input.Id))
            {
                result = !string.IsNullOrEmpty(_teacherCourseArrangeRepository.Update(arrange).Id);
            }
            else
            {
                arrange.Id            = IdentityCreator.NewGuid;
                arrange.ArrangeTime   = DateTime.Now;
                arrange.CreatorUserId = AbpSession.UserId.Value;
                result = validDate(input);
                if (result)
                {
                    if (input.CrossWeek != null && input.CrossWeek.Value)
                    {
                        StringBuilder builder = new StringBuilder();
                        using (var unitOfWork = _unitOfWorkManager.Begin()) //启用工作单元
                        {
                            try
                            {
                                var lastDate   = CalendarHelper.LastDayOfMonth(input.BeginTime);
                                var crossTimes = Math.Floor(Convert.ToDecimal((lastDate.Day - input.BeginTime.Day) / 7));
                                for (int i = 0; i <= crossTimes; i++)
                                {
                                    var newArrange = input.MapTo <TeacherCourseArrange>();
                                    newArrange.Id            = IdentityCreator.NewGuid;
                                    newArrange.ArrangeTime   = DateTime.Now;
                                    newArrange.CreatorUserId = AbpSession.UserId.Value;
                                    newArrange.StudentId     = studentIds;
                                    newArrange.BeginTime     = newArrange.BeginTime.Value.AddDays(7 * i);
                                    newArrange.EndTime       = newArrange.EndTime.Value.AddDays(7 * i);
                                    _teacherCourseArrangeRepository.Insert(newArrange);
                                }
                                unitOfWork.Complete(); //提交事务
                            }
                            catch (Exception ex)
                            {
                                builder.AppendLine(ex.Message);
                            }
                            result = builder.Length == 0;
                        }
                    }
                    else
                    {
                        result = !string.IsNullOrEmpty(_teacherCourseArrangeRepository.Insert(arrange).Id); //.InsertOrUpdate(arrange);
                    }
                }
            }
            //只有创建成功才发送邮件和通知
            //if (result != null&&!string.IsNullOrEmpty(result.Id))
            if (result)
            {
                var user = _userRepository.Load(input.TeacherId); //AbpSession.UserId.Valueinput.TeacherId

                //使用领域事件触发发送通知操作
                _eventBus.Trigger(new AddTeacherCourseArrangeEventData(arrange, user));
                // _notificationPublisher.Publish("安排了新的课程额", new MessageNotificationData("安排了新的课程额"), null,
                //  NotificationSeverity.Info, new[] { user.ToUserIdentifier() });
                //TODO:需要配置QQ邮箱密码
                //_smtpEmailSender.Send("*****@*****.**", task.AssignedPerson.EmailAddress, "New Todo item", message);

                //_notificationPublisher.Publish("安排了新的课程额", new MessageNotificationData(message), null,
                //    NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() });
            }
            // return result ?? new TeacherCourseArrange();
            return(result);
        }