public ActionResult AddToGroup(Guid id, int?groupRef) { var user = _Storage.GetUser(u => u.Id == id); if (groupRef == null) { var groupList = _Storage.GetGroupsAvailableToUser(user).Select( g => new SelectListItem { Text = g.Name, Value = g.Id.ToString(), Selected = false }); var userGroup = new UserGroupModel { GroupList = groupList }; ModelState.AddModelError("GroupRef", "Please select group from list"); return(View(userGroup)); } var group = _Storage.GetGroup(groupRef.Value); _Storage.AddUserToGroup(group, user); return(RedirectToAction("Details", new { Id = id })); }
public ActionResult AddUsers(int id, Guid?userRef) { var group = _Storage.GetGroup(id); if (userRef == null) { var userList = _Storage.GetUsersNotInGroup(group).Select( u => new SelectListItem { Text = u.Username, Value = u.Id.ToString(), Selected = false }); var groupUser = new GroupUser { Group = group, UserList = userList }; ModelState.AddModelError("UserRef", Localization.getMessage("PleaseSelectUserFromList")); return(View(groupUser)); } var user = _Storage.GetUser(u => u.Id == userRef.Value); _Storage.AddUserToGroup(group, user); return(RedirectToAction("Details", new { Id = id })); }
public static void GroupOfStudents(string groupName, IEnumerable <User> students, IUserStorage userStorage) { Group demoGroup = new Group { Name = groupName }; if (!userStorage.GetGroups().Select(g => g.Name).Contains(demoGroup.Name)) { userStorage.CreateGroup(demoGroup); } else { demoGroup.Id = userStorage.GetGroups().FirstOrDefault(g => g.Name == demoGroup.Name).Id; } foreach (var stud in students.Select(s => s).Where(s => !userStorage.GetUsers().Select(u => u.Username).Contains(s.Username))) { userStorage.CreateUser(stud); userStorage.AddUserToRole(Role.Student, stud); userStorage.AddUserToGroup(demoGroup, stud); } }
public static void GroupOfStudents(string groupName, IEnumerable<User> students, IUserStorage userStorage) { Group demoGroup = new Group { Name = groupName }; if (!userStorage.GetGroups().Select(g => g.Name).Contains(demoGroup.Name)) { userStorage.CreateGroup(demoGroup); } else { demoGroup.Id = userStorage.GetGroups().FirstOrDefault(g => g.Name == demoGroup.Name).Id; } foreach (var stud in students.Select(s => s).Where(s => !userStorage.GetUsers().Select(u => u.Username).Contains(s.Username))) { userStorage.CreateUser(stud); userStorage.AddUserToRole(Role.Student, stud); userStorage.AddUserToGroup(demoGroup, stud); } }