Add ResultsAdmin, delete action

This commit is contained in:
2016-05-20 22:47:28 -04:00
parent cff6a0d96f
commit 790e2494e3
6 changed files with 182 additions and 1 deletions
+35 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
@@ -22,6 +23,13 @@ namespace LeafWeb.Core.DAL
_db.Dispose();
}
private void RemoveCollectionFromDbSet<T>(ICollection<T> collection, IDbSet<T> set) where T : class
{
if (collection == null) return;
foreach (var entity in collection.ToArray())
set.Remove(entity);
}
#region Fluxnet Sites
public IQueryable<FluxnetSite> GetFluxnetSites()
@@ -51,6 +59,31 @@ namespace LeafWeb.Core.DAL
return _db.LeafInputs.FirstOrDefault(li => li.Id == id);
}
public void DeleteLeafInput(LeafInput leafInput)
{
RemoveCollectionFromDbSet(leafInput.InputFiles, _db.LeafInputFiles);
RemoveCollectionFromDbSet(leafInput.OutputFiles, _db.LeafOutputFiles);
RemoveCollectionFromDbSet(leafInput.StatusHistory, _db.LeafInputStatus);
// Data
if (leafInput.LeafInputData != null)
foreach (var leafInputData in leafInput.LeafInputData.ToArray())
RemoveLeafInputDataNoUpdate(leafInputData);
_db.LeafInputs.Remove(leafInput);
_db.SaveChanges();
}
private void RemoveLeafInputDataNoUpdate(LeafInputData leafInputData)
{
if (leafInputData.Data != null)
foreach (var curve in leafInputData.Data.ToArray())
_db.LeafInputDataCurves.Remove(curve);
if (leafInputData.Photosynthetic != null)
_db.LeafInputDataPhotosynthetic.Remove(leafInputData.Photosynthetic);
if (leafInputData.Site != null)
_db.LeafInputDataSite.Remove(leafInputData.Site);
_db.LeafInputData.Remove(leafInputData);
}
public LeafOutputFile GetLeafOutput_ChartFile(int leafInputId)
{
return GetLeafOutput_FilenameLike(leafInputId, LeafOutputFile.Filename_LeafChart);
@@ -76,7 +109,7 @@ namespace LeafWeb.Core.DAL
public IQueryable<LeafInput> GetLeafInputs(params LeafInputStatusType[] statuses)
{
return
from file in _db.LeafInputs
from file in GetLeafInputs()
where statuses.Contains(file.CurrentStatus)
select file;
}
@@ -174,5 +207,6 @@ namespace LeafWeb.Core.DAL
}
#endregion
}
}