/// <summary> /// Get <see cref="User"/> from model container by unique ID. /// </summary> /// <param name="mc">Entity Framework model container.</param> /// <param name="userId">Unique user ID.</param> /// <returns>User instance.</returns> internal static User GetUserById(MasterEntities mc, Guid userId) { User user = mc.Users.SingleOrDefault(u => u.Id == userId); if (user == null) { throw new Exception("User with ID " + userId + " not found."); } return(user); }
/// <summary> /// Get <see cref="User"/> from model container by unique ID. /// </summary> /// <param name="mc">Entity Framework model container.</param> /// <param name="userName">Unique user name.</param> /// <returns>User instance.</returns> internal static User GetUserByLogin(MasterEntities mc, string userName) { User user = mc.Users.SingleOrDefault(u => u.Login == userName && !u.IsDisabled); if (user == null) { throw new Exception("User with name \"" + userName + "\" not found."); } return(user); }
/// <summary> /// Check is user <paramref name="login"/> name is not used by some one else. /// </summary> /// <param name="mc">Entity Framework model container.</param> /// <param name="login">User login name.</param> /// <returns><c>true</c> if user login name is unique.</returns> internal static bool IsLoginAvailable(MasterEntities mc, string login) { return(mc.Users.SingleOrDefault(u => u.Login == login) == null); }