public Instance(EAV.Store.IStoreInstance anInstance) { Container_ID = anInstance.ContainerID.GetValueOrDefault(); Instance_ID = anInstance.InstanceID.GetValueOrDefault(); Parent_Instance_ID = anInstance.ParentInstanceID; Subject_ID = anInstance.SubjectID.GetValueOrDefault(); }
public StoreInstance(EAV.Store.IStoreInstance instance) { this.InstanceID = instance.InstanceID; this.ParentInstanceID = instance.ParentInstanceID; this.SubjectID = instance.SubjectID; this.ContainerID = instance.ContainerID; }
public EAV.Store.IStoreInstance CreateChildInstance(EAV.Store.IStoreInstance instance, int containerID, int parentInstanceID) { if (instance == null) { return(null); } using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext()) { Instance dbInstance = new Instance(instance); Instance dbParentInstance = ctx.Instances.SingleOrDefault(it => it.Instance_ID == parentInstanceID); // TODO: Error if dbParentInstance is null dbInstance.Subject_ID = dbParentInstance.Subject_ID; dbInstance.Container_ID = containerID; dbInstance.Parent_Instance_ID = parentInstanceID; ctx.Instances.Add(dbInstance); ctx.SaveChanges(); return((EAVStoreLibrary.StoreInstance)dbInstance); } }
public IHttpActionResult CreateRootInstance(int id, EAV.Store.IStoreInstance anInstance) { try { return(Ok <EAV.Store.IStoreInstance>(instanceClient.CreateRootInstance(anInstance, ContainerID.GetValueOrDefault(), id))); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult UpdateInstance(EAV.Store.IStoreInstance instance) { try { instanceClient.UpdateInstance(instance); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void UpdateInstance(EAV.Store.IStoreInstance instance) { using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext()) { EAVStoreClient.Instance dbInstance = ctx.Instances.SingleOrDefault(it => it.Instance_ID == instance.InstanceID); if (dbInstance != null) { // Nothing to do at the moment, but including skeleton for completness and possible future expansion. } else { throw (new Exception(String.Format("Unable to retrieve instance ID {0}.", instance.InstanceID))); } } }
public void CreateChildInstance() { EAV.Store.Clients.IInstanceStoreClient client = factory.Create <EAV.Store.Clients.IInstanceStoreClient>(); var dbParentInstance = SelectRandomItem(this.DbContext.Instances); EAV.Store.IStoreInstance instance = client.CreateChildInstance(new EAVStoreLibrary.StoreInstance(), dbParentInstance.Container_ID, dbParentInstance.Instance_ID); Assert.IsNotNull(instance, "Failed to create instance for container ID {0} and parent instance ID {1}.", dbParentInstance.Container_ID, dbParentInstance.Instance_ID); ResetDatabaseContext(); var dbInstance = this.DbContext.Instances.SingleOrDefault(it => it.Instance_ID == instance.InstanceID); Assert.IsNotNull(dbInstance, String.Format("Failed to retrieve instance ID {0} from the database.", instance.InstanceID)); Assert.IsNotNull(dbInstance.Parent_Instance_ID, "Instance has no parent reference defined when it should."); }
public void CreateRootInstance() { EAV.Store.Clients.IInstanceStoreClient client = factory.Create <EAV.Store.Clients.IInstanceStoreClient>(); int subjectID = SelectRandomItem(this.DbContext.Subjects).Subject_ID; int containerID = SelectRandomItem(this.DbContext.Containers.Where(it => it.Parent_Container_ID == null)).Container_ID; EAV.Store.IStoreInstance instance = client.CreateRootInstance(new EAVStoreLibrary.StoreInstance(), containerID, subjectID); Assert.IsNotNull(instance, "Failed to create instance for container ID {0} and subject ID {1}.", containerID, subjectID); ResetDatabaseContext(); var dbInstance = this.DbContext.Instances.SingleOrDefault(it => it.Instance_ID == instance.InstanceID); Assert.IsNotNull(dbInstance, String.Format("Failed to retrieve instance ID {0} from the database.", instance.InstanceID)); Assert.IsNull(dbInstance.Parent_Instance_ID, "Instance has parent reference defined when it should not."); }
public EAV.Store.IStoreInstance CreateRootInstance(EAV.Store.IStoreInstance instance, int containerID, int subjectID) { if (instance == null) { return(null); } using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext()) { Instance dbInstance = new Instance(instance); dbInstance.Subject_ID = subjectID; dbInstance.Container_ID = containerID; ctx.Instances.Add(dbInstance); ctx.SaveChanges(); return((EAVStoreLibrary.StoreInstance)dbInstance); } }