Exemplo n.º 1
0
        public static bool AllowableAction(SubmissionAction action, Enrollee enrollee, bool asAdmin)
        {
            enrollee.ThrowIfNull(nameof(enrollee));
            if (enrollee.CurrentStatus == null)
            {
                throw new ArgumentException("Enrollee must have a CurrentStatus", nameof(enrollee));
            }

            var status = enrollee.CurrentStatus.GetStatusType();

            return((status, action) switch
            {
                (StatusType.Editable, SubmissionAction.LockProfile) => asAdmin,
                (StatusType.Editable, SubmissionAction.DeclineProfile) => asAdmin,

                (StatusType.UnderReview, SubmissionAction.Approve) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.EnableEditing) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.LockProfile) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.DeclineProfile) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.RerunRules) => asAdmin,

                (StatusType.RequiresToa, SubmissionAction.AcceptToa) => !asAdmin,
                (StatusType.RequiresToa, SubmissionAction.DeclineToa) => !asAdmin,
                (StatusType.RequiresToa, SubmissionAction.EnableEditing) => asAdmin,
                (StatusType.RequiresToa, SubmissionAction.LockProfile) => asAdmin,
                (StatusType.RequiresToa, SubmissionAction.DeclineProfile) => asAdmin,

                (StatusType.Locked, SubmissionAction.EnableEditing) => asAdmin,
                (StatusType.Locked, SubmissionAction.DeclineProfile) => asAdmin,

                (StatusType.Declined, SubmissionAction.EnableEditing) => asAdmin,

                _ => false
            });
        private static EnrolleeState FromEnrollee(Enrollee enrollee)
        {
            enrollee.ThrowIfNull(nameof(enrollee));
            if (enrollee.CurrentStatus == null)
            {
                throw new ArgumentException("Enrollee must have a CurrentStatus", nameof(enrollee));
            }

            switch (enrollee.CurrentStatus.GetStatusType())
            {
            case StatusType.Editable:
                return(EnrolleeState.Editable);

            case StatusType.UnderReview:
                return(EnrolleeState.UnderReview);

            case StatusType.RequiresToa:
                return(EnrolleeState.RequiresToa);

            case StatusType.Locked:
                return(EnrolleeState.Locked);

            case StatusType.Declined:
                return(EnrolleeState.Declined);

            default:
                throw new ArgumentException($"State machine cannot recognize status code {enrollee.CurrentStatus.StatusCode}");
            }
        }