Rename directories and projects
This commit is contained in:
83
Back/skydiveLogs-api.DomainBusiness/InitDbService.cs
Normal file
83
Back/skydiveLogs-api.DomainBusiness/InitDbService.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class InitDbService : IInitDbService
|
||||
{
|
||||
public InitDbService(IAircraftService aircraftService,
|
||||
IJumpTypeService jumpTypeService,
|
||||
IDropZoneService dropZoneService)
|
||||
{
|
||||
_aircraftService = aircraftService;
|
||||
_jumpTypeService = jumpTypeService;
|
||||
_dropZoneService = dropZoneService;
|
||||
}
|
||||
|
||||
public void GenerateDb()
|
||||
{
|
||||
LoadAircrafts();
|
||||
LoadDropZones();
|
||||
LoadJumpTypes();
|
||||
}
|
||||
|
||||
private void LoadDropZones()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/dropZone.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<DropZone>>(jsonString, options);
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_dropZoneService.AddNewDz(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadJumpTypes()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/jumpType.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<JumpType>>(jsonString, options);
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_jumpTypeService.AddNewJumpType(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadAircrafts()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/aircraft.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<Aircraft>>(jsonString, options);
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_aircraftService.AddNewAircraft(item);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user