//[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}); }
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); } }
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"); }
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"); }
partial void DeleteMaterial(Material instance);
partial void UpdateMaterial(Material instance);
partial void InsertMaterial(Material instance);
private void detach_Materials(Material entity) { this.SendPropertyChanging(); entity.Manufacturer = null; }
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; }
public Material CreateMaterial(Material material) { material.CreatedOn = DateTime.Now; material.ModifiedOn = DateTime.Now; db.Materials.InsertOnSubmit(material); db.SubmitChanges(); return material; }