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();
 }
Example #2
0
 public StoreInstance(EAV.Store.IStoreInstance instance)
 {
     this.InstanceID       = instance.InstanceID;
     this.ParentInstanceID = instance.ParentInstanceID;
     this.SubjectID        = instance.SubjectID;
     this.ContainerID      = instance.ContainerID;
 }
Example #3
0
        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);
            }
        }
Example #4
0
 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));
     }
 }
Example #5
0
        public IHttpActionResult UpdateInstance(EAV.Store.IStoreInstance instance)
        {
            try
            {
                instanceClient.UpdateInstance(instance);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Example #6
0
        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)));
                }
            }
        }
Example #7
0
        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.");
        }
Example #8
0
        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.");
        }
Example #9
0
        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);
            }
        }