예제 #1
0
        public void CreateAttribute()
        {
            EAV.Store.Clients.IAttributeStoreClient client = factory.Create <EAV.Store.Clients.IAttributeStoreClient>();
            int    containerID   = SelectRandomItem(this.DbContext.Containers).Context_ID;
            string attributeName = Guid.NewGuid().ToString();

            EAV.Store.IStoreAttribute attribute = client.CreateAttribute(new EAVStoreLibrary.StoreAttribute()
            {
                Name          = attributeName,
                DataName      = attributeName.ToUpper(),
                DisplayText   = attributeName + ":",
                DataType      = EAV.EAVDataType.String,
                IsKey         = true,
                Sequence      = rng.Next(),
                VariableUnits = true,
            }, containerID);

            Assert.IsNotNull(attribute, "Failed to create attribute with name '{0}' for container ID {1}.", attributeName, containerID);

            ResetDatabaseContext();

            var dbAttribute = this.DbContext.Attributes.SingleOrDefault(it => it.Attribute_ID == attribute.AttributeID);

            Assert.IsNotNull(dbAttribute, String.Format("Failed to retrieve attribute ID {0} from the database.", attribute.AttributeID));

            Assert.AreEqual(attribute.Name, dbAttribute.Name, "Property 'Name' was not created correctly.");
            Assert.AreEqual(attribute.DataName, dbAttribute.Data_Name, "Property 'DataName' was not created correctly.");
            Assert.AreEqual(attribute.DisplayText, dbAttribute.Display_Text, "Property 'DisplayText' was not created correctly.");
            Assert.AreEqual(attribute.DataType.ToString(), dbAttribute.Data_Type.Name, "Property 'DataType' was not created correctly.");
            Assert.AreEqual(attribute.IsKey, dbAttribute.Is_Key, "Property 'IsKey' was not created correctly.");
            Assert.AreEqual(attribute.Sequence, dbAttribute.Sequence, "Property 'Sequence' was not created correctly.");
            Assert.AreEqual(attribute.VariableUnits, dbAttribute.Variable_Units, "Property 'VariableUnits' was not created correctly.");
        }
예제 #2
0
        public void CreateDuplicateAttribute_Data_Name()
        {
            EAV.Store.Clients.IAttributeStoreClient client = factory.Create <EAV.Store.Clients.IAttributeStoreClient>();
            int    containerID   = SelectRandomItem(this.DbContext.Containers).Context_ID;
            string attributeName = Guid.NewGuid().ToString();

            EAV.Store.IStoreAttribute attribute = client.CreateAttribute(new EAVStoreLibrary.StoreAttribute()
            {
                Name          = attributeName,
                DataName      = attributeName.ToUpper(),
                DisplayText   = attributeName + ":",
                DataType      = EAV.EAVDataType.String,
                IsKey         = true,
                Sequence      = rng.Next(),
                VariableUnits = true,
            }, containerID);

            Assert.IsNotNull(attribute, "Failed to create attribute with name '{0}' for container ID {1}.", attributeName, containerID);

            client.CreateAttribute(new EAVStoreLibrary.StoreAttribute()
            {
                Name          = attributeName + "1",
                DataName      = attributeName.ToUpper(),
                DisplayText   = attributeName + ":",
                DataType      = EAV.EAVDataType.String,
                IsKey         = true,
                Sequence      = rng.Next(),
                VariableUnits = true,
            }, containerID);

            Assert.Fail("Failed to throw exception creating attribute with duplicate data name.");
        }
예제 #3
0
 public Attribute(EAV.Store.IStoreAttribute attribute)
 {
     Attribute_ID   = attribute.AttributeID.GetValueOrDefault();
     Container_ID   = attribute.ContainerID.GetValueOrDefault();
     Data_Name      = attribute.DataName;
     Display_Text   = attribute.DisplayText;
     Is_Key         = attribute.IsKey;
     Name           = attribute.Name;
     Sequence       = attribute.Sequence;
     Variable_Units = attribute.VariableUnits;
 }
예제 #4
0
 public IHttpActionResult CreateAttribute(int id, EAV.Store.IStoreAttribute attribute)
 {
     try
     {
         return(Ok <EAV.Store.IStoreAttribute>(attributeClient.CreateAttribute(attribute, id)));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
예제 #5
0
 public StoreAttribute(EAV.Store.IStoreAttribute attribute)
 {
     this.AttributeID   = attribute.AttributeID;
     this.ContainerID   = attribute.ContainerID;
     this.Name          = attribute.Name;
     this.DataName      = attribute.DataName;
     this.DisplayText   = attribute.DisplayText;
     this.DataType      = attribute.DataType;
     this.Sequence      = attribute.Sequence;
     this.IsKey         = attribute.IsKey;
     this.VariableUnits = attribute.VariableUnits;
 }
예제 #6
0
        public IHttpActionResult UpdateAttribute(EAV.Store.IStoreAttribute attribute)
        {
            try
            {
                attributeClient.UpdateAttribute(attribute);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #7
0
        public void UpdateAttribute(EAV.Store.IStoreAttribute attribute)
        {
            using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext())
            {
                EAVStoreClient.Attribute dbAttribute = ctx.Attributes.SingleOrDefault(it => it.Attribute_ID == attribute.AttributeID);

                if (dbAttribute != null)
                {
                    if (dbAttribute.Name != attribute.Name)
                    {
                        dbAttribute.Name = attribute.Name;
                    }

                    if (dbAttribute.Data_Name != attribute.DataName)
                    {
                        dbAttribute.Data_Name = attribute.DataName;
                    }

                    if (dbAttribute.Display_Text != attribute.DisplayText)
                    {
                        dbAttribute.Display_Text = attribute.DisplayText;
                    }

                    if (dbAttribute.Data_Type.Name != attribute.DataType.ToString())
                    {
                        dbAttribute.Data_Type = ctx.Data_Type.Single(it => it.Name == attribute.DataType.ToString());
                    }

                    if (dbAttribute.Sequence != attribute.Sequence)
                    {
                        dbAttribute.Sequence = attribute.Sequence;
                    }

                    if (dbAttribute.Is_Key != attribute.IsKey)
                    {
                        dbAttribute.Is_Key = attribute.IsKey;
                    }

                    if (dbAttribute.Variable_Units != attribute.VariableUnits)
                    {
                        dbAttribute.Variable_Units = attribute.VariableUnits;
                    }

                    ctx.SaveChanges();
                }
                else
                {
                    throw (new Exception(String.Format("Unable to retrieve attribute ID {0}.", attribute.AttributeID)));
                }
            }
        }
예제 #8
0
        public EAV.Store.IStoreAttribute CreateAttribute(EAV.Store.IStoreAttribute attribute, int containerID)
        {
            if (attribute == null)
            {
                return(null);
            }

            using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext())
            {
                Attribute dbAttribute = new Attribute(attribute);

                dbAttribute.Container_ID = containerID;
                dbAttribute.Data_Type    = ctx.LookupDataType(attribute.DataType);

                ctx.Attributes.Add(dbAttribute);

                ctx.SaveChanges();

                return((EAVStoreLibrary.StoreAttribute)dbAttribute);
            }
        }