public void EditAlloySample(NicelideTitanumSampleModel model) { using (ObjectContext context = new ObjectContext(_connectionString)) { var sample = context.CreateObjectSet <NicelideTitanumSample>() .Include("NickelideTitaniumAlloy") .First(x => x.NicelideTitanumSampleId == model.NicelideTitanumSampleId); var alloys = context.CreateObjectSet <NickelideTitaniumAlloy>(); if (!alloys.Select(x => x.Name).Contains(model.NickelideTitaniumAlloyName)) { var alloy = new NickelideTitaniumAlloy { Name = model.NickelideTitaniumAlloyName, Description = null }; alloys.AddObject(alloy); context.SaveChanges(); } var alloyArray = context.CreateObjectSet <NickelideTitaniumAlloy>().ToList(); sample.HammerSpeed = model.HammerSpeed.Value; //sample.SampleNumber = model.SampleNumber.Value; sample.HammerThickness = model.HammerThickness.Value; sample.SampleThickness = model.SampleThickness.Value; sample.SpallSpeed = model.SpallSpeed.Value; sample.SpallStrength = model.SpallStrength.Value; sample.NickelideTitaniumAlloyId = alloyArray.First(x => x.Name == model.NickelideTitaniumAlloyName) .NickelideTitaniumAlloyId; context.SaveChanges(); } }
public ActionResult EditAlloySample(int id) { var sample = _alloyRepository.GetAlloySample(id); var model = new NicelideTitanumSampleModel { NicelideTitanumSampleId = sample.NicelideTitanumSampleId, NickelideTitaniumAlloyName = sample.NickelideTitaniumAlloy.Name, HammerSpeed = sample.HammerSpeed, SampleNumber = sample.SampleNumber, SampleThickness = sample.SampleThickness, SpallStrength = sample.SpallStrength, HammerThickness = sample.HammerThickness, SpallSpeed = sample.SpallSpeed }; var alloySamples = this._alloyRepository.GetAllAlloySamples(); ViewBag.MaxSampleNumber = alloySamples.Select(x => x.SampleNumber).Max(); var baseValues = _alloyRepository.GetNicelideTitanumQualityBaseValue(); ViewBag.MaxSampleThickness = baseValues.SampleThickness; ViewBag.MaxSpallStrength = baseValues.SpallStrength; ViewBag.MaxHammerSpeed = baseValues.HammerSpeed; ViewBag.MaxHammerThickness = baseValues.HammerThickness; ViewBag.MaxSpallSpeed = baseValues.SpallSpeed; ViewBag.IsEdit = true; return(View(model)); }
public ActionResult EditAlloySample(NicelideTitanumSampleModel model) { _alloyRepository.EditAlloySample(model); return(RedirectToAction("Index")); }