/// <summary> /// 根据学生ID 返回申请阶段(全新的哦) /// </summary> /// <param name="versionID"></param> /// <returns></returns> public JsonResult GetScheduleApply(string studentID) { if (studentID == null || studentID == string.Empty || studentID == Guid.Empty.ToString()) { return(Json(new { GetResult = false, Msg = "不能传入空的学生ID" }, JsonRequestBehavior.AllowGet)); } Guid StudentID = new Guid(studentID); AppRelationsEntity appRelation = repository.AppRelations.SingleOrDefault(s => s.StudentID == StudentID); DateTime studentSignDate = Convert.ToDateTime(appRelation.SignDate); //根据月、日进行筛选,并选出符合条件的第一个Entity,通过比较Month与Day两值相加的值来排序比较 ApplyStageVersionEntity suitableVersion = GetApplyVersionByStudentID(StudentID); if (suitableVersion == null) { return(Json(new { GetResult = false, Msg = "找不到符合条件的申请阶段版本,请先创建符合签约日期范围的版本" }, JsonRequestBehavior.AllowGet)); } if (repository.ApplyStageVersionDetail.Count(a => a.VersionID == suitableVersion.VersionID) <= 0) { return(Json(new { GetResult = false, Msg = "找不到符合条件的申请版本的阶段细节,请先编辑相关版本的阶段细节" }, JsonRequestBehavior.AllowGet)); } else { List <StudentApplyStageWrap> applyStageWrapList = CalApplyStageWrapList(StudentID, studentSignDate, suitableVersion.VersionID); return(Json(applyStageWrapList.OrderBy(a => a.ParentStage.StageNo), JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 根据版本ID 返回版本信息 /// </summary> /// <param name="versionID"></param> /// <returns></returns> public JsonResult GetVersionById(string versionID) { if (versionID == null || versionID == string.Empty || versionID == Guid.Empty.ToString()) { return(Json(new ApplyStageVersionEntity { VersionID = Guid.NewGuid(), SignDateBefore = DateTime.Now }, JsonRequestBehavior.AllowGet)); } ApplyStageVersionEntity applyVersion = repository.ApplyStageVersion.Single(r => r.VersionID == new Guid(versionID)); return(Json(applyVersion, JsonRequestBehavior.AllowGet)); }
public JsonResult VersionEdit(ApplyStageVersionEntity ajaxData) { if (ajaxData.SignDateBefore == null) { return(Json(new { SaveResult = false })); } else { repository.SaveApplyStageVersion(ajaxData); return(Json(new { SaveResult = true })); } }
/// <summary> /// 根据学生ID返回合适的申请版本 /// </summary> /// <param name="StudentID"></param> /// <returns></returns> ApplyStageVersionEntity GetApplyVersionByStudentID(Guid StudentID) { StudentInfoEntity studentInfo = repository.StudentsInfo.SingleOrDefault(s => s.StudentID == StudentID); AppRelationsEntity appRelation = repository.AppRelations.SingleOrDefault(s => s.StudentID == StudentID); DateTime studentSignDate = Convert.ToDateTime(appRelation.SignDate); //根据月、日进行筛选,并选出符合条件的第一个Entity,通过比较Month与Day两值相加的值来排序比较 ApplyStageVersionEntity suitableVersion = repository.ApplyStageVersion .Where(a => a.SignDateBefore.Month * 100 + a.SignDateBefore.Day >= studentSignDate.Month * 100 + studentSignDate.Day) .OrderBy(a => (a.SignDateBefore.Month * 100 + a.SignDateBefore.Day)) .FirstOrDefault(); return(suitableVersion); }
/// <summary> /// 添加或更新ApplyStageVersion 数据 /// </summary> /// <param name="versionEntity"></param> public void SaveApplyStageVersion(ApplyStageVersionEntity versionEntity) { if (versionEntity.VersionID == Guid.Empty) //如果传入的Guid全为0,则为添加一新Guid { versionEntity.VersionID = Guid.NewGuid(); } ApplyStageVersionEntity originVersionEntity = context.ApplyStageVersion .SingleOrDefault(a => a.VersionID == versionEntity.VersionID || a.VersionName == versionEntity.VersionName); if (originVersionEntity == null) { context.ApplyStageVersion.Add(versionEntity); } else { context.Entry(originVersionEntity).CurrentValues.SetValues(versionEntity); } context.SaveChanges(); }
public JsonResult ScheduleApply(IEnumerable <StudentApplyStageWrap> ajaxData) { if (ajaxData == null) { return(Json(new { SaveResult = false })); } Guid studentID = ajaxData.FirstOrDefault().ParentStage.StudentID; //根据月、日进行筛选,并选出符合条件的第一个Entity,通过比较Month与Day两值相加的值来排序比较 ApplyStageVersionEntity suitableVersion = GetApplyVersionByStudentID(studentID); List <ApplyStageVersionDetailEntity> versionDetailList = repository.ApplyStageVersionDetail.Where(a => a.VersionID == suitableVersion.VersionID).ToList(); List <StudentApplyStageEntity> applyStageList = new List <StudentApplyStageEntity>(); ApplyStageVersionDetailEntity currentStage = null; //将列表按父阶段的StageNo进行排序 ajaxData = ajaxData.OrderBy(w => w.ParentStage.StageNo); int i = 0; foreach (StudentApplyStageWrap applyStageWrap in ajaxData.OrderBy(s => s.ParentStage.StageNo)) { if (applyStageWrap.ParentStage.IsForbid) { continue; } currentStage = versionDetailList.Single(a => a.StageNo == applyStageWrap.ParentStage.StageNo); applyStageWrap.ParentStage.ID = Guid.NewGuid(); applyStageWrap.ParentStage.StageNameEn = currentStage.StageNameEn; applyStageWrap.ParentStage.ParentNo = currentStage.ParentNo; applyStageWrap.ParentStage.StatusOption = currentStage.StatusOption; applyStageWrap.ParentStage.CurrentOption = currentStage.BeginOption; applyStageWrap.ParentStage.BeginOption = currentStage.BeginOption; applyStageWrap.ParentStage.EndOption = currentStage.EndOption; applyStageWrap.ParentStage.CanForbid = currentStage.CanForbid; applyStageWrap.ParentStage.CanChangeDate = currentStage.CanChangeDate; applyStageWrap.ParentStage.CanChangeName = currentStage.CanChangeName; applyStageWrap.ParentStage.IsDateSameWithParent = currentStage.IsDateSameWithParent; foreach (StudentApplyStageEntity childStage in applyStageWrap.ChildStages) { if (childStage.IsForbid) { continue; } currentStage = versionDetailList.Single(a => a.StageNo == childStage.StageNo); childStage.ID = Guid.NewGuid(); childStage.StageNameEn = currentStage.StageNameEn; childStage.ParentNo = currentStage.ParentNo; childStage.StatusOption = currentStage.StatusOption; childStage.CurrentOption = currentStage.BeginOption; childStage.BeginOption = currentStage.BeginOption; childStage.EndOption = currentStage.EndOption; childStage.Percentage = 0; childStage.CanForbid = currentStage.CanForbid; childStage.CanChangeDate = currentStage.CanChangeDate; childStage.CanChangeName = currentStage.CanChangeName; childStage.IsDateSameWithParent = currentStage.IsDateSameWithParent; } //如果是第一个ParentStage,则设其Percentage为1 //同时,如果子阶段无时间限制,则设所有子阶段的Percentage为1,否则仅设第一个子阶段的Percentage为1 //并同时设置阶段的CurrentOption if (i++ == 0) { applyStageWrap.ParentStage.CurrentOption = applyStageWrap.ParentStage.StatusOption.Split(',').ElementAt(1); applyStageWrap.ParentStage.Percentage = 1; if (applyStageWrap.ParentStage.IsDateSameWithParent) { foreach (StudentApplyStageEntity childItem in applyStageWrap.ChildStages) { childItem.CurrentOption = childItem.StatusOption.Split(',').ElementAt(1); childItem.Percentage = 1; } } //applyStageWrap.ChildStages.ForEach(s => s.Percentage = 1); else { applyStageWrap.ChildStages[0].CurrentOption = applyStageWrap.ChildStages[0].StatusOption.Split(',').ElementAt(1); applyStageWrap.ChildStages[0].Percentage = 1; } } applyStageList.Add(applyStageWrap.ParentStage); applyStageList.AddRange(applyStageWrap.ChildStages); } repository.NewStudentApplyStages(applyStageList); AppRelationsEntity appRelation = repository.AppRelations.SingleOrDefault(s => s.StudentID == studentID); appRelation.HasScheduleApply = true; repository.SaveStudentInfo(repository.StudentsInfo.SingleOrDefault(s => s.StudentID == studentID), appRelation); return(Json(new { SaveResult = true })); }