public ActionResult AddToRole(Guid id, int? roleRef) { var user = _Storage.GetUser(u => u.Id == id); if (roleRef == null) { var userList = _Storage.GetRolesAvailableToUser(user).Select(r => new SelectListItem { Text = Localization.getMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false }); var userRole = new UserRoleModel { RoleList = userList }; ModelState.AddModelError("RoleRef", "Please select role from list"); return View(userRole); } var role = UserRoles.GetRole(roleRef.Value); _Storage.AddUserToRole(role, user); return RedirectToAction("Details", new { Id = id }); }
public ActionResult AddToRole(Guid id) { var user = _Storage.GetUser(u => u.Id == id); var roleList = _Storage.GetRolesAvailableToUser(user).Select(r => new SelectListItem { Text = Localization.getMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false }); var userRole = new UserRoleModel { RoleList = roleList }; return View(userRole); }
public ActionResult AddUsersToRole(string usersId, int? roleRef) { var ids = usersId.Split(','); List<Guid> usersIds = new List<Guid>(); foreach (var id in ids) { try { usersIds.Add(Guid.Parse(id)); } catch (Exception) { } } if (roleRef == null) { var list = new List<Role> { Role.Student, Role.Teacher, Role.CourseCreator, Role.Admin }.Select(r => new SelectListItem { Text = Localization.GetMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false }); var userRole = new UserRoleModel { RoleList = list }; this.ModelState.AddModelError("RoleRef", Localization.GetMessage("SelectRole")); return View(userRole); } var role = UserRoles.GetRole(roleRef.Value); foreach (var id in usersIds) { var user = this.storage.GetUser(u => u.Id == id); if (!this.storage.GetRolesAvailableToUser(user).Contains(role)) { continue; } this.storage.AddUserToRole(role, user); } LmsService.Inform(LMSNotifications.ActionsChanged); return RedirectToAction("Index"); }
public ActionResult AddUsersToRole(string usersId) { var ids = usersId.Split(','); List<Guid> usersIds = new List<Guid>(); foreach (var id in ids) { try { usersIds.Add(Guid.Parse(id)); } catch (Exception) { } } var list = new List<Role> { Role.Student, Role.Teacher, Role.CourseCreator, Role.Admin }.Select( r => new SelectListItem { Text = Localization.GetMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false }); var userRole = new UserRoleModel { RoleList = list }; return View(userRole); }
public ActionResult AddToRole(Guid id, int? roleRef) { var user = this.storage.GetUser(u => u.Id == id); if (user == null) { return this.RedirectToAction("Index"); } if (roleRef == null) { var userList = this.storage.GetRolesAvailableToUser(user).Select( r => new SelectListItem { Text = Localization.GetMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false }); var userRole = new UserRoleModel { RoleList = userList }; this.ModelState.AddModelError("RoleRef", "Please select role from list"); return this.View(userRole); } var role = UserRoles.GetRole(roleRef.Value); this.storage.AddUserToRole(role, user); LmsService.Inform(LMSNotifications.ActionsChanged); return this.RedirectToAction("Details", new { Id = id }); }
public ActionResult AddToRole(Guid id) { var user = this.storage.GetUser(u => u.Id == id); if (user == null) { return this.RedirectToAction("Index"); } var roleList = this.storage.GetRolesAvailableToUser(user).Select( r => new SelectListItem { Text = Localization.GetMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false }); var userRole = new UserRoleModel { RoleList = roleList }; LmsService.Inform(LMSNotifications.ActionsChanged); return this.View(userRole); }