protected UserRole CreateUserRole(Division division, Role role, User user) { UserRole userRole = new UserRole(); userRole.Division = division; userRole.Role = role; userRole.User = user; return userRole; }
protected void AssignUserToDivisions(User user, params Division[] divisions) { Role role = new Role(); role.Name = "System administrator"; db.Roles.InsertOnSubmit(role); db.SubmitChanges(); foreach (Division division in divisions) { UserRole userRole = new UserRole(); userRole.Division = division; userRole.Role = role; userRole.User = user; db.UserRoles.InsertOnSubmit(userRole); } db.SubmitChanges(); }
/// <summary> /// Creates new instance of Logged user from user and division entity. Assigns also Roles property /// </summary> /// <param name="user"></param> /// <param name="division"></param> private LoggedUser(User user, Division division) { if (user == null) { throw new ArgumentNullException("user", "User can not be null"); } if (division == null) { throw new ArgumentNullException("division", "Division for user can not be null"); } LoginName = user.LoginName; Name = user.Name; Division = division; User = user; Roles = DbDataContext.GetInstance().UserRoles.Where(ur => ur.Division.ID == division.ID && ur.User.LoginName == user.LoginName).Select(ur => ur.Role).ToList(); }
protected User CreateUser(string userName, bool insertIntoDb) { User user = new User(); user.EmailAddress = userName + "@memos.cz"; user.LoginName = userName; user.Name = userName; if (insertIntoDb) { Db.Users.InsertOnSubmit(user); Db.SubmitChanges(); } return user; }
/// <summary> /// Sets intance of logged user /// </summary> /// <param name="user"></param> /// <param name="division"></param> public static void SetInstance(User user, Division division) { lock (padlock) { if (instance == null) { try { instance = new LoggedUser(user, division); } catch (Exception exc) { System.Windows.MessageBox.Show(exc.Message); } } } }