-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepository.cs
More file actions
58 lines (46 loc) · 1.97 KB
/
Repository.cs
File metadata and controls
58 lines (46 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Developer_Allocation_Management
{
internal class Repository : DbContext
{
private static MySqlConnection _dbConnection;
public DbSet<Developer> Developers { get; set; }
public DbSet<Credential> Credentials { get; set; }
public DbSet<Project> Projects { get; set; }
public DbSet<Allocation> Allocations { get; set; }
public Repository() : base(GetConnection(), false)
{
if (Database.CreateIfNotExists())
{
Repository repository = this;
Credential credencial = new Credential("douglasbadaro@mail.com", "123456", true, true);
Developer developer = new Developer("Douglas Badaró", DateTime.Parse("2006 - 01 - 14"), 'J');
credencial.Developer = developer;
developer.Credential = credencial;
repository.Developers.Add(developer);
Project project = new Project("Automação", DateTime.Parse("2021-06-21"), DateTime.Parse("2022-12-23"), DateTime.Parse("2022-12-23"));
repository.Projects.Add(project);
Allocation allocation = new Allocation(DateTime.Parse("2021-06-21"), DateTime.Parse("2022-12-23"), 8, 160.0m, developer, project);
repository.Allocations.Add(allocation);
repository.SaveChanges();
}
}
public static MySqlConnection GetConnection()
{
if (_dbConnection == null)
{
String connectionString = ConfigurationManager.ConnectionStrings["DeveloperManagementString"].ConnectionString;
_dbConnection = new MySqlConnection(connectionString);
}
return _dbConnection;
}
}
}