Exemple #1
0
        // will only allow one RequestEntity per user.
        public bool SetRequestEntity(int requestEntityId, int userId)
        {
            RequestEntity re = this.requestEntityRepository.Get(requestEntityId);
            AdminUser     u  = this.userTasks.GetAdminUser(userId);

            if (u != null)
            {
                foreach (RequestEntity e in this.requestEntityRepository.GetAll())
                {
                    u.RemoveRequestEntity(e);
                }
                if (re != null)
                {
                    u.AddRequestEntity(re);
                }
                return(true);
            }
            return(false);
        }
Exemple #2
0
        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 }));
        }