/// <summary>
        /// 保存修改教案
        /// </summary>
        /// <param name="data"></param>
        /// <param name="classId"></param>
        /// <returns></returns>
        public JsonResult SaveClassCourse(string data, int classId)
        {
            try
            {
                var dataList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Tr_TrainClassToCourse> >(data);
                if (dataList.Any())
                {
                    _classManager.BatchDeleteCourse(classId);
                    foreach (var course in dataList)
                    {
                        course.Code         = "wxdewco" + DateTime.Now.ToString("yyyyMMddHHmmss");
                        course.CreateUserID = CurrentUser.UserId;
                        course.CreateTime   = DateTime.Now;
                        course.OrderTime    = DateTime.Now;
                        _classManager.AddTrainClassToCourse(course);
                        var contents = new List <Tr_TrainClassToCouseContent>();
                        var checks   = new List <Tr_TrainClassToCouseCheck>();
                        foreach (var content in course.contentLsit)
                        {
                            content.CourseId = course.ID;
                            contents.Add(content);
                        }
                        foreach (var check in course.checkLsit)
                        {
                            check.CourseId = course.ID;
                            checks.Add(check);
                        }

                        _classManager.AddTrainClassToCourseContentS(contents);
                        _classManager.AddTrainClassToCourseCheckS(checks);
                        SendWanShan(course.CourseId);
                    }
                }
                return(Json(new { result = 1, content = "保存成功" }, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(new { result = 0, content = "保存失败" }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        /// <summary>
        /// 课程、考试、实践考评一起保存
        /// </summary>
        /// <returns></returns>
        public JsonResult SaveCourseExamPract(int classId, string courseData, string examData, string practData)
        {
            try
            {
                using (TransactionScope tran = new TransactionScope())
                {
                    #region == 保存课程信息 ==
                    var dataList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Tr_TrainClassToCourse> >(courseData);
                    var addList  = new List <int>();
                    if (dataList.Any())
                    {
                        _classManager.BatchDeleteCourse(classId);
                        foreach (var course in dataList)
                        {
                            course.Code = "wxdewco" + DateTime.Now.ToString("yyyyMMddHHmmss");
                            if (course.CourseType == 1)
                            {
                                course.CourseId = 0;
                                course.PlanType = 1;
                            }
                            course.CreateUserID = CurrentUser.UserId;
                            course.CreateTime   = DateTime.Now;
                            course.OrderTime    = DateTime.Now;
                            _classManager.AddTrainClassToCourse(course);
                            var contents = new List <Tr_TrainClassToCouseContent>();
                            var checks   = new List <Tr_TrainClassToCouseCheck>();
                            var resource = new List <Tr_TrainClassToCourseResource>();

                            if (course.IsSend == 1)
                            {
                                addList.Add(course.ID);
                            }

                            foreach (var content in course.contentLsit)
                            {
                                content.CourseId = course.ID;
                                contents.Add(content);
                            }
                            foreach (var check in course.checkLsit)
                            {
                                check.CourseId = course.ID;
                                checks.Add(check);
                            }
                            foreach (var res in course.resourceLsit)
                            {
                                res.ClassCourseId = course.ID;
                                resource.Add(res);
                            }
                            _classManager.BatchDeleteCourseResource(course.ID);
                            _classManager.AddTrainClassToCourseResourceS(resource);
                            _classManager.AddTrainClassToCourseContentS(contents);
                            _classManager.AddTrainClassToCourseCheckS(checks);
                        }
                    }
                    #endregion

                    #region == 保存考试信息 ==
                    var examDataList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Tr_TrainClassToExam> >(examData);
                    if (examDataList.Any())
                    {
                        _classManager.BatchDeleteTrainClassToExam(classId);
                        foreach (var exam in examDataList)
                        {
                            var timespan = (int)(exam.EndTime - exam.StartTime).TotalMinutes;
                            if (timespan < exam.ExamLength)
                            {
                                return(Json(new { result = 3, content = LanguageResources.Exam.Examination.String3 },
                                            JsonRequestBehavior.DenyGet));
                            }

                            if (exam.ExamType == 1)
                            {
                                exam.ExamID = 0;
                            }

                            if (exam.ExamType == 0)
                            {
                                tbExamination exammodel = new tbExamination();
                                exammodel.PaperID          = exam.PaperID;
                                exammodel.ScoreOpenFlag    = 0;
                                exammodel.ApprovalUser     = exam.ApprovalUser;
                                exammodel.ExamBeginTime    = exam.StartTime;
                                exammodel.ExamEndTime      = exam.EndTime;
                                exammodel.ExaminationTitle = exam.ExamTitle;
                                exammodel.ExamLength       = exam.ExamLength;
                                exammodel.PassScore        = exam.PassScore;
                                exammodel.PercentFlag      = 0;
                                exammodel.PublishedFlag    = 0;
                                exammodel.RadomOrderFlag   = exam.RadomOrderFlag;
                                exammodel.ShowType         = 0;
                                exammodel.TestTimes        = exam.TestTimes;
                                exammodel.ExamRules        = "";
                                exammodel.StartCheating    = 1;
                                exammodel.LeavePageTimes   = int.MaxValue;
                                exammodel.AutoMarking      = 1;
                                exammodel.LastUpdateTime   = DateTime.Now;
                                exammodel.CreateTime       = DateTime.Now;
                                exammodel.UserID           = CurrentUser.UserId;
                                exammodel.TenantId         = CurrentTenant.TenantId;
                                exammodel.UserCount        = 0;
                                if (string.IsNullOrEmpty(exam.ApprovalUserIds))
                                {
                                    exammodel.ApprovalUser = new List <int>();
                                }
                                else
                                {
                                    exammodel.ApprovalUser =
                                        exam.ApprovalUserIds.Split(',')
                                        .Distinct()
                                        .Where(p => !string.IsNullOrEmpty(p))
                                        .Select(int.Parse)
                                        .ToList();
                                }
                                if (exam.ExamID == 0)
                                {
                                    _examinationBL.AddExamination(exammodel);
                                }
                                else
                                {
                                    exammodel._id = exam.ExamID;
                                    _examinationBL.ModifyExamination(exammodel);
                                }
                                exam.ExamID = exammodel._id;
                            }
                            _classManager.AddTrainClassToExam(exam);
                        }
                    }
                    #endregion

                    #region == 保存实践考评信息 ==
                    var practDataList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Tr_TrainClassToPractical> >(practData);
                    if (practDataList.Any())
                    {
                        _classManager.BatchDeleteTrainClassToPractical(classId);
                        _classManager.AddTrainClassToPracticalS(practDataList);
                    }
                    #endregion

                    tran.Complete();
                }

                return(Json(new { result = 1, content = "保存成功" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { result = 0, content = "保存失败," + ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }