コード例 #1
0
 public void OnUpdate()
 {
     try
     {
         var dlg = new AddUserDialog();
         dlg.DataContext = SelectedUser;
         if (SelectedUser.Photo != null)
         {
             dlg.Photo = SelectedUser.Photo;
         }
         if (dlg.ShowDialog() == true)
         {
             var item = (from r in ctx.Users where r.UserID == SelectedUser.UserID select r).FirstOrDefault <User>();
             if (item != null)
             {
                 item.FName      = SelectedUser.FName;
                 item.MName      = SelectedUser.MName;
                 item.LName      = SelectedUser.LName;
                 item.UserSIN    = SelectedUser.UserSIN;
                 item.UserRole   = SelectedUser.UserRole;
                 item.Gender     = SelectedUser.Gender;
                 item.StreetNo   = SelectedUser.StreetNo;
                 item.StreetName = SelectedUser.StreetName;
                 item.City       = SelectedUser.City;
                 item.Province   = SelectedUser.Province;
                 item.PostalCode = SelectedUser.PostalCode;
                 item.Phone      = SelectedUser.Phone;
                 item.Cell       = SelectedUser.Cell;
                 item.Email      = SelectedUser.Email;
                 item.Photo      = dlg.Photo;
                 item.Password   = SelectedUser.Password;
             }
             ctx.SaveChanges();
             LoadCourse();
         }
     }
     catch (Exception ex)
         when((ex is InvalidParameterException) || (ex is SystemException))
         {
             Log.WriteLine(ex.Message);
         }
 }
コード例 #2
0
 public void OnAdd()
 {
     try
     {
         var dlg  = new AddUserDialog();
         var user = new User();
         dlg.DataContext = user;
         if (dlg.ShowDialog() == true)
         {
             user.Photo = dlg.Photo;
             ctx.Users.Add(user);
             ctx.SaveChanges();
             LoadCourse();
         }
     }
     catch (Exception ex)
         when((ex is InvalidParameterException) || (ex is SystemException))
         {
             Log.WriteLine(ex.Message);
         }
 }