コード例 #1
0
        //[HttpPost]
        public ActionResult Clone(int id)
        {
            Material newMaterial = new Material();
            using (var mm = new MaterialsManager())
            {
                Material mat = mm.SingleMaterial(id);

                // use reflection to populate the new Material

                // reflect to get instances of the entity preoprties
                var editProperties =
                    from p in mat.GetType().GetProperties()
                    select p;

                // copy the values
                PropertyInfo[] editProps = editProperties.ToArray();
                foreach (PropertyInfo propertyInfo in editProps)
                {
                    propertyInfo.SetValue(newMaterial, propertyInfo.GetValue(mat, null), null);
                }

                // set specifics
                newMaterial.Name = mat.Name + " - Clone";
                if (newMaterial.Name.Length > 100)
                {
                    newMaterial.Name = newMaterial.Name.Substring(0, 100);
                }
                newMaterial.CreatedOn = DateTime.Now;
                newMaterial.ModifiedOn = DateTime.Now;
                newMaterial.ID = 0;

                newMaterial = mm.CreateMaterial(newMaterial);
            }
            return RedirectToAction("EditMaterial", new {id = newMaterial.ID});
        }
コード例 #2
0
        public void CreateMaterialTest()
        {
            Material material = new Material();

            material.CreatedOn = DateTime.Now;
            material.Measurement = Measurement.SquareFeet;
            material.ModifiedOn = DateTime.Now;
            material.Name = "Wood Siding";
            material.SubName = "Light Blue";

            using (var mm = new MaterialsManager())
            {
                material = mm.CreateMaterial(material);
                Assert.IsTrue(material.ID > 0);
            }
        }
コード例 #3
0
ファイル: MaterialModel.cs プロジェクト: BizzyQuote/BQ2013
        public MaterialModel(Material material)
        {
            Name = material.Name;
            SubName = material.SubName;
            UnitCost = material.UnitCost.GetValueOrDefault();
            Measurement = material.Measurement;
            Height = material.Height.GetValueOrDefault();
            Width = material.Width.GetValueOrDefault();
            Thickness = material.Thickness;
            Texture = material.Texture;
            Finish = material.Finish;
            Overlap = material.Overlap.GetValueOrDefault();
            SKU = material.SKU;
            IsActive = material.IsActive;
            ID = material.ID;
            CreatedOn = material.CreatedOn;
            ModifiedOn = material.ModifiedOn;
            ManufacturerID = material.ManufacturerID;

            var values = from Measurement e in Enum.GetValues(typeof(Measurement))
                         select new { Id = e, Name = e.ToString() };
            MeasurementList = new SelectList(values, "Id", "Name");
        }
コード例 #4
0
        public ActionResult EditMaterial(MaterialModel model)
        {
            using (var mm = new MaterialsManager())
            {
                // TODO: Refactor into an extention method that uses generics
                var material = new Material
                {
                    Name = model.Name,
                    SubName = model.SubName,
                    Measurement = model.Measurement,
                    CreatedOn = model.CreatedOn,
                    ModifiedOn = model.ModifiedOn,
                    UnitCost = model.UnitCost,
                    IsActive = model.IsActive,
                    ManufacturerID = model.ManufacturerID,
                    Height = model.Height,
                    Width = model.Width,
                    Thickness = model.Thickness,
                    Texture = model.Texture,
                    Finish = model.Finish,
                    Overlap = model.Overlap,
                    SKU = model.SKU,
                    ID = model.ID
                };

                material = mm.EditMaterial(material);
            }

            return RedirectToAction("Materials");
        }
コード例 #5
0
 partial void DeleteMaterial(Material instance);
コード例 #6
0
 partial void UpdateMaterial(Material instance);
コード例 #7
0
 partial void InsertMaterial(Material instance);
コード例 #8
0
		private void detach_Materials(Material entity)
		{
			this.SendPropertyChanging();
			entity.Manufacturer = null;
		}
コード例 #9
0
ファイル: MaterialsManager.cs プロジェクト: BizzyQuote/BQ2013
        public Material EditMaterial(Material material)
        {
            material.ModifiedOn = DateTime.Now;
            Material dbMaterial = SingleMaterial(material.ID);

            // get the database columns which need to be updated
            var databaseMembers =
                db.Mapping.MappingSource.GetModel(typeof(BizzyQuoteDataContext)).GetMetaType(typeof(Material)).DataMembers
                    .Where(d => d.IsAssociation == false && d.IsDbGenerated == false && d.IsPersistent == true);

            // reflect to get instances of the entity preoprties
            var editProperties =
                from p in dbMaterial.GetType().GetProperties()
                join m in databaseMembers on p.Name equals m.Name
                select p;

            // copy the values
            PropertyInfo[] editProps = editProperties.ToArray();
            foreach (PropertyInfo propertyInfo in editProps)
            {
                propertyInfo.SetValue(dbMaterial, propertyInfo.GetValue(material, null), null);
            }

            db.SubmitChanges();
            return dbMaterial;
        }
コード例 #10
0
ファイル: MaterialsManager.cs プロジェクト: BizzyQuote/BQ2013
        public Material CreateMaterial(Material material)
        {
            material.CreatedOn = DateTime.Now;
            material.ModifiedOn = DateTime.Now;

            db.Materials.InsertOnSubmit(material);
            db.SubmitChanges();
            return material;
        }