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); }
internal ApiResult UpdateChangeRequestStatus(ApproverForChangeRequest link) { ApiResult apiResult = new ApiResult(); try { if (!link.IsValidUpdate()) { apiResult.SetFailuresAsStatusInResponseFields(link.StatusDesc); return(apiResult); } ApproverForChangeRequest old = ApproverForChangeRequest.QueryWithStoredProc("GetApproverToChangeRequest", link.ApproverId, link.ChangeRequestId).FirstOrDefault(); if (old == null) { link.Save(); } else { old.Decision = link.Decision; old.Reason = link.Reason; old.Save(); } apiResult.SetSuccessAsStatusInResponseFields(); return(apiResult); } catch (Exception ex) { HandleError(nameof(UpdateChangeRequestStatus), "EXCEPTION", ex.Message); apiResult.SetFailuresAsStatusInResponseFields(ex.Message); } return(apiResult); }
public void UpdateChangeRequestStatusTest_InvalidParameters() { ChangeRequestInterface api = new CRSubSystemAPI(); ChangeRequest changeRequest = new ChangeRequest(); ApproverForChangeRequest link = new ApproverForChangeRequest(); ApiResult result = api.UpdateChangeRequestStatus(link); Assert.AreEqual(Globals.FAILURE_STATUS_CODE, result.StatusCode); }
public void AssignChangeRequestToApproverTest() { ChangeRequestInterface api = new CRSubSystemAPI(); ApproverForChangeRequest link = new ApproverForChangeRequest(); link.ChangeRequestId = "1234"; link.Decision = ""; link.Reason = ""; link.ApproverId = "*****@*****.**"; ApiResult result = api.AssignChangeRequestToApprover(link); Assert.AreEqual(Globals.SUCCESS_STATUS_TEXT, result.StatusDesc); }
public static void Main(string[] args) { CRSubSystemAPI.Initialize(); ChangeRequestInterface api = new CRSubSystemAPI(); ApproverForChangeRequest link = new ApproverForChangeRequest { ChangeRequestId = "12345", Decision = "APPROVED", Reason = "APPROVED", ApproverId = "*****@*****.**" }; ApiResult result = api.UpdateChangeRequestStatus(link); Console.Read(); }
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); }
protected void btnSubmit_Click(object sender, EventArgs e) { try { ApproverForChangeRequest attachment = new ApproverForChangeRequest(); attachment.ChangeRequestId = Request.QueryString["Id"]; attachment.CreatedBy = (Session["User"] as SystemUser)?.Username; attachment.CreatedOn = DateTime.Now; attachment.ModifiedBy = (Session["User"] as SystemUser)?.Username; attachment.ModifiedOn = DateTime.Now; attachment.Decision = "PENDING"; attachment.Reason = "PENDING"; attachment.ApproverId = ddNameOfApprover.SelectedValue; attachment.Role = ddTypeOfApprover.SelectedValue; ApiResult apiResult = BussinessLogic.cRSystemAPIClient.AssignChangeRequestToApprover(attachment); if (apiResult.StatusCode != Globals.SUCCESS_STATUS_CODE) { //Show Error Message string msg = "ERROR:" + apiResult.StatusDesc; Master.ErrorMessage = msg; return; } DataTable dt = BussinessLogic.cRSystemAPIClient.ExecuteDataSet("GetApproversByChangeRequestId", new object[] { attachment.ChangeRequestId }).Tables[0]; dataGridResults.DataSource = dt; dataGridResults.DataBind(); } catch (Exception ex) { //Show Error Message string msg = "ERROR:" + ex.Message; Master.ErrorMessage = msg; return; } }
public void SendApproveCrEmailTest() { ChangeRequestInterface api = new CRSubSystemAPI(); ChangeRequest changeRequest = new ChangeRequest(); changeRequest.ApprovalStatus = "PENDING"; changeRequest.ApprovalReason = ""; changeRequest.ChangeCategoryId = "EMERGENCY_CHANGE"; changeRequest.ChangeRequestId = DateTime.Now.Ticks.ToString(); changeRequest.ChangeEndDateTime = DateTime.Now; changeRequest.ChangeStartDateTime = DateTime.Now; changeRequest.ImpactOfNotImplementing = "Bad Stuff"; changeRequest.ImplementerCompany = "Pegasus"; changeRequest.ImplementerEmail = "*****@*****.**"; changeRequest.ImplementerName = "kasozi"; changeRequest.ImplementerPhone = "0785975800"; changeRequest.Justification = "We need to do this"; changeRequest.RequesterCompany = "Stanbic"; changeRequest.RequesterEmail = "*****@*****.**"; changeRequest.RequesterName = "Damalie"; changeRequest.RequesterPhone = "0785975800"; changeRequest.Title = "Changing Transaction Status"; changeRequest.Problem = "Pegasus server 192.168.55.3 wishes to access UTL airtime listening on URL http://172.25.100.6/atpurchase.php in order to be able to send Airtime Top Up requests for UTL phone numbers"; changeRequest.Solution = "Creation of UTL VPN"; changeRequest.Save(); ApproverForChangeRequest systemAffected = new ApproverForChangeRequest(); systemAffected.ChangeRequestId = changeRequest.ChangeRequestId; systemAffected.ApproverId = "nsubugak"; string ApproveURL = ""; ApiResult result = api.SendApproveCrEmail(systemAffected); Assert.AreEqual(Globals.SUCCESS_STATUS_TEXT, result.StatusDesc); }
internal ApiResult ApproveChangeRequest(string UserId, string ChangeRequestId, string Decision, string Reason) { ApiResult apiResult = new ApiResult(); try { //look for the Approver based on the CR Id ApproverForChangeRequest old = ApproverForChangeRequest.QueryWithStoredProc("GetApproverByID", UserId, ChangeRequestId, "").FirstOrDefault(); //Approver not found. This guy is hacking this shit if (old == null) { apiResult.SetFailuresAsStatusInResponseFields($"NOT ABLE TO FIND CR {ChangeRequestId} FOR APPROVER {UserId}"); return(apiResult); } //save the decision made old.Decision = Decision; old.Reason = Reason; old.Save(); //automatically set the success fields //here SUCCESS simply means we have logged their response successfully apiResult.SetSuccessAsStatusInResponseFields(); apiResult.StatusDesc = "SUCCESS: YOUR DECISION HAS BEEN SAVED SUCCESFULLY"; //this dude has rejected the CR if (Decision == "REJECTED") { //inform the requestor asynchronously Task.Factory.StartNew(() => { InformRequestorOfCrOutCome(ChangeRequestId); }); return(apiResult); } //check if there is someone else left to approve ApproverForChangeRequest[] pending = ApproverForChangeRequest.QueryWithStoredProc("GetPendingApprovers"); //no one else is left to approve if (pending.Length == 0) { //inform the requestor asynchronously Task.Factory.StartNew(() => { InformRequestorOfCrOutCome(ChangeRequestId); }); return(apiResult); } return(apiResult); } catch (Exception ex) { HandleError(nameof(AssignApproverToChangeRequest), "EXCEPTION", ex.Message); apiResult.SetFailuresAsStatusInResponseFields(ex.Message); } return(apiResult); }
public ApiResult AssignChangeRequestToApprover(ApproverForChangeRequest link) => cRSubSystemAPI.AssignChangeRequestToApprover(link);
public ApiResult UpdateChangeRequestStatus(ApproverForChangeRequest link) => cRSubSystemAPI.UpdateChangeRequestStatus(link);
public static ApiResult SendApproveCrEmail(ApproverForChangeRequest link) { ApiResult result = new ApiResult(); try { SystemUser approver = SystemUser.QueryWithStoredProc("GetSystemUserById", link.ApproverId).FirstOrDefault(); if (approver == null) { result.StatusCode = Globals.FAILURE_STATUS_CODE; result.StatusDesc = $"USER WITH THE APPROVER ID {link.ApproverId} WAS NOT FOUND"; return(result); } ChangeRequest changeRequest = ChangeRequest.QueryWithStoredProc("GetChangeRequestById", link.ChangeRequestId).FirstOrDefault(); if (changeRequest == null) { result.StatusCode = Globals.FAILURE_STATUS_CODE; result.StatusDesc = $"CHANGE REQUEST WITH THE ID {link.ChangeRequestId} WAS NOT FOUND"; return(result); } string filePath = SystemSetting.QueryWithStoredProc("GetSystemSettingById", Globals.FILE_PATH_TO_APPROVE_CR_EMAIL_TEMPLATE).FirstOrDefault()?.SettingValue; if (filePath == null) { result.StatusCode = Globals.FAILURE_STATUS_CODE; result.StatusDesc = $"{nameof(Globals.FILE_PATH_TO_APPROVE_CR_EMAIL_TEMPLATE)} NOT FOUND"; return(result); } string ApproveURL = SystemSetting.QueryWithStoredProc("GetSystemSettingById", Globals.APPROVE_CR_URL).FirstOrDefault()?.SettingValue; if (ApproveURL == null) { result.StatusCode = Globals.FAILURE_STATUS_CODE; result.StatusDesc = $"{nameof(Globals.APPROVE_CR_URL)} NOT FOUND"; return(result); } string msg = File.ReadAllText(filePath); string dateFormat = "yyyy-MM-dd HH:mm"; msg = msg.Replace("[APPROVER_NAME]", approver.Username); msg = msg.Replace("[TITLE]", changeRequest.Title); msg = msg.Replace("[CURRENT_PROBLEM]", changeRequest.Problem); msg = msg.Replace("[PROPOSED_SOLUTION]", changeRequest.Solution); msg = msg.Replace("[CHANGE_CATEGORY]", changeRequest.ChangeCategoryId); msg = msg.Replace("[JUSTIFICATION]", changeRequest.Justification); msg = msg.Replace("[IMPACT]", changeRequest.ImpactOfNotImplementing); msg = msg.Replace("[REQUESTOR_NAME]", changeRequest.RequesterName); msg = msg.Replace("[REQUESTOR_EMAIL]", changeRequest.RequesterEmail); msg = msg.Replace("[REQUESTOR_PHONE]", changeRequest.RequesterPhone); msg = msg.Replace("[REQUESTOR_COMPANY]", changeRequest.RequesterCompany); msg = msg.Replace("[IMPLEMENTER_NAME]", changeRequest.ImplementerName); msg = msg.Replace("[IMPLEMENTER_EMAIL]", changeRequest.ImplementerEmail); msg = msg.Replace("[IMPLEMENTER_PHONE]", changeRequest.ImplementerPhone); msg = msg.Replace("[START_DATE]", changeRequest.ChangeStartDateTime.ToString(dateFormat)); msg = msg.Replace("[END_DATE]", changeRequest.ChangeEndDateTime.ToString(dateFormat)); msg = msg.Replace("[APPROVE_URL]", ApproveURL); msg = msg.Replace("[USER_ID]", link.ApproverId); msg = msg.Replace("[CR_ID]", changeRequest.ChangeRequestId); MailMessage mail = new MailMessage(Globals.FROM_EMAIL, approver.Email); SmtpClient client = new SmtpClient(); client.Port = 587; client.Host = Globals.SMPTP_SERVER; client.EnableSsl = true; client.Timeout = 10000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(Globals.SMTP_USERNAME, Globals.SMTP_PASSWORD); mail.Subject = Globals.MAIL_SUBJECT_APPROVE_CR_EMAIL; mail.Body = msg; mail.IsBodyHtml = true; client.Send(mail); result.StatusCode = Globals.SUCCESS_STATUS_CODE; result.StatusDesc = Globals.SUCCESS_STATUS_TEXT; } catch (Exception ex) { result.StatusCode = Globals.FAILURE_STATUS_CODE; result.StatusDesc = "EXCEPTION: " + ex.Message; return(result); } return(result); }
public ApiResult AssignChangeRequestToApprover(ApproverForChangeRequest link) => bll.AssignApproverToChangeRequest(link);
public ApiResult UpdateChangeRequestStatus(ApproverForChangeRequest link) => bll.UpdateChangeRequestStatus(link);
public ApiResult SendApproveCrEmail(ApproverForChangeRequest link) => NotificationsHandler.SendApproveCrEmail(link);