Example #1
0
 public void Execute(object parameter)
 {
     using (PostDbEntities5 cashDbContext = new PostDbEntities5())
     {
         List <string> errorMessages = new List <string>();
         bool          oldvalid      = cashDbContext.Configuration.ValidateOnSaveEnabled;
         try
         {
             cashDbContext.Configuration.ValidateOnSaveEnabled = false;
             var item = UserViewModel.SelectedUser;
             cashDbContext.Users.Attach(item);
             cashDbContext.Entry(item).State = EntityState.Deleted;
             cashDbContext.SaveChanges();
             UserViewModel.AllUsers.Remove(item);
             UserViewModel.CurrentUser = new User();
         }
         catch (DbEntityValidationException ex)
         {
             foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
             {
                 string entityName = validationResult.Entry.Entity.GetType().Name;
                 foreach (DbValidationError error in validationResult.ValidationErrors)
                 {
                     errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                 }
             }
         }
     }
 }
Example #2
0
 public void Execute(object parameter)
 {
     using (PostDbEntities5 cashDbContext = new PostDbEntities5())
     {
         List <string> errorMessages = new List <string>();
         try
         {
             var item = UserViewModel.CurrentUser;
             cashDbContext.Users.Add(item);
             cashDbContext.SaveChanges();
             UserViewModel.AllUsers.Add(item);
         }
         catch (DbEntityValidationException ex)
         {
             foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
             {
                 string entityName = validationResult.Entry.Entity.GetType().Name;
                 foreach (DbValidationError error in validationResult.ValidationErrors)
                 {
                     errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                 }
             }
         }
     }
 }
Example #3
0
 public void Execute(object parameter)
 {
     using (PostDbEntities5 DbContext = new PostDbEntities5())
     {
         DbContext.Entry(UserViewModel.CurrentUser).State = EntityState.Modified;
         DbContext.SaveChanges();
         UserViewModel.AllUsers = new ObservableCollection <User>(DbContext.Users.ToList());
     }
 }