Add .NET Core 2.1 versions

This commit is contained in:
Elton Stoneman
2018-09-21 19:23:31 +01:00
parent e3eb2dbd2a
commit 879e5bc477
86 changed files with 28610 additions and 1 deletions

View File

@ -0,0 +1,7 @@
namespace Worker.Data
{
public interface IVoteData
{
void Set(string voterId, string vote);
}
}

View File

@ -0,0 +1,35 @@
using Microsoft.Extensions.Logging;
using Worker.Entities;
namespace Worker.Data
{
public class MySqlVoteData : IVoteData
{
private readonly VoteContext _context;
private readonly ILogger _logger;
public MySqlVoteData(VoteContext context, ILogger<MySqlVoteData> logger)
{
_context = context;
_logger = logger;
}
public void Set(string voterId, string vote)
{
var currentVote = _context.Votes.Find(voterId);
if (currentVote == null)
{
_context.Votes.Add(new Vote
{
VoterId = voterId,
VoteOption = vote
});
}
else if (currentVote.VoteOption != vote)
{
currentVote.VoteOption = vote;
}
_context.SaveChanges();
}
}
}