private void undoCheckout(Int64 datasetId, string username, bool adminMode, bool commit = true)
{
// maybe its required to pass the caller's repo in order to the rollback changes to be visible to the caller function and be able to commit them
// bring back the historical tuples. recover deleted ones/ editedVersion ones. throw away created ones.
// remove the version after the processes are finished
// take the dataset back to the checked in state
// check for admin mode
DateTime timestamp = DateTime.UtcNow;
using (IUnitOfWork uow = this.GetUnitOfWork())
{
IRepository<Dataset> repo = uow.GetRepository<Dataset>();
Dataset ds = null;
if (adminMode)
ds = repo.Get(p => p.Id == datasetId && p.Status == DatasetStatus.CheckedOut).FirstOrDefault();
else
ds = repo.Get(p => p.Id == datasetId && p.Status == DatasetStatus.CheckedOut && p.CheckOutUser.Equals(getUserIdentifier(username))).FirstOrDefault();
if (ds != null)
{
if (ds.Versions.Count() > 0)
{
//remove the version from the dataset, it should cause the version to be removed.
DatasetVersion dsv = ds.Versions.OrderByDescending(t => t.Timestamp).First(p => p.Status == DatasetVersionStatus.CheckedOut);
// handle tuples here
undoTupleChanges(dsv);
ds.Versions.Remove(dsv);
}
//// take the dataset back to the checked in status
//ds.Status = DatasetStatus.CheckedIn;
////var previous = ds.Versions.OrderByDescending(t => t.Timestamp).FirstOrDefault(p => p.Status == DatasetVersionStatus.CheckedIn);
//ds.LastCheckIOTimestamp = timestamp;
//ds.CheckOutUser = string.Empty;
if (commit)
{
repo.Put(ds);
uow.Commit();
}
}
}
}