Fix queue storage in the db

This commit is contained in:
Lucio Maranta
2018-09-19 12:12:57 +02:00
parent 95bdb77175
commit 1ba3475c32
5 changed files with 151 additions and 147 deletions
+28 -3
View File
@@ -51,11 +51,30 @@ namespace Step.Database.Controllers
dbCtx.SaveChanges();
}
public void UpdateReps(int processId, int id, int reps)
{
QueueItemsModel item = dbCtx.Queue.Where(x => x.Id == id && x.Process == processId).FirstOrDefault();
// Update reps
item.Reps = reps;
item.RemainingReps = reps;
dbCtx.SaveChanges();
}
public void DeleteItem(int processId, int id)
{
QueueItemsModel item = dbCtx.Queue.Where(x => x.Id == id && x.Process == processId).FirstOrDefault();
dbCtx.Queue.Remove(item);
dbCtx.SaveChanges();
}
public void ReadAndPopulateQueue()
{
var dbQueue = dbCtx.Queue.ToList();
bool foundData = false;
foreach(var entity in dbQueue)
{
// Check if process queue exists
@@ -73,7 +92,13 @@ namespace Step.Database.Controllers
Status = (QUEUE_ITEM_STATUS)entity.Status
});
if((QUEUE_ITEM_STATUS)entity.Status == QUEUE_ITEM_STATUS.RUNNING)
if ((QUEUE_ITEM_STATUS)entity.Status != QUEUE_ITEM_STATUS.FINISHED && !foundData)
{
QueueRunningIndexes[entity.Process] = entity.Id - 1;
foundData = true;
}
if ((QUEUE_ITEM_STATUS)entity.Status == QUEUE_ITEM_STATUS.RUNNING)
QueueRunningIndexes[entity.Process] = entity.Id - 1;
}
}