public ActionResult AddMeasurement(Measurement measurement) { if (ModelState.IsValid) { //Add the date measurement.MeasurementDate = DateTime.Now; //Associate the batch with the measurement int batchId = (int)Session["CurrentBatchId"]; Batch batch = db.Batches.Find(batchId); measurement.Batch = batch; db.Entry(measurement).State = EntityState.Added; batch.Measurements.Add(measurement); db.SaveChanges(); return RedirectToAction("Details/" + batch.BatchId); } return View(measurement); }
public void TestAddMeasurement() { Batch batch = new Batch(); batch.Name = "Test"; batch.Type = BatchType.Wine; batch.StartDate = DateTime.Now; context.Batches.Add(batch); Measurement measurement = new Measurement(); measurement.Batch = batch; measurement.Description = "This is a test!"; measurement.Measured = "Gravity"; measurement.Value = 1.01; measurement.MeasurementDate = DateTime.Now; context.Measurements.Add(measurement); context.SaveChanges(); Assert.IsTrue(batch.Measurements.Contains(measurement)); }
public static Measurement createMeasurement(Batch batch, String name, String description, String measured, Double value) { BrewersBuddyContext db = new BrewersBuddyContext(); Measurement measurment = new Measurement(); measurment.Batch = batch; measurment.Name = name; measurment.Description = description; measurment.Measured = measured; measurment.MeasurementDate = DateTime.Now; measurment.Value = value; db.Measurements.Add(measurment); db.SaveChanges(); return measurment; }