Add .NET Core 2.1 versions
This commit is contained in:
7
worker/dotnet/Worker/Data/IVoteData.cs
Normal file
7
worker/dotnet/Worker/Data/IVoteData.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Worker.Data
|
||||
{
|
||||
public interface IVoteData
|
||||
{
|
||||
void Set(string voterId, string vote);
|
||||
}
|
||||
}
|
35
worker/dotnet/Worker/Data/MySqlVoteData.cs
Normal file
35
worker/dotnet/Worker/Data/MySqlVoteData.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user