public void AddDataView(BExIS.Dlm.Entities.DataStructure.StructuredDataStructure dataStructure, DataView view)
{
// view should not be connected to a Dataset. if so throw an exception and the caller must remove the relationship to that dataset and then add to a data structure
Contract.Requires(dataStructure != null && dataStructure.Id >= 0);
Contract.Requires(view != null && view.Id >= 0);
Contract.Requires(view.Dataset == null);
//Contract.Ensures(Contract.Result<StructuredDataStructure>() != null && Contract.Result<StructuredDataStructure>().Id >= 0);
StructuredDataStructureRepo.Reload(dataStructure);
StructuredDataStructureRepo.LoadIfNot(dataStructure.Views);
int count = (from v in dataStructure.Views
where v.Id.Equals(view.Id)
select v
)
.Count();
if (count > 0)
throw new Exception(string.Format("There is a connection between data structure {0} and view {1}", dataStructure.Id, view.Id));
dataStructure.Views.Add(view);
view.DataStructures.Add(dataStructure);
using (IUnitOfWork uow = this.GetUnitOfWork())
{
IRepository<StructuredDataStructure> repo = uow.GetRepository<StructuredDataStructure>();
repo.Put(dataStructure);
uow.Commit();
}
}