* Added machine model, and new database relations

* Added first centralized database config and  added machine self-registration into db
* Fix database migration with new database
* Refactor
This commit is contained in:
Lucio Maranta
2018-01-17 10:24:18 +01:00
parent b26ec6cc43
commit fa485d902b
32 changed files with 457 additions and 141 deletions
@@ -0,0 +1,55 @@
using Step.Model.DatabaseModels;
using System;
using System.Linq;
using static Step.Config.ServerConfig;
namespace Step.Database.Controllers
{
public class MachineController : IDisposable
{
private DatabaseContext dbCtx;
public MachineController()
{
// Initialize database context
dbCtx = new DatabaseContext();
}
public void Dispose()
{
// Clear database context
dbCtx.Dispose();
}
public MachineModel GetMachineById(int id)
{
return dbCtx
.Machines
.Where(x => x.MachineId == id)
.SingleOrDefault();
}
public MachineModel GetMachineByUniqueId(string uniqueId)
{
return dbCtx
.Machines
.Where(x => x.UniqueId == uniqueId)
.SingleOrDefault();
}
public MachineModel Create( string uniqueId)
{
MachineModel machine= new MachineModel()
{
MachineId = 1,
Name = NcConfig.NcName,
UniqueId = uniqueId
};
dbCtx.Machines.Add(machine);
dbCtx.SaveChanges();
return machine;
}
}
}