Пример #1
0
 public ActionResult Edit(StudentInfoEntity studentInfo,AppRelationsEntity appRelation)
 {
     if(studentInfo.StudentID == Guid.Empty)
         studentInfo.StudentID = Guid.NewGuid();
     appRelation.StudentID = studentInfo.StudentID;
     if (ModelState.IsValid)
     {
         repository.SaveStudentInfo(studentInfo, appRelation);
         TempData["message"] = string.Format("{0} has been saved", studentInfo.NameCn);
         return RedirectToAction("List");
     }
     else
     {
         return View(new StudentInfoViewModel { StudentInfo = studentInfo, AppRelation = appRelation });
     }
 }
Пример #2
0
 //根据学生ID返回StudentInfo和AppRelation
 public JsonResult GetStudentInfoViewModel(string studentID)
 {
     StudentInfoEntity studentInfo = null;
     AppRelationsEntity appRelation = null;
     if (studentID == string.Empty || studentID == Guid.Empty.ToString())
     {
         studentInfo = new StudentInfoEntity();
         appRelation = new AppRelationsEntity { StudentID = studentInfo.StudentID };
     }
     else
     {
         Guid id = new Guid(studentID);
         studentInfo = repository.StudentsInfo.SingleOrDefault(s => s.StudentID == id);
         appRelation = repository.AppRelations.SingleOrDefault(a => a.StudentID == id);
     }
     return Json(new { StudentInfo=studentInfo, AppRelation=appRelation },JsonRequestBehavior.AllowGet);
 }
Пример #3
0
        public void SaveStudentInfo(StudentInfoEntity studentInfo,AppRelationsEntity appRelation)
        {
            if(studentInfo.StudentID == Guid.Empty) //如果传入的学生ID为空,则创建一个新的GUID
                studentInfo.StudentID = appRelation.StudentID = Guid.NewGuid(); //确保StudentInfo和AppRelation会创建同一个StudentID的对象

            if (context.StudentsInfo.Where(u => u.StudentID == studentInfo.StudentID).SingleOrDefault()==null)  //如果数据库不存在传入的Guid,则为添加新记录,否则修改已有对象
            {
                studentInfo.CreateTime = DateTime.Now;
                context.StudentsInfo.Add(studentInfo);
            }
            else
            {
                StudentInfoEntity originStudent = context.StudentsInfo.Where(u => u.StudentID == studentInfo.StudentID).SingleOrDefault();  //根据StudentID查找到就的StudentInfo
                studentInfo.CreateTime = originStudent.CreateTime;
                context.Entry(originStudent).CurrentValues.SetValues(studentInfo);
            }

            SaveAppRelation(appRelation); //同步添加AppRelation

            context.SaveChanges();
        }
Пример #4
0
        public JsonResult EditStudent(StudentInfoEntity studentInfo, AppRelationsEntity appRelation, IEnumerable<EasyChatTimeEntity> EasyChatTimes)
        {
            bool editResult = true;
            if (studentInfo != null && appRelation != null)
            {
                //获取学生现在的销售顾问的ID,等下将要与新的销售顾问进行比较
                Guid? currentSaleConsultantID = repository.AppRelations.Single(a => a.StudentID == studentInfo.StudentID).SaleConsultant;

                //保存StudentInfo、AppRelation 信息到数据库中
                repository.SaveStudentInfo(studentInfo, appRelation);

                //只有在销售顾问有变化时才更新新销售顾问的LastJobData
                if (currentSaleConsultantID != appRelation.SaleConsultant)
                {
                    UserInfoEntity saleUser = repository.UsersInfo.SingleOrDefault(u => u.UserID == appRelation.SaleConsultant);
                    saleUser.LastJobDate = DateTime.Now;
                    userRepository.SaveUserInfo(saleUser);
                }

                //删除EasyChatTimes中与学生有关的所有记录
                repository.EmptyStudentEasyChatTimes(studentInfo.StudentID);

                //遍历EasyChatTimes, 并添加到数据库中
                if (EasyChatTimes != null)
                {
                    foreach (EasyChatTimeEntity item in EasyChatTimes)
                    {
                        repository.SaveEasyChatTime(item);
                    }
                }
            }
            else
            {
                editResult = false;
            }
            return Json(new { EditResult = editResult });
        }
Пример #5
0
        public void DeleteStudentInfo(StudentInfoEntity studentInfo)
        {
            StudentInfoEntity originStudent = context.StudentsInfo.Where(u => u.StudentID == studentInfo.StudentID).SingleOrDefault();  //根据StudentID查找到就的StudentInfo
            context.StudentsInfo.Remove(originStudent);

            //还有很大段删除操作要进行,因为涉及的数据表很多

            //AppRelation
            AppRelationsEntity appRelation = context.AppRelations.Where(a => a.StudentID == studentInfo.StudentID).SingleOrDefault();
            DeleteAppRelation(appRelation);

            //AssayMaterial
            DeleteAssayMaterial(studentInfo.StudentID);

            context.SaveChanges();
        }