Add project files.
This commit is contained in:
48
StockDBEF/GreetingService.cs
Normal file
48
StockDBEF/GreetingService.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StockDBEF.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// DI, SeriLog, Settings
|
||||
|
||||
namespace StockDBEF
|
||||
{
|
||||
public class GreetingService : IGreetingService
|
||||
{
|
||||
private readonly ILogger<GreetingService> _log;
|
||||
private readonly IConfiguration _config;
|
||||
private readonly StockDBContext _stockDBContext;
|
||||
|
||||
public GreetingService(ILogger<GreetingService> log, IConfiguration config, StockDBContext stockDBContext)
|
||||
{
|
||||
_log = log;
|
||||
_config = config;
|
||||
_stockDBContext = stockDBContext;
|
||||
}
|
||||
public async void Run()
|
||||
{
|
||||
for (int i = 0; i < _config.GetValue<int>("LoopTimes"); i++)
|
||||
{
|
||||
_log.LogInformation("Run number {runNumber}", i);
|
||||
}
|
||||
|
||||
await SaveInitialStock();
|
||||
await SaveInitialPerson();
|
||||
}
|
||||
|
||||
public async Task SaveInitialStock()
|
||||
{
|
||||
StockMember sm = new StockMember { BuyValue = 120M, ActAmount = 100, BuyDate = DateTime.Parse("2021-03-01"), PostAmount = 100, Comment = "Initial aktiepost" };
|
||||
_stockDBContext.StockMembers.Add(sm);
|
||||
await _stockDBContext.SaveChangesAsync();
|
||||
}
|
||||
public async Task SaveInitialPerson()
|
||||
{
|
||||
Person p = new Person { FirstName="Nisse", LastName="Pärlemo", Born=DateTime.Parse("1995-10-15"), NickName="Nippe" };
|
||||
_stockDBContext.Persons.Add(p);
|
||||
await _stockDBContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user