Added models and GET API
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels.ToolModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
public class NcToolManagerController : IDisposable
|
||||
{
|
||||
private DatabaseContext dbCtx;
|
||||
|
||||
public NcToolManagerController()
|
||||
{
|
||||
// Initialize database context
|
||||
dbCtx = new DatabaseContext();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public List<NcFamilyModel> GetFamilies()
|
||||
{
|
||||
List<NcFamilyModel> families = dbCtx.Families.ToList();
|
||||
|
||||
List<NcToolModel> tools = dbCtx.Tools.ToList();
|
||||
foreach (NcFamilyModel family in families)
|
||||
{
|
||||
family.Tools = tools.Where(x => x.FamilyId == family.FamilyId).ToList();
|
||||
}
|
||||
|
||||
return families;
|
||||
}
|
||||
|
||||
public List<NcToolModel> GetTools()
|
||||
{
|
||||
List<NcToolModel> tools = dbCtx.Tools
|
||||
.Include("Offset1")
|
||||
.Include("Offset2")
|
||||
.Include("Offset3")
|
||||
.ToList();
|
||||
|
||||
return tools;
|
||||
}
|
||||
|
||||
public List<NcShankModel> GetShanks()
|
||||
{
|
||||
List<NcShankModel> shanks = dbCtx.Shanks.ToList();
|
||||
|
||||
return shanks;
|
||||
}
|
||||
|
||||
public List<NcMagazinePositionModel> GetPositions()
|
||||
{
|
||||
List<NcMagazinePositionModel> positions = dbCtx.MagazinePositions.ToList();
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
public List<NcOffsetModel> GetOffsets()
|
||||
{
|
||||
List<NcOffsetModel> offsets = dbCtx.Offsets.ToList();
|
||||
|
||||
return offsets;
|
||||
}
|
||||
|
||||
|
||||
public NcToolModel AddTool(DTONcToolModel tool)
|
||||
{
|
||||
dbCtx.Tools.Add((NcToolModel)tool);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return (NcToolModel)tool;
|
||||
}
|
||||
|
||||
|
||||
public NcFamilyModel AddFamily(DTONcFamilyModel family)
|
||||
{
|
||||
dbCtx.Families.Add((NcFamilyModel)family);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return (NcFamilyModel)family;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user