I make registration on the site for educational purposes. I want to prohibit creating users with the same login. I check for the same login in the interface implementation. Here is the code:
public void Add_New_User(User user) { User olduser = context.Users.FirstOrDefault(c=>c.LoginUser == user.LoginUser); if (olduser == null) { context.Users.Add(user); } else { throw new Exception(); } context.SaveChanges(); } That is, if there is no user with such a login, then I register him. If there is a user with such a login, then I push out an error (And I want to change this error to something more beautiful. For example: to the message "There is already a user with this login").