-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContratosImpl.cs
150 lines (142 loc) · 5.26 KB
/
ContratosImpl.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using Fivet.Dao;
using Fivet.ZeroIce.model;
using Ice;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Fivet.ZeroIce
{
/// <summary>
/// The Implementation of the contratos.
/// </summary>
public class ContratosImpl : ContratosDisp_
{
/// <summary>
/// The Logger
/// </summary>
private readonly ILogger<ContratosImpl> _logger;
/// <summary>
/// The Provider of DBcontext
/// </summary>
private readonly IServiceScopeFactory _serviceScopeFactory;
/// <summary>
/// The Constructor
/// </summary>
/// <param name="logger"></param>
/// <param name="serviceScopeFactory"></param>
public ContratosImpl( ILogger<ContratosImpl> logger, IServiceScopeFactory serviceScopeFactory){
_logger = logger;
_logger.LogDebug("Building the ContratosImpl..");
_serviceScopeFactory = serviceScopeFactory;
// Create The DataBase
_logger.LogInformation("Creating the Database...");
using (var scope = _serviceScopeFactory.CreateScope())
{
FivetContext fc = scope.ServiceProvider.GetService<FivetContext>();
fc.Database.EnsureCreated();
fc.SaveChanges();
}
_logger.LogInformation("Done.");
}
/// <summary>
/// Get The Persona.
/// </summary>
/// <param name="numero">to save</param>
/// <param name="current">the context of ZeroIce</param>
/// <returns></returns>
public override Persona obtenerPersona(string rut, Current current = null)
{
using (var scope = _serviceScopeFactory.CreateScope()){
FivetContext fc = scope.ServiceProvider.GetService<FivetContext>();
Persona persona = fc.Personas.Find(rut);
fc.SaveChanges();
return persona;
}
}
/// <summary>
/// Get The Ficha.
/// </summary>
/// <param name="numero">to save</param>
/// <param name="current">the context of ZeroIce</param>
/// <returns></returns>
public override Ficha obtenerFicha(int numero, Current current)
{
using (var scope = _serviceScopeFactory.CreateScope()){
FivetContext fc = scope.ServiceProvider.GetService<FivetContext>();
Ficha ficha = fc.Fichas.Find(numero);
fc.SaveChanges();
return ficha;
}
}
/// <summary>
/// Create the Ficha
/// </summary>
/// <param name="ficha">to save</param>
/// <param name="current">the context of ZeroIce</param>
/// <returns></returns>
public override Ficha crearFicha(Ficha ficha, Current current)
{
using (var scope = _serviceScopeFactory.CreateScope()){
FivetContext fc = scope.ServiceProvider.GetService<FivetContext>();
fc.Fichas.Add(ficha);
fc.SaveChanges();
return ficha;
}
}
/// <summary>
/// Create the Persona
/// </summary>
/// <param name="persona">to save</param>
/// <param name="current">the context of ZeroIce</param>
/// <returns></returns>
public override Persona crearPersona(Persona persona, Current current)
{
using (var scope = _serviceScopeFactory.CreateScope()){
FivetContext fc = scope.ServiceProvider.GetService<FivetContext>();
fc.Personas.Add(persona);
fc.SaveChanges();
return persona;
}
}
/// <summary>
/// Create the Control
/// </summary>
/// <param name="control">to save</param>
/// <param name="current">the context of ZeroIce</param>
/// <returns></returns>
public override Control crearControl(int numeroFicha, Control control, Current current)
{
using (var scope = _serviceScopeFactory.CreateScope()){
FivetContext fc = scope.ServiceProvider.GetService<FivetContext>();
fc.Controles.Add(control);
fc.SaveChanges();
return control;
}
}
/// <summary>
/// Insert The Foto
/// </summary>
/// <param name="foto">to save</param>
/// <param name="current">the context of ZeroIce</param>
/// <returns></returns>
public override Foto agregarFoto(Foto foto, Current current)
{
using (var scope = _serviceScopeFactory.CreateScope()){
FivetContext fc = scope.ServiceProvider.GetService<FivetContext>();
fc.Fotos.Add(foto);
fc.SaveChanges();
return foto;
}
}
/// <summary>
/// Delay
/// </summary>
/// <param name="clientTime"></param>
/// <param name="current"></param>
/// <returns></returns>
public override long getDelay(long clientTime, Current current = null)
{
return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - clientTime;
}
}
}