Ejemplo n.º 1
0
        /// <summary>
        /// 作者:Kylin
        /// 时间:2014.06.20
        /// 描述:更新用户计划标注
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdateUserSchedule(UserSchedule model)
        {
            using (var edb = new EmeEntities())
            {
                try
                {
                    if (model != null)
                    {
                        var userScheduleModel = edb.UserSchedule.SingleOrDefault(p => p.Id == model.Id);
                        if (userScheduleModel != null)
                        {
                            userScheduleModel.ScheduleType = model.ScheduleType;
                            userScheduleModel.UpdateTime = DateTime.Now;

                            edb.Entry(userScheduleModel).State = EntityState.Modified;
                            return edb.SaveChanges() > 0;
                        }
                    }
                }
                catch (Exception e)
                {
                    // 异常日志消息队列
                    Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                    {
                        ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                        Message =
                            string.Format("UserBLL-UpdateUserSchedule:{0};{1};{2}", e.Message,
                                e.InnerException.Message, e.HelpLink),
                        IsTreat = false,
                        CreateTime = DateTime.Now
                    });
                }
                return false;
            }
        }
Ejemplo n.º 2
0
 public JsonResult CreateTeacherSchedule(UserSchedule model)
 {
     var result = false;
     result = model.Id > 0 ? UserBLL.UpdateUserSchedule(model) : UserBLL.CreateUserSchedule(model);
     return Json(new { status = result });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 作者:Kylin
        /// 时间:2014.06.20
        /// 描述:添加用户计划标注
        /// Update Date :2014.08.23
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool CreateUserSchedule(UserSchedule model)
        {
            if (model != null)
            {
                // Step1.验证教师是否已存在相同时间段日程
                if (IsExistUserScheduleByUserId(model.UserId, model.BeginTime, model.EndTime))
                {
                    return false;
                }
            }

            using (var tran = new TransactionScope(TransactionScopeOption.Required))
            {
                using (var edb = new EmeEntities())
                {
                    try
                    {
                        if (model != null)
                        {
                            // Step2.添加user schedule
                            model.Status = ConvertEnum.StatusTypeForActive;
                            model.CreateTime = DateTime.Now;
                            edb.Entry(model).State = EntityState.Added;

                            var teacherModel = edb.Teacher.SingleOrDefault(p => p.UserId == model.UserId && p.Status == ConvertEnum.StatusTypeForActive);
                            if (teacherModel != null)
                            {
                                if (teacherModel.IsFullTime) //when teacher is fulltime then do
                                {
                                    //Step3.更新老师的排班任务量(听课不计工作量)
                                    if (model.ScheduleType != ConvertEnum.ScheduleTypeForObservation)
                                    {
                                        var userWorktime =
                                            edb.UserWorkTime.FirstOrDefault(
                                                p =>
                                                    p.WorkDate == model.BeginTime.Date && p.UserId == model.UserId &&
                                                    p.Status == ConvertEnum.StatusTypeForActive);

                                        if (userWorktime != null && userWorktime.CurrentTaskNum < userWorktime.MaxTaskNum)
                                        {
                                            userWorktime.CurrentTaskNum++;
                                            edb.Entry(userWorktime).State = EntityState.Modified;
                                        }
                                        else
                                        {
                                            return false; //when userWorktime.CurrentTaskNum > userWorktime.MaxTaskNum return false
                                        }
                                    }
                                }
                                else
                                {
                                    var teachRequeire = edb.TeachRequirement.Where(
                                          p => p.TeachEndTime == model.BeginTime
                                              && p.TeachEndTime == model.EndTime
                                              && p.TeacherId == teacherModel.Id
                                              && p.Status == ConvertEnum.StatusTypeForActive);
                                    foreach (var teachRequirement in teachRequeire)
                                    {
                                        teachRequirement.IsSuccessful = true;
                                        teachRequirement.UpdateTime = DateTime.Now;
                                        edb.Entry(teachRequirement).State = EntityState.Modified;
                                    }
                                }
                            }

                            edb.SaveChanges(); // 下面要用到 Model.Id

                            //Step4. create user task
                            var scheduleTypeStr = model.ScheduleType.ToString(CultureInfo.InvariantCulture);
                            if (BaseEnum.EmeEnum<ScheduleType>.GetEnumEnumerator("Scode").Any(p => p.Value.Equals(scheduleTypeStr)))
                            {
                                var scheduleTypeItemEname = BaseEnum.EmeEnum<ScheduleType>.GetEnameByValue(model.ScheduleType);
                                var taskType = BaseEnum.EmeEnum<TaskType>.GetEnumEnumerator("Ename").Single(p => p.Text == scheduleTypeItemEname);
                                var taskNum = BaseEnum.EmeEnum<ScheduleType>.GetEnumEnumerator("Ename")
                                    .Any(p => !p.Value.Equals(taskType.Text)) ? 1 : 0;

                                var userTaskModel = new UserTask()
                                {
                                    IsSystem = true,
                                    IsComplete = false,
                                    Status = ConvertEnum.StatusTypeForActive,
                                    BeginTime = DateTime.Now,
                                    EndTime = DateTime.Now,
                                    TaskValue = model.Id,
                                    TaskNum = taskNum,
                                    TaskType = CommonHelper.To<int>(taskType.Value),
                                    CreateBy = model.UserId,
                                    CreateTime = DateTime.Now,
                                    UserId = model.UserId
                                };
                                edb.Entry(userTaskModel).State = EntityState.Added;
                            }

                        }
                        else
                        {
                            tran.Dispose();
                            return false;
                        }

                        var result = edb.SaveChanges() > 0;
                        tran.Complete();
                        return result;
                    }
                    catch (Exception e)
                    {
                        tran.Dispose();
                        // 异常日志消息队列
                        Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                        {
                            ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                            Message =
                                string.Format("UserBLL-CreateUserSchedule:{0};{1};{2}", e.Message,
                                    e.InnerException.Message, e.HelpLink),
                            IsTreat = false,
                            //CreateBy = model.UpdateBy,
                            CreateTime = DateTime.Now
                        });
                        return false;
                    }
                }
            }
        }