Пример #1
0
        public ActionResult EditEmail(User user)
        {
            if (user.Id.ToLower() != CurrentUser.Identity.Name.ToLower())
            {
                return(this.RedirectToAction <ErrorController>(a => a.NotAuthorized()));
            }

            var userToEdit = GetCurrent();

            userToEdit.Email = user.Email.ToLower();

            ModelState.Clear();
            userToEdit.TransferValidationMessagesTo(ModelState);

            if (!ModelState.IsValid)
            {
                ErrorMessage = "Unable to Save";
                return(View(user));
            }

            _userRepository.EnsurePersistent(userToEdit);
            Message = "Email Updated";

            return(this.RedirectToAction(a => a.Profile()));
        }
Пример #2
0
        public ActionResult AdminEdit(Guid id, int?seminarId, bool?allList, PersonEditModel personEditModel, HttpPostedFileBase profilepic)
        {
            var user = _userRepository.GetNullableById(id);

            if (user == null)
            {
                Message = string.Format(Messages.NotFound, "user", id);
                int sid = 0;

                if (!seminarId.HasValue)
                {
                    sid = SiteService.GetLatestSeminar(Site).Id;
                }
                else
                {
                    sid = seminarId.Value;
                }

                return(this.RedirectToAction <AttendeeController>(a => a.Index(sid)));
            }

            var seminarPerson = _seminarPersonRepository.GetNullableById(personEditModel.SeminarPersonId);
            var person        = SetPerson(personEditModel, seminarPerson, ModelState, user.Person, profilepic);

            var membership = user.Membership;

            user.SetUserName(personEditModel.UserName);
            membership.SetEmail(personEditModel.Email);

            if (ModelState.IsValid)
            {
                _personRepository.EnsurePersistent(person);
                _userRepository.EnsurePersistent(user);
                _membershipRepository.EnsurePersistent(membership);

                if (seminarPerson != null)
                {
                    _seminarPersonRepository.EnsurePersistent(seminarPerson);
                }
                Message = string.Format(Messages.Saved, "Person");

                // send to crop photo if one was uploaded
                if (profilepic != null)
                {
                    return(this.RedirectToAction(a => a.UpdateProfilePicture(person.Id, seminarId, true)));
                }

                return(this.RedirectToAction(a => a.AdminEdit(person.User.Id, seminarId, null)));
            }

            ViewBag.AllList = allList ?? false;
            var viewModel = AdminPersonViewModel.Create(Repository, _firmService, Site, seminarId, user.Person, user.Email);

            return(View(viewModel));
        }
Пример #3
0
        public ActionResult Edit(EmployeeEditModel editModel)
        {
            var id = editModel.Id.Substring(2);

            //TODO: Check permissions
            //var isDepartmentUser = Session[GlobalConstants.KEY_IS_DEPARTMENT_USER] as bool? ?? false;
            var employee = _employeeRepository.GetById(id);

            if (editModel.HireDate.HasValue)
            {
                employee.SetCareerHireDate(editModel.HireDate.Value);
            }
            else
            {
                employee.SetCareerHireDate(null);
            }

            if (editModel.TitleDate.HasValue)
            {
                employee.SetApptHireDate(editModel.TitleDate.Value);
            }
            else
            {
                employee.SetApptHireDate(null);
            }

            if (editModel.ExperienceDate.HasValue)
            {
                employee.SetExperienceBeginDate(editModel.ExperienceDate.Value);
            }
            else
            {
                employee.SetExperienceBeginDate(null);
            }

            employee.SetPPSCareerHireDateChecked(editModel.HireChecked);
            employee.SetPPSApptHireDateChecked(editModel.TitleChecked);

            employee.SetDepartmentComments(editModel.DeptComments, IsDepartmentUser);
            employee.SetDeansOfficeComments(editModel.DeansComments, IsDepartmentUser);

            _employeeRepository.EnsurePersistent(employee);

            var result = new
            {
                hireDate          = String.Format("{0:MM/dd/yyyy}", employee.AdjustedCareerHireDate),
                hireAdjusted      = employee.CareerDateHasBeenAdjusted,
                yearsOfService    = String.Format("{0:0.00}", employee.YearsOfService),
                titleDate         = String.Format("{0:MM/dd/yyyy}", employee.ApptHireDate),
                titleAdjusted     = employee.ApptDateHasBeenAdjusted,
                timeInTitle       = String.Format("{0:0.00}", employee.TimeInTitle),
                experienceDate    = employee.ExperienceBeginDate == null ? String.Empty : String.Format("{0:MM/dd/yyyy}", employee.ExperienceBeginDate),
                yearsOfExperience = employee.YearsOfExperience == null ? String.Empty : String.Format("{0:0.00}", employee.YearsOfExperience),
                success           = true
            };

            return(Json(result));
        }
        public ActionResult Create(DepartmentalAdminRequestViewModel request, List <string> orgs)
        {
            Check.Require(request != null);
            if (orgs == null || !orgs.Any())
            {
                ErrorMessage = "Must select at least one organization";
                return(this.RedirectToAction(x => x.Create()));
            }

            var ldap = _directorySearchService.FindUser(CurrentUser.Identity.Name);

            Check.Require(ldap != null, "Person requesting Departmental Access ID not found. ID = " + CurrentUser.Identity.Name);

            var requestToSave = _departmentalAdminRequestRepository.GetNullableById(CurrentUser.Identity.Name.ToLower()) ?? new DepartmentalAdminRequest(CurrentUser.Identity.Name.ToLower());

            requestToSave.RequestCount++;
            requestToSave.Complete        = false;
            requestToSave.FirstName       = ldap.FirstName;
            requestToSave.LastName        = ldap.LastName;
            requestToSave.Email           = ldap.EmailAddress;
            requestToSave.DateCreated     = DateTime.UtcNow.ToPacificTime();
            requestToSave.Organizations   = string.Join(",", orgs);
            requestToSave.PhoneNumber     = request.DepartmentalAdminRequest.PhoneNumber;
            requestToSave.SharedOrCluster = request.DepartmentalAdminRequest.SharedOrCluster;
            requestToSave.DepartmentSize  = request.DepartmentalAdminRequest.DepartmentSize;

            ModelState.Clear();
            requestToSave.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _departmentalAdminRequestRepository.EnsurePersistent(requestToSave);

                //TODO: Generate email to either all admins or a specific person that a DA request has arrived

                Message = "Request created.";
                return(this.RedirectToAction <HomeController>(x => x.Index()));
            }

            ErrorMessage = "There were Errors, please correct and try again.";
            request.DepartmentalAdminRequest = requestToSave;
            return(View(request));
        }
Пример #5
0
 /// <summary>
 /// Loads the records for CRUD Tests.
 /// </summary>
 /// <returns></returns>
 protected virtual void LoadRecords(int entriesToAdd)
 {
     EntriesAdded += entriesToAdd;
     for (int i = 0; i < entriesToAdd; i++)
     {
         var validEntity = GetValid(i + 1);
         if (typeof(IdT) == typeof(int))
         {
             _intRepository.EnsurePersistent(validEntity);
         }
         else if (typeof(IdT) == typeof(Guid))
         {
             _guidRepository.EnsurePersistent(validEntity, true);
         }
         else
         {
             _stringRepository.EnsurePersistent(validEntity);
         }
     }
 }
Пример #6
0
        public ActionResult ModifyAdmin(User user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            var userToSave = _userRepository.GetNullableById(user.Id) ?? new User(user.Id);

            //user.Organizations = userToSave.Organizations; //Transfer the orgs and roles since they aren't managed on this page
            //user.Roles = userToSave.Roles;
            userToSave.FirstName = user.FirstName;
            userToSave.LastName  = user.LastName;
            userToSave.Email     = user.Email;
            userToSave.IsActive  = user.IsActive;

            //Mapper.Map(user, userToSave);


            var isAdmin = userToSave.Roles.Any(x => x.Id == Role.Codes.Admin);

            if (!isAdmin)
            {
                userToSave.Roles.Add(_roleRepository.GetById(Role.Codes.Admin));
            }

            _userRepository.EnsurePersistent(userToSave);

            // invalid the cache for the user that was just given permissions
            _userIdentity.RemoveUserRoleFromCache(Resources.Role_CacheId, userToSave.Id);


            if (_emailPreferencesRepository.GetNullableById(userToSave.Id) == null)
            {
                _emailPreferencesRepository.EnsurePersistent(new EmailPreferences(userToSave.Id));
            }

            Message = string.Format("{0} was edited under the administrator role", user.FullNameAndId);

            return(this.RedirectToAction(a => a.Index()));
        }
Пример #7
0
        public ActionResult Create(School school)
        {
            var schoolToCreate = new School();

            Mapper.Map(school, schoolToCreate);

            schoolToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _schoolRepository.EnsurePersistent(schoolToCreate);

                Message = "School Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = SchoolViewModel.Create(Repository);
                viewModel.School = school;

                return(View(viewModel));
            }
        }
Пример #8
0
        public ActionResult EmailPreferences(EmailPreferences emailPreferences)
        {
            Check.Require(emailPreferences.Id == CurrentUser.Identity.Name,
                          string.Format("User {0} attempted to save the email preferences for {1}",
                                        CurrentUser.Identity.Name, emailPreferences.Id));

            if (!ModelState.IsValid)
            {
                return(View(emailPreferences));
            }

            Message = "Your email preferences have been updated";

            _emailPreferencesRepository.EnsurePersistent(emailPreferences);

            return(RedirectToAction("Profile"));
        }
Пример #9
0
        public ActionResult ColumnPreferences(ColumnPreferences columnPreferences, bool fromList = false)
        {
            Check.Require(columnPreferences.Id == CurrentUser.Identity.Name,
                          string.Format("User {0} attempted to save the column preferences for {1}",
                                        CurrentUser.Identity.Name, columnPreferences.Id));

            if (!ModelState.IsValid)
            {
                return(View(columnPreferences));
            }

            Message = "Your column preferences have been updated";

            _columnPreferencesRepository.EnsurePersistent(columnPreferences);

            return(fromList ? RedirectToAction("Index", "History") : RedirectToAction("Profile"));
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">Workgroup Id</param>
        /// <param name="role">Role being for people being added</param>
        /// <param name="workgroup">workgroup</param>
        /// <param name="successCount">how many have already been successfully added</param>
        /// <param name="lookupUser">user being added</param>
        /// <param name="failCount">count of number not added</param>
        /// <param name="notAddedKvp">list of users not added and reason why.</param>
        /// <returns></returns>
        public int TryToAddPeople(int id, Role role, Workgroup workgroup, int successCount, string lookupUser, ref int failCount, ref int duplicateCount, List <KeyValuePair <string, string> > notAddedKvp)
        {
            var saveParm = lookupUser;
            var user     = _userRepository.GetNullableById(lookupUser);

            if (user == null)
            {
                var ldapuser = _searchService.FindUser(lookupUser);
                if (ldapuser != null)
                {
                    lookupUser = ldapuser.LoginId;
                    user       = _userRepository.GetNullableById(ldapuser.LoginId);
                    if (user == null)
                    {
                        user           = new User(ldapuser.LoginId);
                        user.Email     = ldapuser.EmailAddress;
                        user.FirstName = ldapuser.FirstName;
                        user.LastName  = ldapuser.LastName;

                        _userRepository.EnsurePersistent(user);

                        var emailPrefs = new EmailPreferences(user.Id);
                        _emailPreferencesRepository.EnsurePersistent(emailPrefs);
                    }
                }
            }

            if (user == null)
            {
                //notAddedSb.AppendLine(string.Format("{0} : Not found", saveParm));
                notAddedKvp.Add(new KeyValuePair <string, string>(saveParm, "Not found"));
                failCount++;
                return(successCount);
            }

            if (!_workgroupPermissionRepository.Queryable.Any(a => a.Role == role && a.User == user && a.Workgroup == workgroup && a.IsAdmin == false))
            {
                var workgroupPermission = new WorkgroupPermission();
                workgroupPermission.Role      = role;
                workgroupPermission.User      = _userRepository.GetNullableById(lookupUser);
                workgroupPermission.Workgroup = _workgroupRepository.GetNullableById(id);

                _workgroupPermissionRepository.EnsurePersistent(workgroupPermission);

                if (workgroup.Administrative)
                {
                    var ids = GetChildWorkgroups(workgroup.Id);
                    foreach (var childid in ids)
                    {
                        var childWorkgroup = _workgroupRepository.Queryable.Single(a => a.Id == childid);
                        if (!_workgroupPermissionRepository.Queryable.Any(a => a.Workgroup == childWorkgroup && a.Role == role && a.User == user && a.IsAdmin && a.ParentWorkgroup == workgroup))
                        {
                            Check.Require(role.Id != Role.Codes.Requester);
                            var childPermission = new WorkgroupPermission();
                            childPermission.Role            = role;
                            childPermission.User            = workgroupPermission.User;
                            childPermission.Workgroup       = childWorkgroup;
                            childPermission.IsAdmin         = true;
                            childPermission.IsFullFeatured  = workgroup.IsFullFeatured;
                            childPermission.ParentWorkgroup = workgroup;
                            _workgroupPermissionRepository.EnsurePersistent(childPermission);
                        }
                    }
                }
                // invalid the cache for the user that was just given permissions
                _userIdentity.RemoveUserRoleFromCache(Resources.Role_CacheId, workgroupPermission.User.Id);

                successCount++;
            }
            else
            {
                //notAddedSb.AppendLine(string.Format("{0} : Is a duplicate", lookupUser));
                notAddedKvp.Add(new KeyValuePair <string, string>(lookupUser, "Is a duplicate"));
                failCount++;
                duplicateCount++;
            }

            return(successCount);
        }
Пример #11
0
        public ActionResult ModifyDepartmental(DepartmentalAdminModel departmentalAdminModel, List <string> orgs)
        {
            if (orgs == null || orgs.Count == 0)
            {
                ModelState.AddModelError("User.Organizations", "You must select at least one department for a departmental Admin.");
            }
            if (!ModelState.IsValid)
            {
                return(View(departmentalAdminModel));
            }

            var user = _userRepository.GetNullableById(departmentalAdminModel.User.Id) ?? new User(departmentalAdminModel.User.Id);


            departmentalAdminModel.User.Roles = user.Roles;

            //Mapper.Map(departmentalAdminModel.User, user); // This was causing problems if an existing DA was saved.
            user.FirstName = departmentalAdminModel.User.FirstName;
            user.LastName  = departmentalAdminModel.User.LastName;
            user.Email     = departmentalAdminModel.User.Email;
            user.IsActive  = departmentalAdminModel.User.IsActive;

            var isDeptAdmin = user.Roles.Any(x => x.Id == Role.Codes.DepartmentalAdmin);
            var isSscAdmin  = user.Roles.Any(x => x.Id == Role.Codes.SscAdmin);

            if (!isDeptAdmin)
            {
                user.Roles.Add(_roleRepository.GetById(Role.Codes.DepartmentalAdmin));
            }

            user.Organizations = new List <Organization>();
            foreach (var org in orgs)
            {
                user.Organizations.Add(_organizationRepository.Queryable.Single(a => a.Id == org));
            }


            _userRepository.EnsurePersistent(user);

            // invalid the cache for the user that was just given permissions
            _userIdentity.RemoveUserRoleFromCache(Resources.Role_CacheId, user.Id);

            if (isSscAdmin && departmentalAdminModel.UpdateAllSscAdmins)
            {
                var userList = new List <string>();
                var users    = _roleRepository.Queryable.Where(x => x.Id == Role.Codes.SscAdmin).SelectMany(x => x.Users).Where(w => w.IsActive && w.Id != user.Id).ToList();

                foreach (var user1 in users)
                {
                    user1.Organizations = new List <Organization>();
                    foreach (var org in orgs)
                    {
                        user1.Organizations.Add(_organizationRepository.Queryable.Single(a => a.Id == org));
                    }
                    _userRepository.EnsurePersistent(user1);
                    // invalid the cache for the user that was just given permissions
                    _userIdentity.RemoveUserRoleFromCache(Resources.Role_CacheId, user1.Id);
                    userList.Add(user1.FullNameAndId);
                }
                Message =
                    string.Format(
                        "{0} was added as a departmental admin to the specified organization(s) Also added perms for {1}.",
                        user.FullNameAndId, string.Join(",", userList.ToArray()));
            }
            else
            {
                Message = string.Format("{0} was added as a departmental admin to the specified organization(s)",
                                        user.FullNameAndId);
            }

            return(this.RedirectToAction(a => a.Index()));
        }
        public ActionResult Create(int?workgroupId, string orgId, ConditionalApprovalModifyModel modifyModel)
        {
            if (workgroupId.HasValue)
            {
                ViewBag.WorkgroupId      = workgroupId.Value;
                modifyModel.ApprovalType = WorkgroupType;
                modifyModel.Workgroup    = _workgroupRepository.GetNullableById(workgroupId.Value);
                var workgroup = _workgroupRepository.Queryable.Single(a => a.Id == workgroupId.Value);
                if (workgroup.Administrative)
                {
                    ErrorMessage = "Conditional Approval may not be added to an administrative workgroup.";
                    return(this.RedirectToAction <WizardController>(a => a.Details(workgroup.Id)));
                }
            }
            else if (!string.IsNullOrWhiteSpace(orgId))
            {
                modifyModel.ApprovalType = OrganizationType;
                modifyModel.Organization = _organizationRepository.GetNullableById(orgId);
                ViewBag.OrganizationId   = orgId;
            }

            var primaryApproverInDb   = GetUserBySearchTerm(modifyModel.PrimaryApprover);
            var secondaryApproverInDb = string.IsNullOrWhiteSpace(modifyModel.SecondaryApprover)
                                            ? null
                                            : GetUserBySearchTerm(modifyModel.SecondaryApprover);

            if (primaryApproverInDb == null)
            {
                DirectoryUser primaryApproverInLdap = _directorySearchService.FindUser(modifyModel.PrimaryApprover);

                if (primaryApproverInLdap == null)
                {
                    ModelState.AddModelError("primaryapprover",
                                             "No user could be found with the kerberos or email address entered");
                }
                else //found the primary approver in ldap
                {
                    primaryApproverInDb = new User(primaryApproverInLdap.LoginId)
                    {
                        FirstName = primaryApproverInLdap.FirstName,
                        LastName  = primaryApproverInLdap.LastName,
                        Email     = primaryApproverInLdap.EmailAddress,
                        IsActive  = true
                    };

                    _userRepository.EnsurePersistent(primaryApproverInDb, forceSave: true);
                }
            }

            if (!string.IsNullOrWhiteSpace(modifyModel.SecondaryApprover)) //only check if a value was provided
            {
                if (secondaryApproverInDb == null)
                {
                    DirectoryUser secondaryApproverInLdap = _directorySearchService.FindUser(modifyModel.SecondaryApprover);

                    if (secondaryApproverInLdap == null)
                    {
                        ModelState.AddModelError("secondaryapprover",
                                                 "No user could be found with the kerberos or email address entered");
                    }
                    else //found the secondary approver in ldap
                    {
                        secondaryApproverInDb = new User(secondaryApproverInLdap.LoginId)
                        {
                            FirstName = secondaryApproverInLdap.FirstName,
                            LastName  = secondaryApproverInLdap.LastName,
                            Email     = secondaryApproverInLdap.EmailAddress,
                            IsActive  = true
                        };

                        _userRepository.EnsurePersistent(secondaryApproverInDb, forceSave: true);
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(CreateModifyModel(modifyModel.ApprovalType, modifyModel)));
            }

            Check.Require(modifyModel.Workgroup != null || modifyModel.Organization != null, "Must have a Workgroup or an Organization");

            var newConditionalApproval = new ConditionalApproval
            {
                Question          = modifyModel.Question,
                Organization      = modifyModel.Organization,
                Workgroup         = modifyModel.Workgroup,
                PrimaryApprover   = primaryApproverInDb,
                SecondaryApprover = secondaryApproverInDb
            };

            _conditionalApprovalRepository.EnsurePersistent(newConditionalApproval);

            Message = "Conditional approval added successfully";

            if (workgroupId.HasValue)
            {
                return(this.RedirectToAction(a => a.ByWorkgroup(workgroupId.Value)));
            }

            if (!string.IsNullOrWhiteSpace(orgId))
            {
                return(this.RedirectToAction(a => a.ByOrg(orgId)));
            }

            //return this.RedirectToAction(a => a.Index());
            return(this.RedirectToAction <ErrorController>(a => a.Index()));
        }
Пример #13
0
        public ActionResult AddConditionalApproval(int id, ConditionalApproval conditionalApproval, string primaryApproverParm, string secondaryApproverParm)
        {
            ViewBag.StepNumber = 11;
            // TODO Check that primary and secondary approvers are in db, add if not. Double check against ConditionalApprover controller
            var workgroup = _workgroupRepository.GetNullableById(id);

            if (workgroup == null)
            {
                Message = "Workgroup not found.";
                this.RedirectToAction <WorkgroupController>(a => a.Index(false));
            }
            ViewBag.IsAccountSync = workgroup.SyncAccounts;

            var primaryApproverInDb   = GetUserBySearchTerm(primaryApproverParm);
            var secondaryApproverInDb = string.IsNullOrWhiteSpace(secondaryApproverParm)
                                            ? null
                                            : GetUserBySearchTerm(secondaryApproverParm);

            if (primaryApproverInDb == null)
            {
                DirectoryUser primaryApproverInLdap = _searchService.FindUser(primaryApproverParm);

                if (primaryApproverInLdap == null)
                {
                    ModelState.AddModelError("primaryApproverParm",
                                             "No user could be found with the kerberos or email address entered");
                }
                else //found the primary approver in ldap
                {
                    primaryApproverInDb = new User(primaryApproverInLdap.LoginId)
                    {
                        FirstName = primaryApproverInLdap.FirstName,
                        LastName  = primaryApproverInLdap.LastName,
                        Email     = primaryApproverInLdap.EmailAddress,
                        IsActive  = true
                    };

                    _userRepository.EnsurePersistent(primaryApproverInDb, forceSave: true);
                }
            }

            if (!string.IsNullOrWhiteSpace(secondaryApproverParm)) //only check if a value was provided
            {
                if (secondaryApproverInDb == null)
                {
                    DirectoryUser secondaryApproverInLdap = _searchService.FindUser(secondaryApproverParm);

                    if (secondaryApproverInLdap == null)
                    {
                        ModelState.AddModelError("secondaryApproverParm",
                                                 "No user could be found with the kerberos or email address entered");
                    }
                    else //found the secondary approver in ldap
                    {
                        secondaryApproverInDb = new User(secondaryApproverInLdap.LoginId)
                        {
                            FirstName = secondaryApproverInLdap.FirstName,
                            LastName  = secondaryApproverInLdap.LastName,
                            Email     = secondaryApproverInLdap.EmailAddress,
                            IsActive  = true
                        };

                        _userRepository.EnsurePersistent(secondaryApproverInDb, forceSave: true);
                    }
                }
            }

            conditionalApproval.PrimaryApprover   = primaryApproverInDb;
            conditionalApproval.SecondaryApprover = secondaryApproverInDb;
            conditionalApproval.Workgroup         = workgroup;
            ModelState.Clear();
            conditionalApproval.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                var newConditionalApproval = new ConditionalApproval
                {
                    Question          = conditionalApproval.Question,
                    Organization      = conditionalApproval.Organization,
                    Workgroup         = workgroup,
                    PrimaryApprover   = primaryApproverInDb,
                    SecondaryApprover = secondaryApproverInDb
                };
                Repository.OfType <ConditionalApproval>().EnsurePersistent(newConditionalApproval);
                return(this.RedirectToAction(a => a.ConditionalApprovals(id)));
            }
            conditionalApproval.Workgroup = workgroup;
            return(View(conditionalApproval));
        }