public void EditUserBySSN(UserViewModel user) { //Instance of the ManageRoles class to get the user's role ManageRoles man = new ManageRoles(); //Find the right user var model = _db.Users.Where(x => x.SSN == user.SSN).FirstOrDefault(); //If the user dosn't exist throw an exception otherwise change the user information if (model == null) { //TODO: kasta villu throw new ArgumentNullException(); } else { model.FullName = user.FullName; model.SSN = user.SSN; model.Email = user.Email; if (man.GetUserRole(model.Email) != null) { man.ClearUserRoles(model.Id); } man.AddUserToRole(model.Id, user.UserRole); } try { _db.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var error in ex.EntityValidationErrors) { Console.WriteLine("===================="); Console.WriteLine("Entity {0} in state {1} has validation errors:", error.Entry.Entity.GetType().Name, error.Entry.State); foreach (var ve in error.ValidationErrors) { Console.WriteLine("\tProperty: {0}, Error: {1}", ve.PropertyName, ve.ErrorMessage); } Console.WriteLine(); } throw; } }