Exemplo n.º 1
0
        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 }));
        }
Exemplo n.º 2
0
        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 }));
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
      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);
         }
      }