Пример #1
0
        public void Insert()
        {
            //Insert Categories if not exist
            var mc0 = new MyMaterialCategory0();

            CategoryID0 = mc0.CreateCategoryID(CategoryID0, 0, CategoryName0);

            var mc1 = new MyMaterialCategory1();

            CategoryID1 = mc1.CreateCategoryID(CategoryID1, CategoryID0, CategoryName1);

            var mc2 = new MyMaterialCategory2();

            CategoryID2 = mc2.CreateCategoryID(CategoryID2, CategoryID1, CategoryName2);

            var mc3 = new MyMaterialCategory3();

            CategoryID3 = mc3.CreateCategoryID(CategoryID3, CategoryID2, CategoryName3);

            var mc4 = new MyMaterialCategory4();

            CategoryID4 = mc4.CreateCategoryID(CategoryID4, CategoryID3, CategoryName4);


            //1. Insert material
            var material = new SpecDomain.Model.Material();

            MyReflection.Copy(this, material);
            _db.Materials.Add(material);
            _db.SaveChanges();


            //2. Insert Price
            var price = new MaterialPrice
            {
                MaterialID         = material.MaterialID,
                UnitID             = UnitID,
                Price              = Price,
                InvoicePriceUnitID = UnitID,
                VenderID           = 0,
                Active             = true
            };

            _db.MaterialPrices.Add(price);
            _db.SaveChanges();

            //3. Update Price
            material.PriceID          = price.PriceID;
            material.UnitID           = price.UnitID;
            material.Price            = Price;
            _db.Entry(material).State = EntityState.Modified;
            _db.SaveChanges();
        }
Пример #2
0
        public void Update()
        {
            IsNewCategoryCreated = false;
            var material = _db.Materials.Find(MaterialID);

            //Insert Categories if not exist

            if (!MyConvert.IsNullString(CategoryName0))
            {
                var mc0 = new MyMaterialCategory0();
                CategoryID0 = mc0.FindCategoryID(0, CategoryName0);
            }

            var mc1 = new MyMaterialCategory1();

            CategoryID1 = mc1.FindCategoryID(CategoryID0, CategoryName1);

            var mc2 = new MyMaterialCategory2();

            CategoryID2 = mc2.FindCategoryID(CategoryID1, CategoryName2);

            var mc3 = new MyMaterialCategory3();

            CategoryID3 = mc3.FindCategoryID(CategoryID2, CategoryName3);

            var mc4 = new MyMaterialCategory4();

            CategoryID4 = mc4.FindCategoryID(CategoryID3, CategoryName4);

            //Update material
            material.CategoryID0  = CategoryID0;
            material.CategoryID1  = CategoryID1;
            material.CategoryID2  = CategoryID2;
            material.CategoryID3  = CategoryID3;
            material.CategoryID4  = CategoryID4;
            material.Remark       = Remark;
            material.MaterialCode = MaterialCode;

            _db.Entry(material).State = EntityState.Modified;
            _db.SaveChanges();
        }
        //1. Insert material
        private void InsertMaterial(string tobeinsertedMaterialCategory2OrCategory3)
        {
            if (!IsValidated)
            {
                return;
            }

            if (_myMaterial.CategoryID2 == 0)
            {
                var mc2 = new MyMaterialCategory2();
                _myMaterial.CategoryID2 = mc2.CreateCategoryID(_myMaterial.CategoryID2, _myMaterial.CategoryID1, tobeinsertedMaterialCategory2OrCategory3);
            }
            else
            {
                var mc3 = new MyMaterialCategory3();
                _myMaterial.CategoryID3 = mc3.CreateCategoryID(_myMaterial.CategoryID3, _myMaterial.CategoryID2, tobeinsertedMaterialCategory2OrCategory3);
            }

            _db.Materials.Add(_myMaterial);
            _db.SaveChanges();
        }