// will only allow one ScreeningEntity per user. public bool SetScreeningEntity(int screeningEntityId, int userId) { ScreeningEntity se = this.screeningEntityRepository.Get(screeningEntityId); AdminUser u = this.userTasks.GetAdminUser(userId); if (u != null) { foreach (ScreeningEntity e in this.screeningEntityRepository.GetAll()) { u.RemoveScreeningEntity(e); } if (se != null) { u.AddScreeningEntity(se); } return(true); } return(false); }
public ActionResult Edit(UserViewModel vm) { if (ModelState.IsValid) { AdminUser u = this.userTasks.GetAdminUser(vm.Id); u.Email = vm.Email; u.AdminRoles.Clear(); if (!string.IsNullOrEmpty(vm.AdminRoleIds)) { string[] ids = vm.AdminRoleIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { AdminRole r = this.userTasks.GetAdminRole(result); if (r != null) { u.AdminRoles.Add(r); } } } } u.Affiliations.Clear(); if (!string.IsNullOrEmpty(vm.SourceOwningEntityIds)) { string[] ids = vm.SourceOwningEntityIds.Split(','); foreach (string id in ids) { int result; if (int.TryParse(id, out result)) { SourceOwningEntity e = this.sourcePermissionTasks.GetSourceOwningEntity(result); if (e != null) { u.Affiliations.Add(e); } } } } if (vm.RequestEntityID.HasValue) { this.requestTasks.SetRequestEntity(vm.RequestEntityID.Value, vm.Id); } else { foreach (RequestEntity re in this.requestTasks.GetRequestEntities()) { u.RemoveRequestEntity(re); } } if (vm.ScreeningEntityID.HasValue) { this.screeningTasks.SetScreeningEntity(vm.ScreeningEntityID.Value, vm.Id); } else { foreach (ScreeningEntity se in this.screeningTasks.GetScreeningEntities()) { u.RemoveScreeningEntity(se); } } } return(RedirectToAction("Details", new { id = vm.Id })); }