public ActionResult CreateMeasurement(MeasurementViewModel measure) { ViewBag.CurrentPage = "Children"; try { //string sessionId = (string)HttpContext.Items["AspSession"]; Child child = _childService.GetChildForSession(User.Identity.Name); measure.CaptureMeasurement.ChildID = child.IdNumber; measure.CaptureMeasurement.Created = DateTime.Now; db.ChildMeasurements.Add(measure.CaptureMeasurement); db.SaveChanges(); return RedirectToAction("Index"); } catch (Exception ex) { return RedirectToAction("Index"); } }
public ActionResult Measurements(string childId) { ViewBag.CurrentPage = "Children"; try { if (string.IsNullOrEmpty(childId)) { Child child = _childService.GetChildForSession(User.Identity.Name); childId = child.IdNumber; } List<ChildMeasurement> measures = db.ChildMeasurements.Where(m => m.ChildID == childId).ToList(); MeasurementViewModel measureVM = new MeasurementViewModel(measures); return View(measureVM); } catch (Exception ex) { return RedirectToAction("Index"); } }
public ActionResult CreateMeasurement(string id) { ViewBag.CurrentPage = "Children"; try { //string sessionId = (string)HttpContext.Items["AspSession"]; Child child = _childService.GetChildForSession(User.Identity.Name); if (child == null) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } child = db.Children.Find(id); if (child == null) { return HttpNotFound(); } _childService.SetChildForSession(User.Identity.Name, child); } List<ChildMeasurement> measures = db.ChildMeasurements.Where(m => m.ChildID == id).ToList(); MeasurementViewModel measureVM = new MeasurementViewModel(measures); return View(measureVM); //if (child == null) child = (Child)Session["User"]; //var sessionId = HttpContext.Items["AspSession"]; //return View(); } catch (Exception ex) { return RedirectToAction("Index"); } }