SMS-utskick har lagts till

This commit is contained in:
2020-04-22 23:00:34 +02:00
parent ac1d5371f2
commit f7d8e2a049
6 changed files with 112 additions and 33 deletions

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
namespace TrackerLibrary
{
public class SMSLogic
{
public static void SendSMSMessage(string to, string textMessage)
{
string accountSid = GlobalConfig.AppKeyLookup("smsAccountSid");
string authToken = GlobalConfig.AppKeyLookup("smsAuthToken");
string fromPhoneNumber = GlobalConfig.AppKeyLookup("smsFromPhoneNumber");
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
to: new PhoneNumber(to),
from: new PhoneNumber(fromPhoneNumber),
body: textMessage
);
}
}
}

View File

@ -73,38 +73,43 @@ namespace TrackerLibrary
private static void AlertPersonToNewRound(PersonModel p, string teamName, MatchupEntryModel competitor)
{
if (p.EmailAddress.Length == 0)
if (p.EmailAddress.Length > 0)
{
return;
string subject;
StringBuilder body = new StringBuilder();
if (competitor != null)
{
subject = $"You have a new matchup with {competitor.TeamCompeting.TeamName}";
body.AppendLine("<h1>You Have a new matchup</h1>");
body.Append("<strong>Competitor: </strong>");
body.Append(competitor.TeamCompeting.TeamName);
body.AppendLine();
body.AppendLine();
body.AppendLine("Have a great time!");
body.AppendLine("~Tournament Tracker");
}
else
{
subject = "You have a bye week this round";
body.AppendLine("Enjoy your round off!");
body.AppendLine("~Tournament Tracker");
}
string to = p.EmailAddress;
EmailLogic.SendEmail(to, subject, body.ToString());
}
string subject;
StringBuilder body = new StringBuilder();
if (competitor != null)
if (p.CellPhoneNumber.Length > 0)
{
subject = $"You have a new matchup with {competitor.TeamCompeting.TeamName}";
body.AppendLine("<h1>You Have a new matchup</h1>");
body.Append("<strong>Competitor: </strong>");
body.Append(competitor.TeamCompeting.TeamName);
body.AppendLine();
body.AppendLine();
body.AppendLine("Have a great time!");
body.AppendLine("~Tournament Tracker");
SMSLogic.SendSMSMessage(p.CellPhoneNumber, $"You have a new matchup with {competitor.TeamCompeting.TeamName}");
}
else
{
subject = "You have a bye week this round";
body.AppendLine("Enjoy your round off!");
body.AppendLine("~Tournament Tracker");
}
string to = p.EmailAddress;
EmailLogic.SendEmail(to, subject, body.ToString()); ;
}
private static int CheckCurrentRound(this TournamentModel model)

View File

@ -37,15 +37,31 @@
<Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapper.2.0.30\lib\net461\Dapper.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Logging, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Logging.1.1.2\lib\net451\Microsoft.IdentityModel.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Tokens, Version=5.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.5.1.2\lib\net451\Microsoft.IdentityModel.Tokens.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=5.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.5.1.2\lib\net451\System.IdentityModel.Tokens.Jwt.dll</HintPath>
</Reference>
<Reference Include="System.Net" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Twilio, Version=5.39.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Twilio.5.39.1\lib\net451\Twilio.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DataAccess\IDataConnection.cs" />
@ -62,9 +78,11 @@
<Compile Include="Models\TeamModel.cs" />
<Compile Include="Models\TournamentModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SMSLogic.cs" />
<Compile Include="TournamentLogic.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>

11
TrackerLibrary/app.config Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -2,4 +2,9 @@
<packages>
<package id="Dapper" version="2.0.30" targetFramework="net472" />
<package id="Microsoft.CodeAnalysis.Analyzers" version="3.0.0" targetFramework="net472" developmentDependency="true" />
<package id="Microsoft.IdentityModel.Logging" version="1.1.2" targetFramework="net472" />
<package id="Microsoft.IdentityModel.Tokens" version="5.1.2" targetFramework="net472" />
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net472" />
<package id="System.IdentityModel.Tokens.Jwt" version="5.1.2" targetFramework="net472" />
<package id="Twilio" version="5.39.1" targetFramework="net472" />
</packages>