コード例 #1
0
        public static void SaveRoom(Classroom cl)
        {
            using (var context = new Entities())
            {
                var recordToUpdate = from c in context.Classroom
                                     where c.classCode == cl.classCode
                                     select c;

                List <Classroom> records = recordToUpdate.ToList();
                if (recordToUpdate.Count() > 0)
                {
                    Classroom old = records.FirstOrDefault();
                    context.Entry(old).CurrentValues.SetValues(cl);
                }
                else
                {
                    context.Set <Classroom>().Add(cl);
                }
                context.SaveChanges();
            }
        }
コード例 #2
0
ファイル: UserBinding.cs プロジェクト: munn9422/SeniorProject
 public static void JoinClass(string studentUserID, string classCode)
 {
     using (var context = new Entities())
     {
         var studentquery = from s in context.Student
                            where s.UserID == studentUserID
                            select s;
         var classquery = from cr in context.Classroom
                          where cr.classCode == classCode
                          select cr;
         List <Student>   studentsreturned   = studentquery.ToList();
         List <Classroom> classroomsreturned = classquery.ToList();
         if (studentsreturned.Count < 1 || classroomsreturned.Count < 1)
         {
             //TODO error code
             return;
         }
         Student   stu    = studentquery.First();
         Classroom clroom = classquery.First();
         stu.Classroom = clroom;
         context.SaveChanges();
     }
 }