Пример #1
0
        public IHttpActionResult Post(ActionApprovalInfo actionApproval)
        {
            if (actionApproval == null)
            {
                throw new ArgumentNullException("actionApproval");
            }

            switch (actionApproval.ActionType)
            {
                case "approve":
                    return ApproveOrReject(actionApproval, ApprovalMemberResults.Approved);
                case "reject":
                    return ApproveOrReject(actionApproval, ApprovalMemberResults.Rejected);
                case "acknowledge":
                    return Acknowledge(actionApproval.ActionId);
            }

            return NotFound();
        }
Пример #2
0
        private IHttpActionResult ApproveOrReject(ActionApprovalInfo actionApproval, ApprovalMemberResults approvalType)
        {
            try
            {
                var actions = DynamicTypeManager.GetInfoListById<IInfoList>(Constants.ActionItemsProcessName, actionApproval.ActionId);
                var action = actions.Cast<IActionItemInfo>().FirstOrDefault();

                if (action == null)
                {
                    return Ok(new { Success = false, Message = "Action not found" });
                }

                var authenticationResult = AuthenticateUserCommand.Execute(actionApproval.UserName, actionApproval.Password, Utils.CurrentUserPersonId);
                if (authenticationResult.AuthenticationResult != LoginStatuses.Success)
                {
                    return Ok(new { Success = false, Message = "Authentication failed" });
                }

                var approveCommandResult = UpdateApprovalMemberResultCommand.Execute(actionApproval.ActionId, approvalType, actionApproval.Comments);
                if (approveCommandResult.IsSuccessful)
                {
                    return Ok(new { Success = true, ActionId = actionApproval.ActionId });
                }

                var errorMessage = !string.IsNullOrEmpty(approveCommandResult.ErrorMessage)
                                       ? approveCommandResult.ErrorMessage
                                       : "There was an error with this action, please try to refresh and repeat";

                return Ok(new { Success = false, Message = errorMessage });
            }
            catch (Exception ex)
            {
                Logger.Log(LogSeverity.Error, "Approve", ex.ToString());
                return Ok(new { Success = false, Message = "There was an error with this action, please try to refresh and repeat." });
            }
        }