Merge branch 'feature/MaintenancesWP5' into develop

This commit is contained in:
Lucio Maranta
2018-06-11 17:48:21 +02:00
24 changed files with 431 additions and 75 deletions
@@ -1,8 +1,10 @@
using Step.Model.DatabaseModels;
using Step.Model.DTOModels.MaintenanceModels;
using System;
using System.Collections.Generic;
using System.Linq;
using static Step.Config.ServerConfig;
using static Step.Model.Constants;
namespace Step.Database.Controllers
{
@@ -22,7 +24,7 @@ namespace Step.Database.Controllers
dbCtx.Dispose();
}
public List<PerformedMaintenanceModel> FindLastMaintenance()
public List<PerformedMaintenanceModel> FindLastPerformedMaintenances()
{
List<PerformedMaintenanceModel> lastMaintenances = new List<PerformedMaintenanceModel>();
// Find last performed maintenance
@@ -50,14 +52,38 @@ namespace Step.Database.Controllers
.ToList();
}
public MaintenanceModel Create(DTONewMaintenanceModel newMaint, int userId)
{
MaintenanceModel dbMaint = new MaintenanceModel()
{
CreationDate = DateTime.Now,
CounterId = 0,
Interval = newMaint.Interval != null ? (double)newMaint.Interval : 0,
Deadline = newMaint.Deadline,
Description = newMaint.Description,
Title = newMaint.Title,
Type = newMaint.Type,
UnitOfMeasure = newMaint.UnitOfMeasure,
UserId = userId,
LastExpirationDate = null
};
// Add to database
dbCtx.Maintenances.Add(dbMaint);
// Commit changes
dbCtx.SaveChanges();
return dbMaint;
}
public void CheckDifferencesFromDbAndXml()
{
List<MaintenanceModel> dbMaintenances = dbCtx
.Maintenances
.ToList();
// Find database rows that
List<MaintenanceModel> toDeleteMaint = dbMaintenances.Where(x =>
// Find database rows that has to be deleted
List<MaintenanceModel> toDeleteMaint = dbMaintenances.Where(x => x.UserId == null &&
!MaintenancesConfig.Select(y => y.Id).Contains(x.MaintenanceId)
).ToList();
@@ -87,6 +113,8 @@ namespace Step.Database.Controllers
old.Interval = x.Intervall.TotalMinutes;
old.Type = x.Type;
old.CounterId = x.CouterId;
old.Description = x.Description;
old.UnitOfMeasure = (MAINTENANCE_UNIT_OF_MEASURE)Enum.Parse(typeof(MAINTENANCE_UNIT_OF_MEASURE), x.UnitOfMeasure);
return old;
}).FirstOrDefault();
}
@@ -104,6 +132,9 @@ namespace Step.Database.Controllers
Type = x.Type,
CounterId = x.CouterId,
CreationDate = DateTime.Now,
Description = x.Description,
UnitOfMeasure = (MAINTENANCE_UNIT_OF_MEASURE) Enum.Parse(typeof(MAINTENANCE_UNIT_OF_MEASURE),x.UnitOfMeasure),
UserId = null,
LastExpirationDate = null
})
.ToList();