private static async Task <bool> CmdSaveEmailedCode(TSEmailedCode ParEmailedCode) { bool result = true; try { bool b = await TS.DeleteExpiredEmaiedCodes(); b = await TS.DeleteEmaiedCodes(ParEmailedCode.Email); result = await TS.AddEmailedCode(ParEmailedCode); } catch (Exception ex) { await TS.AddErrorLog("AllUsers", ex.Message, MethodBase.GetCurrentMethod()); result = false; } return(result); }
public static async Task <TSEmail> SendEmail(TSEmail ParTSEmail, string ParIPAddress, string ParMachineID) { var attr = new EmailAddressAttribute(); if (!attr.IsValid(ParTSEmail.To)) { ParTSEmail.Result = "Error:Email format is not valid!"; return(ParTSEmail); } if (ParTSEmail.To.ToLower().Equals("*****@*****.**")) { ParTSEmail.Result = "Error:Can't sent any email to demo user!"; return(ParTSEmail); } bool MustSaveEmailedCode = false; EmailOperationsEnum tmp_Operation = (EmailOperationsEnum)ParTSEmail.OperationCode; string tmp_Code = string.Empty; switch (tmp_Operation) { case EmailOperationsEnum.Registration: tmp_Code = GetSalt(); if (CmdSendEmail(ParTSEmail.To.Trim(), "Registration", "Hello,\n\nYour code is " + tmp_Code + "\nThank you for registration.\n\nBest Regards,\nSite Administration").Result) { ParTSEmail.Result = "OK"; MustSaveEmailedCode = true; } else { ParTSEmail.Result = "Error"; MustSaveEmailedCode = false; } break; case EmailOperationsEnum.EmailChange: tmp_Code = GetSalt(); if (CmdSendEmail(ParTSEmail.To.Trim(), "Email change", "Hello,\n\nYour code is " + tmp_Code + "\n\nBest Regards,\nSite Administration").Result) { ParTSEmail.Result = "OK"; MustSaveEmailedCode = true; } else { ParTSEmail.Result = "Error"; MustSaveEmailedCode = false; } break; case EmailOperationsEnum.PasswordChange: tmp_Code = GetSalt(); if (CmdSendEmail(ParTSEmail.To.Trim(), "Password change", "Hello,\n\nYour code is " + tmp_Code + "\n\nBest Regards,\nSite Administration").Result) { ParTSEmail.Result = "OK"; MustSaveEmailedCode = true; } else { ParTSEmail.Result = "Error"; MustSaveEmailedCode = false; } break; case EmailOperationsEnum.PasswordRecovery: MustSaveEmailedCode = false; if (CmdSendEmail(ParTSEmail.To.Trim(), "Password Recovery", "Hello,\n\nYour new password is " + ParMachineID + "\n\nPlease change password after login.\n\nBest Regards,\nSite Administration").Result) { ParTSEmail.Result = "OK"; } else { ParTSEmail.Result = "Error"; } break; case EmailOperationsEnum.TodoReminder: MustSaveEmailedCode = false; if (CmdSendEmail(ParTSEmail.To.Trim(), "Todo Reminder", "Hello,\n\nYour requested todo remind is here.\n\n" + ParMachineID + "\n\nBest Regards,\nSite Administration").Result) { ParTSEmail.Result = "OK"; } else { ParTSEmail.Result = "Error"; } break; default: break; } if (MustSaveEmailedCode) { TSEmailedCode tsEmailedCode = new TSEmailedCode { Email = ParTSEmail.To.Trim(), Code = tmp_Code, IPAddress = ParIPAddress, OperationType = ParTSEmail.OperationCode, MachineID = ParMachineID }; await CmdSaveEmailedCode(tsEmailedCode); } return(ParTSEmail); }