Beispiel #1
0
        public void CreateUnit()
        {
            EAV.Store.Clients.IUnitStoreClient client = factory.Create <EAV.Store.Clients.IUnitStoreClient>();
            string UnitDisplayText = Guid.NewGuid().ToString();

            EAV.Store.IStoreUnit Unit = client.CreateUnit(new EAVStoreLibrary.StoreUnit()
            {
                SingularName         = "SN_" + UnitDisplayText,
                SingularAbbreviation = "SA_" + UnitDisplayText.Substring(0, 4),
                PluralName           = "PN_" + UnitDisplayText,
                PluralAbbreviation   = "PA_" + UnitDisplayText.Substring(0, 4),
                Symbol      = "SYM",
                DisplayText = UnitDisplayText,
                Curated     = false,
            });

            Assert.IsNotNull(Unit, "Failed to create Unit with display text '{0}'", UnitDisplayText);

            ResetDatabaseContext();

            var dbUnit = this.DbContext.Units.SingleOrDefault(it => it.Unit_ID == Unit.UnitID);

            Assert.IsNotNull(dbUnit, String.Format("Failed to retrieve Unit ID {0} from the database.", Unit.UnitID));

            Assert.AreEqual(Unit.SingularName, dbUnit.Singular_Name, "Property 'SingularName' was not created correctly.");
            Assert.AreEqual(Unit.SingularAbbreviation, dbUnit.Singular_Abbreviation, "Property 'SingularAbbreviation' was not created correctly.");
            Assert.AreEqual(Unit.PluralName, dbUnit.Plural_Name, "Property 'PluralName' was not created correctly.");
            Assert.AreEqual(Unit.PluralAbbreviation, dbUnit.Plural_Abbreviation, "Property 'PluralAbbreviation' was not created correctly.");
            Assert.AreEqual(Unit.Symbol, dbUnit.Symbol, "Property 'Symbol' was not created correctly.");
            Assert.AreEqual(Unit.DisplayText, dbUnit.Display_Text, "Property 'DisplayText' was not created correctly.");
            Assert.AreEqual(Unit.Curated, dbUnit.Curated, "Property 'Curated' was not created correctly.");
        }
Beispiel #2
0
 public StoreUnit(EAV.Store.IStoreUnit unit)
 {
     this.UnitID               = unit.UnitID;
     this.SingularName         = unit.SingularName;
     this.SingularAbbreviation = unit.SingularAbbreviation;
     this.PluralName           = unit.PluralName;
     this.PluralAbbreviation   = unit.PluralAbbreviation;
     this.Symbol               = unit.Symbol;
     this.Curated              = unit.Curated;
 }
 public Unit(EAV.Store.IStoreUnit aUnit)
 {
     Unit_ID               = aUnit.UnitID.GetValueOrDefault();
     Singular_Name         = aUnit.SingularName;
     Singular_Abbreviation = aUnit.SingularAbbreviation;
     Plural_Name           = aUnit.PluralName;
     Plural_Abbreviation   = aUnit.PluralAbbreviation;
     Symbol       = aUnit.Symbol;
     Display_Text = aUnit.DisplayText;
     Curated      = aUnit.Curated;
 }
Beispiel #4
0
 public IHttpActionResult CreateUnit(EAV.Store.IStoreUnit unit)
 {
     try
     {
         return(Ok <EAV.Store.IStoreUnit>(unitClient.CreateUnit(unit)));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Beispiel #5
0
        public IHttpActionResult UpdateUnit(EAV.Store.IStoreUnit unit)
        {
            try
            {
                unitClient.UpdateUnit(unit);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #6
0
        public void UpdateUnit(EAV.Store.IStoreUnit aUnit)
        {
            using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext())
            {
                EAVStoreClient.Unit dbUnit = ctx.Units.SingleOrDefault(it => it.Unit_ID == aUnit.UnitID);

                if (dbUnit != null)
                {
                    if (dbUnit.Singular_Name != aUnit.SingularName)
                    {
                        dbUnit.Singular_Name = aUnit.SingularName;
                    }

                    if (dbUnit.Singular_Abbreviation != aUnit.SingularAbbreviation)
                    {
                        dbUnit.Singular_Abbreviation = aUnit.SingularAbbreviation;
                    }

                    if (dbUnit.Plural_Name != aUnit.PluralName)
                    {
                        dbUnit.Plural_Name = aUnit.PluralName;
                    }

                    if (dbUnit.Plural_Abbreviation != aUnit.PluralAbbreviation)
                    {
                        dbUnit.Plural_Abbreviation = aUnit.PluralAbbreviation;
                    }

                    if (dbUnit.Symbol != aUnit.Symbol)
                    {
                        dbUnit.Symbol = aUnit.Symbol;
                    }

                    if (dbUnit.Display_Text != aUnit.DisplayText)
                    {
                        dbUnit.Display_Text = aUnit.DisplayText;
                    }

                    if (dbUnit.Curated != aUnit.Curated)
                    {
                        dbUnit.Curated = aUnit.Curated;
                    }

                    ctx.SaveChanges();
                }
                else
                {
                    throw (new Exception(String.Format("Unable to retrieve Unit ID {0}.", aUnit.UnitID)));
                }
            }
        }
Beispiel #7
0
        public EAV.Store.IStoreUnit CreateUnit(EAV.Store.IStoreUnit aUnit)
        {
            if (aUnit == null)
            {
                return(null);
            }

            // TODO: Need to check that at least one string property has a non-empty value?

            using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext())
            {
                Unit dbUnit = new Unit(aUnit);

                ctx.Units.Add(dbUnit);

                ctx.SaveChanges();

                return((EAVStoreLibrary.StoreUnit)dbUnit);
            }
        }