Added load/unload into shank
Fixed magazine position returned data WIP loading/unloading rules
This commit is contained in:
@@ -128,11 +128,25 @@ namespace Step.Database.Controllers
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public DTONcShankModel GetShank(int shankId)
|
||||
{
|
||||
// Get shank from database
|
||||
NcShankModel dbShank = dbCtx
|
||||
.Shanks
|
||||
.Where(x => x.ShankId == shankId)
|
||||
.Include("Tools")
|
||||
.FirstOrDefault();
|
||||
|
||||
// Convert into DTOModel
|
||||
DTONcShankModel dtoShanks = (DTONcShankModel)dbShank;
|
||||
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public List<NcMagazinePositionModel> FindPositions()
|
||||
{
|
||||
List<NcMagazinePositionModel> positions = dbCtx
|
||||
.MagazinePositions
|
||||
.Include("Shank")
|
||||
.ToList();
|
||||
|
||||
return positions;
|
||||
@@ -146,6 +160,26 @@ namespace Step.Database.Controllers
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public List<DTONcMagazinePositionModel> GetMagazinePositions(byte magId)
|
||||
{
|
||||
// Get only magazine positions that match with magazineId
|
||||
List<DTONcMagazinePositionModel> magPos = FindMagazinePositions(magId).Select(x => (DTONcMagazinePositionModel)x).ToList();
|
||||
// Get&filter shanks by magazineId in order to get only mounted shanks in the current magazineId
|
||||
List<NcShankModel> shanks = dbCtx.Shanks.Where(x => x.MagazineId == magId).ToList();
|
||||
|
||||
foreach(NcShankModel shank in shanks)
|
||||
{
|
||||
// Populate magazinePosition shank Id
|
||||
magPos
|
||||
.Where(x => x.PositionId == shank.PositionId)
|
||||
.FirstOrDefault()
|
||||
.ShankId = shank.ShankId;
|
||||
}
|
||||
// Convert in DTOModel and return
|
||||
return magPos;
|
||||
}
|
||||
|
||||
public NcMagazinePositionModel FindMagazinePosition(byte magId, byte posId)
|
||||
{
|
||||
NcMagazinePositionModel positions = dbCtx
|
||||
@@ -156,13 +190,6 @@ namespace Step.Database.Controllers
|
||||
return positions;
|
||||
}
|
||||
|
||||
//public List<NcOffsetModel> GetOffsets()
|
||||
//{
|
||||
// List<NcOffsetModel> offsets = dbCtx.Offsets.ToList();
|
||||
|
||||
// return offsets;
|
||||
//}
|
||||
|
||||
public List<DTONcShankModel> GetMountedShanks(int magazineId)
|
||||
{
|
||||
List<DTONcShankModel> dtoShanks = GetShanks()
|
||||
@@ -299,7 +326,7 @@ namespace Step.Database.Controllers
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public NcMagazinePositionModel UpdatePosition(NcMagazinePositionModel dbPos, DTONcMagazinesPositionsModel dtoPos)
|
||||
public NcMagazinePositionModel UpdatePosition(NcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos)
|
||||
{
|
||||
dbPos.Type = dtoPos.Type;
|
||||
dbPos.Disabled = dtoPos.Disabled;
|
||||
@@ -332,5 +359,28 @@ namespace Step.Database.Controllers
|
||||
|
||||
return (DTONcShankModel)shank;
|
||||
}
|
||||
|
||||
public DTONcShankModel LoadToolIntoShank(NcToolModel tool, int shankId)
|
||||
{
|
||||
dbCtx.Tools.Attach(tool);
|
||||
|
||||
tool.ShankId = shankId;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return GetShank(shankId);
|
||||
}
|
||||
|
||||
public DTONcShankModel UnloadToolFromShank(NcToolModel tool)
|
||||
{
|
||||
dbCtx.Tools.Attach(tool);
|
||||
int? shankId = tool.ShankId;
|
||||
|
||||
tool.ShankId = null;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return GetShank(shankId.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user