Beispiel #1
0
        public int Modify(
            string userName,
            string password,
            string confPass,
            string permission,
            Employee emp)
        {
            Tuple <string, Permission>[] perms = Employee.GetPermissions();
            // container exception for all then errors in the modification
            CreationException exception = new CreationException();
            bool goodPass = true;

            if (!string.IsNullOrWhiteSpace(password))
            {
                goodPass = emp.ValidPass(password, confPass, exception);
            }
            bool goodUser = emp.ValidUser(userName, exception);

            // match the permission string from the view with the correct
            // permission on the Permission Enum
            Permission suppliedPerm = (from perm in perms
                                       where perm.Item1 == permission
                                       select perm.Item2).FirstOrDefault();

            // default value is 0 or "None"
            if (suppliedPerm == Permission.None)
            {
                exception.AddError(
                    "Invalid selected permission",
                    "The permission provided wasn't any of Manager, " +
                    "Enrollee Specialist, HSP Specialist, Plan Admin, or" +
                    " Accountant");
            }

            if (exception.IsProblem)
            {
                throw exception;
            }
            if (!string.IsNullOrWhiteSpace(password))
            {
                emp.SetSecurePass(password);
            }
            emp.NewName    = userName;
            emp.Permission = suppliedPerm;
            int id = Mgr.UpdateEmployee(emp);

            return(id);
        }
Beispiel #2
0
        /// <summary>
        /// Check if the information provided by view is valid and if it is:
        /// create an employee and send back it's id
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="confPass"></param>
        /// <param name="permission"></param>
        public int Create(
            string userName,
            string password,
            string confPass,
            string permission)
        {
            // trim any whitespace that can come up with winforms
            userName   = userName.Trim();
            password   = password.Trim();
            confPass   = confPass.Trim();
            permission = permission.Trim();
            var perm     = Permission.None;
            var employee = new Employee();
            // if there is an exception with creating the account
            CreationException except = new CreationException();

            switch (permission)
            {
            case "Plan Admin":
                perm = Permission.PlanAdmin;
                break;

            case "Enrollee Support":
                perm = Permission.EnrolleeSupport;
                break;

            case "HSP Support":
                perm = Permission.HSPSupport;
                break;

            case "Accountant":
                perm = Permission.Accountant;
                break;

            case "Manager":
                perm = Permission.Manager;
                break;

            default:
                var msg     = "Invalid permission";
                var caption = "You pick a permission that wasn't Manager, " +
                              "Accountant, HSP Support, Enrollee Support, or Plan " +
                              "Administrator";
                except.AddError(msg, caption);
                break;
            } // switch on Permission


            var validPass = employee.ValidPass(password, confPass, except);
            var validUser = employee.ValidUser(userName, except);

            if (except.IsProblem)
            {
                throw except;
            }

            employee.UserName = userName;
            employee.SetSecurePass(password);
            employee.Permission = perm;
            return(Mgr.SaveEmployee(employee));
        }