Exemple #1
0
        private ApiResult InformRequestorOfCrOutCome(string changeRequestId)
        {
            ApiResult apiResult = new ApiResult();

            try
            {
                ChangeRequest cr = ChangeRequest.QueryWithStoredProc("GetChangeRequestById", changeRequestId)[0];

                ApproverForChangeRequest[] pending = ApproverForChangeRequest.QueryWithStoredProc("CheckForCRRejection", changeRequestId);

                //Someone has rejected the Change Rejected
                if (pending.Length != 0)
                {
                    cr.ApprovalStatus = pending[0].Decision;
                    cr.ApprovalReason = $"CR NOT APPROVED BY APPROVER {pending[0].ApproverId}. Reason: {pending[0].Reason}";
                    cr.Save();
                    apiResult = NotificationsHandler.SendCrRejectedEmail(cr, cr.ApprovalReason);
                    return(apiResult);
                }

                cr.ApprovalStatus = "APPROVED";
                cr.ApprovalReason = "APPROVED BY EVERY APPROVER";
                cr.Save();
                apiResult = NotificationsHandler.SendCrApprovedEmail(cr);
                return(apiResult);
            }
            catch (Exception ex)
            {
                apiResult.StatusCode = Globals.FAILURE_STATUS_CODE;
                apiResult.StatusDesc = "EXCEPTION: " + ex.Message;
            }
            return(apiResult);
        }
Exemple #2
0
        private ApiResult InformRequestorOfTbarOutCome(string tbarID)
        {
            ApiResult apiResult = new ApiResult();

            try
            {
                TimeBoundAccessRequest tbar = TimeBoundAccessRequest.QueryWithStoredProc("GetTbarById2", tbarID)[0];

                if (tbar.Status == "APPROVED")
                {
                    apiResult = NotificationsHandler.SendTbarApprovedEmail(tbar);
                }
                else if (tbar.Status == "REJECTED")
                {
                    apiResult = NotificationsHandler.SendTbarRejectedEmail(tbar, tbar.ApproverReason);
                }

                apiResult.SetSuccessAsStatusInResponseFields();
                return(apiResult);
            }
            catch (Exception ex)
            {
                apiResult.StatusCode = Globals.FAILURE_STATUS_CODE;
                apiResult.StatusDesc = "EXCEPTION: " + ex.Message;
            }
            return(apiResult);
        }
Exemple #3
0
        internal ApiResult SendOneTimePIN(string username, string MethodOfSending)
        {
            ApiResult apiResult = new ApiResult();

            try
            {
                //Thread.Sleep(new TimeSpan(0, 1, 0));
                if (string.IsNullOrEmpty(username))
                {
                    apiResult.StatusCode = Globals.FAILURE_STATUS_CODE;
                    apiResult.StatusDesc = $"Please Supply a Username";
                    return(apiResult);
                }
                if (!Globals.AcceptableMethodsOfSendingOTP.Contains(MethodOfSending.ToUpper()))
                {
                    apiResult.StatusCode = Globals.FAILURE_STATUS_CODE;
                    apiResult.StatusDesc = $"Please Specify how you want to recieve the OTP";
                    return(apiResult);
                }

                SystemUser[] systemUsers = SystemUser.QueryWithStoredProc("GetSystemUserByID", username);

                if (systemUsers.Count() <= 0)
                {
                    apiResult.StatusCode = Globals.FAILURE_STATUS_CODE;
                    apiResult.StatusDesc = $"User with Username [{username}] doesnt exist";
                    return(apiResult);
                }

                SystemUser user = systemUsers[0];

                OneTimePassword oneTimePassword = new OneTimePassword();
                oneTimePassword.CompanyCode = user.CompanyCode;
                oneTimePassword.Password    = "******";
                oneTimePassword.ValidityDurationInSeconds = 5 * 60;
                oneTimePassword.Username = user.Username;
                oneTimePassword.Save();


                ApiResult sendResult = MethodOfSending.ToUpper() == "PHONE" ? NotificationsHandler.SendOneTimePINByPhone(user.PhoneNumber, oneTimePassword.Password) : NotificationsHandler.SendOneTimePINByEmail(user.Email, oneTimePassword.Password);


                if (sendResult.StatusCode != Globals.SUCCESS_STATUS_CODE)
                {
                    apiResult.StatusCode = Globals.FAILURE_STATUS_CODE;
                    apiResult.StatusDesc = "Send One Time PIN failed: " + sendResult.StatusDesc;
                    return(apiResult);
                }

                apiResult.StatusCode = Globals.SUCCESS_STATUS_CODE;
                apiResult.StatusDesc = $"Successfully Sent One time Password by {MethodOfSending} to {sendResult.PegPayID}. Its Valid for {oneTimePassword.ValidityDurationInSeconds / 60} minute(s)";
                return(apiResult);
            }
            catch (Exception ex)
            {
                apiResult = HandleException(nameof(SendOneTimePIN), $"{username}, Error:{ex.Message}", ex);
            }
            return(apiResult);
        }
Exemple #4
0
        internal ApiResult SaveTimeBoundAccessRequest(TimeBoundAccessRequest req)
        {
            ApiResult apiResult = new ApiResult();

            try
            {
                if (!req.IsValid())
                {
                    apiResult.SetFailuresAsStatusInResponseFields(req.StatusDesc);
                    return(apiResult);
                }

                req.Save();

                if (req.Status != "PENDING")
                {
                    apiResult.PegPayID = req.Id.ToString();
                    apiResult.SetSuccessAsStatusInResponseFields();
                    return(apiResult);
                }

                ApiResult sendResult = NotificationsHandler.SendApproveTbarEmail(req);

                if (sendResult.StatusCode != Globals.SUCCESS_STATUS_CODE)
                {
                    apiResult.PegPayID = req.Id.ToString();
                    apiResult.SetFailuresAsStatusInResponseFields("FAILED TO SEND EMAIL TO APPROVER: " + sendResult.StatusDesc);
                    return(apiResult);
                }


                apiResult.SetSuccessAsStatusInResponseFields();
            }
            catch (Exception ex)
            {
                HandleError(nameof(AttachSystemAffectedToChangeRequest), "EXCEPTION", ex.Message);
                apiResult.SetFailuresAsStatusInResponseFields(ex.Message);
            }
            return(apiResult);
        }
Exemple #5
0
        internal ApiResult AssignApproverToChangeRequest(ApproverForChangeRequest link)
        {
            ApiResult apiResult = new ApiResult();

            try
            {
                link.HasEmailBeenSent = false;
                if (!link.IsValid())
                {
                    apiResult.SetFailuresAsStatusInResponseFields(link.StatusDesc);
                    return(apiResult);
                }

                ApproverForChangeRequest old = ApproverForChangeRequest.QueryWithStoredProc("GetApproverByID", link.ApproverId, link.ChangeRequestId, link.Role).FirstOrDefault();

                link.Id = old != null ? old.Id : link.Id;
                link.Save();


                ApiResult sendResult = NotificationsHandler.SendApproveCrEmail(link);

                if (sendResult.StatusCode != Globals.SUCCESS_STATUS_CODE)
                {
                    apiResult.PegPayID = link.Id.ToString();
                    apiResult.SetFailuresAsStatusInResponseFields("FAILED TO SEND EMAIL TO APPROVER: " + sendResult.StatusDesc);
                    return(apiResult);
                }

                apiResult.PegPayID = link.Id.ToString();
                apiResult.SetSuccessAsStatusInResponseFields();
                return(apiResult);
            }
            catch (Exception ex)
            {
                HandleError(nameof(AssignApproverToChangeRequest), "EXCEPTION", ex.Message);
                apiResult.SetFailuresAsStatusInResponseFields(ex.Message);
            }
            return(apiResult);
        }
 public ApiResult SendApproveTbarEmail(TimeBoundAccessRequest tbar) => NotificationsHandler.SendApproveTbarEmail(tbar);
 public ApiResult SendApproveCrEmail(ApproverForChangeRequest link) => NotificationsHandler.SendApproveCrEmail(link);