slarny4/Demo1/DataInitializer.cs
2024-12-02 13:24:02 +03:00

37 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace Demo
{
public class DataInitializer
{
public static void Initialize(RemoteDatabaseContext context)
{
context.Database.EnsureCreated();
if (context.Groups.Any() || context.Users.Any())
{
return; // База данных уже содержит данные
}
context.Users.AddRange(
new User { Id = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "Иванов Иван Иванович", GroupID = 1 },
new User { Id = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "Петров Петр Петрович", GroupID = 2 },
new User { Id = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "Мендалиев Наиль", GroupID = 3 },
new User { Id = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "Сидоров Сидор Сидорович", GroupID = 1 },
new User { Id = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "Кузнецов Алексей Викторович", GroupID = 2 },
new User { Id = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), FIO = "Смирнова Анна Сергеевна", GroupID = 3 }
);
context.Groups.AddRange(
new Group { Id = 1, Name = "ИП1-23" },
new Group { Id = 2, Name = "ИП1-22" },
new Group { Id = 3, Name = "С1-23" }
);
context.SaveChanges();
}
}
}