コード例 #1
0
 public string getStudentInfo(string id)
 {
     if (!Validation.IDValidation(id))
         return "Wrong Input";
     ProjectDBEntities PDb = new ProjectDBEntities();
     Student student = new Student();
     try
     {
         IQueryable<StudentInfo> allInfo = from stu in PDb.StudentInfo
                                           where stu.SID == id
                                           select stu;
         if (allInfo.Count() == 0)
             return "False";
         foreach (StudentInfo item in allInfo)
         {
             student.ID = item.SID;
             student.Name = item.S_NAME;
             student.Gender = item.S_GENDER;
             student.School = item.S_SCHOOL;
             student.Birthday = item.S_BIRTHDAY;
             student.Grade = item.S_GRADE;
         }
         string reRes = JsonConvert.SerializeObject(student);
         return reRes;
     }
     catch
     {
         return "False";
     }
 }
コード例 #2
0
 public string Reg(string input)
 {
     Student student = new Student();
     student = JsonConvert.DeserializeObject<Student>(input);
     ProjectDBEntities PDb = new ProjectDBEntities();
     int count = PDb.StudentInfo.Where(s => s.SID == student.ID).Count();
     if (count == 0)
     {
         StudentInfo st = new StudentInfo
         {
             SID = student.ID,
             S_NAME = student.Name,
             S_GENDER = student.Gender,
             S_BIRTHDAY = student.Birthday,
             S_SCHOOL = student.School,
             S_GRADE = student.Grade
         };
         PDb.StudentInfo.Add(st);
         PDb.SaveChanges();
         return "True";
     }
     else
         return "False";
 }