Esempio n. 1
0
        public IHttpActionResult Post(ApprovalInfo approval)
        {
            if (approval == null)
            {
                throw new ArgumentNullException("approval");
            }

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

            return NotFound();
        }
Esempio n. 2
0
        private IHttpActionResult ApproveOrReject(ApprovalInfo approval, ApprovalMemberResults approvalType)
        {
            try
            {
                var actions = DynamicTypeManager.GetInfoListById<IInfoList>(Constants.ActionItemsProcessName, approval.ActionId);
                var action = actions.Cast<IActionItemInfo>().FirstOrDefault();

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

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

                var approveCommandResult = UpdateApprovalMemberResultCommand.Execute(approval.ActionId, approvalType, approval.Comments);
                if (approveCommandResult.IsSuccessful)
                {
                    return Ok(new { Success = true, ActionId = approval.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." });
            }
        }