public ActionResult UpdateInit(int studentid)
        {
            JsonResultData <StudentUIModel> resultdata = new JsonResultData <StudentUIModel>();

            try
            {
                StudentUIModel student = studentservice.GetStudentById(studentid);

                if (student == null)
                {
                    resultdata.Code = 0;
                    resultdata.Data = student;
                }
                else
                {
                    resultdata.Code = 1;
                    resultdata.Data = student;
                }
            }
            catch (Exception ex)
            {
                resultdata.Msg = ex.Message;
            }

            return(Json(resultdata, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public StudentUIModel GetStudentById(int studentid)
        {
            using (var db = new EFContext())
            {
                StudentUIModel student = db.Students
                                         .Select(x => new StudentUIModel()
                {
                    StudentIdUIModel          = x.StudentId,
                    StudentNameUIModel        = x.StudentName,
                    StudentGenderUIModel      = x.StudentGender,
                    StudentPhoneNumberUIModel = x.StudentPhoneNumber,
                    CityUIModel           = x.City,
                    EducationUIModel      = x.Education,
                    PersonalrofileUIModel = x.Personalrofile,
                })
                                         .FirstOrDefault(m => m.StudentIdUIModel == studentid);


                if (student == null)
                {
                    throw new Exception("要编辑的学员不存在,请您刷新列表后在操作!");
                }

                return(student);
            }
        }