Added PUT & DELETE API

This commit is contained in:
Lucio Maranta
2018-06-28 17:20:47 +02:00
parent b5d499e6ed
commit 028770dd0a
16 changed files with 538 additions and 315 deletions
@@ -2,6 +2,7 @@
using Step.Model.DTOModels.ToolModels;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
namespace Step.Database.Controllers
@@ -27,10 +28,10 @@ namespace Step.Database.Controllers
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();
}
//foreach (NcFamilyModel family in families)
//{
// family.Tools = tools.Where(x => x.FamilyId == family.FamilyId).ToList();
//}
return families;
}
@@ -38,19 +39,28 @@ namespace Step.Database.Controllers
public NcToolModel FindTool(int toolId)
{
return dbCtx.Tools
.Include("Offset1")
.Include("Offset2")
.Include("Offset3")
.Where(x => x.ToolId == toolId)
.FirstOrDefault();
}
public NcShankModel FindShank(int shankId)
{
return dbCtx.Shanks
.Where(x => x.ShankId == shankId)
.FirstOrDefault();
}
public NcFamilyModel FindFamily(int familyId)
{
return dbCtx.Families
.Where(x => x.FamilyId == familyId)
.FirstOrDefault();
}
public List<NcToolModel> GetTools()
{
List<NcToolModel> tools = dbCtx.Tools
.Include("Offset1")
.Include("Offset2")
.Include("Offset3")
List<NcToolModel> tools = dbCtx.Tools.Include("Family")
.Include("Shank")
.ToList();
return tools;
@@ -58,7 +68,7 @@ namespace Step.Database.Controllers
public List<NcShankModel> GetShanks()
{
List<NcShankModel> shanks = dbCtx.Shanks.ToList();
List<NcShankModel> shanks = dbCtx.Shanks.Include("MagazinePosition").ToList();
return shanks;
}
@@ -70,21 +80,31 @@ namespace Step.Database.Controllers
return positions;
}
public NcMagazinePositionModel GetPosition(byte magId, byte posId)
{
NcMagazinePositionModel positions = dbCtx
.MagazinePositions
.Where(x => x.MagazineId == magId && x.PositionId == posId)
.FirstOrDefault();
return positions;
}
public List<NcOffsetModel> GetOffsets()
{
List<NcOffsetModel> offsets = dbCtx.Offsets.ToList();
return offsets;
}
public NcToolModel AddTool(DTONcToolModel tool)
public NcToolModel AddTool(DTONcToolModel dtoTool)
{
dbCtx.Tools.Add((NcToolModel)tool);
NcToolModel tool = (NcToolModel)dtoTool;
dbCtx.Tools.Add(tool);
dbCtx.SaveChanges();
return (NcToolModel)tool;
return tool;
}
public NcToolModel UpdateTool(NcToolModel tool, DTONcToolModel dtoTool)
@@ -97,25 +117,80 @@ namespace Step.Database.Controllers
dbCtx.SaveChanges();
return (NcToolModel)tool;
return tool;
}
public void DeleleTool(int toolId)
{
NcToolModel tool = FindTool(toolId);
DeleleTool(tool);
}
public void DeleleTool(NcToolModel tool)
{
dbCtx.Tools.Remove(tool);
dbCtx.SaveChanges();
}
public NcFamilyModel AddFamily(DTONcFamilyModel family)
{
dbCtx.Families.Add((NcFamilyModel)family);
NcFamilyModel familyModel = (NcFamilyModel)family;
dbCtx.Families.Add(familyModel);
dbCtx.SaveChanges();
return (NcFamilyModel)family;
return familyModel;
}
public NcShankModel AddShank(DTONcShankModel shank)
{
dbCtx.Shanks.Add((NcShankModel)shank);
NcShankModel dbShank = (NcShankModel)shank;
dbCtx.Shanks.Add(dbShank);
dbCtx.SaveChanges();
return (NcShankModel)shank;
return dbShank;
}
public NcShankModel UpdateShank(NcShankModel dbShank, DTONcShankModel dtoShank)
{
dbShank.MagazinePositionType = dtoShank.MagazinePositionType;
dbCtx.SaveChanges();
return dbShank;
}
public void DeleleShank(int shankId)
{
NcShankModel shank = FindShank(shankId);
DeleleShank(shank);
}
public void DeleleShank(NcShankModel shank)
{
dbCtx.Shanks.Remove(shank);
dbCtx.SaveChanges();
}
public NcMagazinePositionModel UpdatePosition(NcMagazinePositionModel dbPos, DTONcMagazinesPositionsModel dtoPos)
{
dbPos.Type = dtoPos.Type;
dbPos.Disabled = dtoPos.Disabled;
dbCtx.SaveChanges();
return dbPos;
}
public void DeleleFamily(NcFamilyModel family)
{
dbCtx.Families.Attach(family);
dbCtx.Families.Remove(family);
dbCtx.SaveChanges();
}
}
}