- Timestamp:
- 04/01/16 16:34:14 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/UserController.cs
r13741 r13742 27 27 _environment = env; 28 28 } 29 #region Users30 29 private void init() 31 30 { … … 43 42 } 44 43 } 44 #region Users 45 45 46 public IActionResult Index() 46 47 { … … 75 76 { 76 77 vm.SelectedUser = vm.getUserById(curr); 78 vm.SelectedUserSubscriptions = accessClient.getSubscribedGroups(curr); 77 79 ViewBag.title = vm.SelectedUser.UserName; 78 80 } … … 97 99 user = accessClient.Users.Find(x => x.Id == uid); 98 100 99 user.Id = uid; 100 user.UserName = inpusername; 101 101 102 user.FullName = inpfullname; 102 103 user.Email = inpemail; … … 105 106 if (uid == Guid.Empty) 106 107 { 108 user.UserName = inpusername; 107 109 uid = accessClient.addUser(user); 108 ViewBag.Title = inpusername + " added - User";110 ViewBag.Title = user.UserName + " added - User"; 109 111 } 110 112 else 111 113 { 112 114 accessClient.updateUser(user); 113 ViewBag.Title = inpusername + " updated - User";115 ViewBag.Title = user.UserName + " updated - User"; 114 116 } 115 117 116 118 return RedirectToAction( "SelectUser", new { id = uid.ToString()}); 119 120 } 121 public IActionResult deleteUser(string id) 122 { 123 init(); 124 var uid = Guid.Parse(id); 125 UserViewModel vm = new UserViewModel(accessClient).refreshUsers(); 126 127 if (uid == Guid.Empty) 128 { 129 vm.message = "Something went wrong, user is not deleted"; 130 return View("Index", vm); 131 } 132 else 133 { 134 var user = vm.getUserById(uid); 135 vm.message = user.UserName + " ("+user.FullName+") has been deleted"; 136 accessClient.DeleteUser(user); 137 vm.refreshUsers(); 138 return View("Index", vm); 139 } 117 140 118 141 } … … 128 151 129 152 ViewBag.Title = "Groups"; 130 // accessClient.RefreshUsers(); 131 132 return View("Groups"); 133 } 134 else 135 { 136 return RedirectToAction("Index", "Home"); 137 } 153 UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers(); 154 return View("Groups", vm); 155 } 156 else 157 { 158 return RedirectToAction("Index", "Home"); 159 } 160 } 161 public IActionResult SelectGroup(string id) 162 { 163 init(); 164 if (serviceLocator.CheckLogin()) 165 { 166 Guid curr = Guid.Parse(id); 167 168 UserViewModel vm = new UserViewModel(accessClient) 169 .refreshGroups() 170 .refreshUsers(); 171 if (curr == Guid.Empty) 172 { 173 ViewBag.Title = "Add group"; 174 } 175 else 176 { 177 vm.SelectedGroup = vm.getGroupById(curr); 178 vm.SelectedGroupMembers = accessClient.getGroupMembers(curr); 179 ViewBag.title = vm.SelectedGroup.Name; 180 } 181 ViewBag.Title += " - Group"; 182 return View("Groups", vm); 183 } 184 else 185 { 186 return RedirectToAction("Index", "Home"); 187 } 188 } 189 [HttpPost] 190 public IActionResult saveGroup(string inpgroupname, string u, string[] userstoadd, string[] groupstoadd) 191 { 192 init(); 193 var uid = Guid.Parse(u); 194 var vm = new UserViewModel(accessClient).refreshGroups().refreshUsers(); 195 196 Access.UserGroup group; 197 198 if (uid == Guid.Empty) 199 group = new Access.UserGroup(); 200 else 201 group = accessClient.Groups.Find(x => x.Id == uid); 202 203 group.Name = inpgroupname; 204 205 if (uid == Guid.Empty) 206 { 207 uid = accessClient.addGroup(group); 208 ViewBag.Title = group.Name + " added - Group"; 209 } 210 else 211 { 212 accessClient.updateGroup(group); 213 ViewBag.Title = group.Name + " updated - Group"; 214 } 215 vm.refreshGroups(); 216 group = vm.getGroupById(uid); 217 foreach(var s in userstoadd) 218 { 219 var tempid = Guid.Parse(s); 220 var member = vm.getUserById(tempid); 221 accessClient.addMember(member, group); 222 } 223 foreach (var g in groupstoadd) 224 { 225 var tempid = Guid.Parse(g); 226 var member = vm.getGroupById(tempid); 227 accessClient.addMember(member, group); 228 } 229 230 return RedirectToAction("SelectGroup", new { id = uid.ToString() }); 231 232 } 233 public IActionResult deleteGroup(string id) 234 { 235 init(); 236 var uid = Guid.Parse(id); 237 UserViewModel vm = new UserViewModel(accessClient).refreshGroups(); 238 239 if (uid == Guid.Empty) 240 { 241 vm.message = "Something went wrong, group is not deleted"; 242 return View("Groups", vm); 243 } 244 else 245 { 246 var group = vm.getGroupById(uid); 247 vm.message = group.Name + " has been deleted"; 248 accessClient.deleteUserGroup(group); 249 vm.refreshGroups(); 250 return View("Groups", vm); 251 } 252 253 } 254 public IActionResult deleteMember(string g, string m) 255 { 256 init(); 257 var gid = Guid.Parse(g); 258 var mid = Guid.Parse(m); 259 UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers() ; 260 261 if (gid == Guid.Empty || mid == Guid.Empty) 262 { 263 vm.message = "Something went wrong, member is not deleted"; 264 return View("Groups", vm); 265 } 266 else 267 { 268 var group = vm.getGroupById(gid); 269 Access.UserGroupBase member = vm.getUserById(mid); 270 if(member == null) 271 { 272 member = vm.getGroupById(mid); 273 } 274 vm.message = " Member deleted"; 275 accessClient.deleteMember(member,group); 276 vm.refreshGroups(); 277 return RedirectToAction("SelectGroup", new { id = g }); 278 } 279 138 280 } 139 281 #endregion 282 140 283 #region Roles 141 284 public IActionResult Roles()
Note: See TracChangeset
for help on using the changeset viewer.