private bool Sms(CAR_USER_VIEW user, string body) { // This is a trial twilio Account to test string accountSid = "ACa87fbb932f84a58fa90e92ad8a9e0bdf"; string authToken = "0ed0016760b2631d2f1dc7ff78213a84"; string testFromPhoneNumber = "+15005550006"; TwilioClient.Init(accountSid, authToken); List <string> personalAndWork = GetUsersToSendsms(user); foreach (string personalOrWork in personalAndWork) { var message = MessageResource.Create( to: new PhoneNumber(personalOrWork), @from: new PhoneNumber(testFromPhoneNumber), body: body ); if (message.ErrorCode != null || message.ErrorMessage != null) { string error = $"Error Sending SMS with Error Code: {message.ErrorCode} & Error Message: {message.ErrorMessage}"; return(false); } Console.WriteLine(message.Sid); } return(true); }
private void OnSendtoEmployeeNoBlocked(CAR_USER_VIEW carUserBlocker, car_request req = null) { EmailSmsEventNoBlocked?.Invoke(this, new EmailSmsNoBlockedEventArgs() { CarUserBlocker = carUserBlocker, Req = req }); }
public static string MsgToCarBlocked(CAR_USER_VIEW caruserBlocker) { if (caruserBlocker.PERSONAL_MOBILE == caruserBlocker.WORK_MOBILE) { return ($"Your car blocker details: {caruserBlocker.EMPLOYEE_NAME} \n " + $"{caruserBlocker.EMAIL} \n Dept: {caruserBlocker.DEPARTMENT} \n Work Number: {caruserBlocker.EXTENSION} \n Manager: {caruserBlocker.MANAGER_NAME}"); } return ($"Your car blocker details: {caruserBlocker.EMPLOYEE_NAME} \n {caruserBlocker.EMAIL} \n " + $"Dept: {caruserBlocker.DEPARTMENT} \n Work Number: {caruserBlocker.EXTENSION} \n Work Mobile:{caruserBlocker.WORK_MOBILE} \n Manager: {caruserBlocker.MANAGER_NAME}"); }
public static string MsgToCarBlocker(CAR_USER_VIEW caruserBlocked) { if (caruserBlocked.PERSONAL_MOBILE == caruserBlocked.WORK_MOBILE) { return ($"Please move your car, you are blocking : {caruserBlocked.EMPLOYEE_NAME} \n " + $"{caruserBlocked.EMAIL} \n Dept: {caruserBlocked.DEPARTMENT} \n Work Number: {caruserBlocked.EXTENSION}"); } return ($"Please move your car, you are blocking : {caruserBlocked.EMPLOYEE_NAME} \n " + $"{caruserBlocked.EMAIL} \n Dept: {caruserBlocked.DEPARTMENT} \n Work Number: {caruserBlocked.EXTENSION} \n Work Mobile:{caruserBlocked.WORK_MOBILE}"); }
private static List <string> GetUsersToSendsms(CAR_USER_VIEW user) { List <string> personalAndWork = new List <string>(); if (user.PERSONAL_MOBILE == user.WORK_MOBILE) { string personalMobileUpdated = user.PERSONAL_MOBILE; //Check if the number begins with "00" , and replace with "+" if (personalMobileUpdated.Substring(0, 2) == "00") { personalMobileUpdated = "+" + user.PERSONAL_MOBILE.Substring(2); } personalAndWork.Add(personalMobileUpdated); } else { string personalMobileUpdated = user.PERSONAL_MOBILE; string workMobileUpdated = user.WORK_MOBILE; //Check if the number begins with "00" , and replace with "+" if (personalMobileUpdated.Substring(0, 2) == "00") { personalMobileUpdated = "+" + user.PERSONAL_MOBILE.Substring(2); } if (workMobileUpdated.Substring(0, 2) == "00") { workMobileUpdated = "+" + user.WORK_MOBILE.Substring(2); } personalAndWork.Add(personalMobileUpdated); personalAndWork.Add(workMobileUpdated); } return(personalAndWork); }
public void Execute() { while (_mysqlRep.TestMySqlConnection() == false || _oracleRep.TestOracleConnection() == false) { if (_mysqlRep.TestMySqlConnection() == false) { Logger.Info("Cannot Access MySQL Database"); } else { Logger.Info("Cannot Access Oracle Database"); } Thread.Sleep(5000); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); foreach (car_request req in _mysqlRep.OpenCases()) { try { CAR_USER_VIEW carUserBlocked = _oracleRep.CarUserBlocked(req?.CAR_USERNAME); List <CAR_USER_VIEW> carUserBlockers = _oracleRep.CarUserBlockers(req?.PLATE_NUMBER); _mysqlRep.ChangeStatus(req, "INPROGRESS"); if (carUserBlockers?.Count >= 1 && carUserBlocked?.EMAIL != null) { // Apply the "ChangeUserWorkExtensionToFullPhone" Method for all users found first carUserBlocked.EXTENSION = ChangeUserWorkExtensionToFullPhone(carUserBlocked.EXTENSION); foreach (CAR_USER_VIEW caruserBlocker in carUserBlockers) { if (caruserBlocker.EMAIL != null) { caruserBlocker.EXTENSION = ChangeUserWorkExtensionToFullPhone(caruserBlocker.EXTENSION); OnSendtoEmployee(caruserBlocker, carUserBlocked); Logger.Info($"Request N {req?.ID} Blocked: {carUserBlocked?.EMAIL} Blocker: {caruserBlocker?.EMAIL} "); //Notification(); //add log to Oracle _oracleRep.OracleTransactionLog(carUserBlocked, caruserBlocker, req); } } } else if ((carUserBlockers.Count < 1 || carUserBlockers == null) && carUserBlocked?.EMAIL != null) { carUserBlocked.EXTENSION = ChangeUserWorkExtensionToFullPhone(carUserBlocked?.EXTENSION); OnSendtoEmployeeNoBlocker(carUserBlocked, req); Logger.Info($"Request N {req?.ID} Blocked: {carUserBlocked?.EMAIL} "); } // blocked user not found -- what the hell case !! else if (carUserBlocked?.EMAIL == null && carUserBlockers?.Count >= 1) { SendEmailandSms sendemail = new SendEmailandSms(); // this email is sent to admin, to enform him that there is a blocked user with no database record ! sendemail.Email("*****@*****.**", $"Hi yehia, Case ID is :{req?.ID}", "Blocked Car App - Cannot find the Blocked User - Admin Mail"); foreach (CAR_USER_VIEW caruserBlocker in carUserBlockers) { caruserBlocker.EXTENSION = ChangeUserWorkExtensionToFullPhone(caruserBlocker?.EXTENSION); OnSendtoEmployeeNoBlocked(caruserBlocker, req); Logger.Info($"Request N {req?.ID} Blocker: {caruserBlocker?.EMAIL} "); //Notification(); //add log to Oracle _oracleRep.OracleTransactionLog(null, caruserBlocker, req); } } // Both blocked user and Blockers not found -- what the hell case !! else if ((carUserBlockers.Count < 1 || carUserBlockers == null) && carUserBlocked?.EMAIL == null) { _mysqlRep.ChangeStatus(req, "BlockedandBlockerNF"); return; } // Unknown or unpredictable Case ! else { _mysqlRep.ChangeStatus(req, "BlockedandBlockerNF"); return; } _mysqlRep.ChangeStatus(req, "RESOLVED"); } catch (Exception ex) { Logger.Error($"{req?.ID} {ex?.Message} {ex?.InnerException} {ex?.StackTrace}"); //_mysqlRep.ChangeStatus(req, "OPEN"); SendEmailandSms sendemail = new SendEmailandSms(); sendemail.Email("*****@*****.**", $"{ex.Message} {ex.InnerException} {ex.StackTrace}", "General Exception"); } } stopwatch.Stop(); }