public IActionResult CreateDive(ViewAddLog NewViewAddLog) { System.Console.WriteLine(ModelState.Count); System.Console.WriteLine(ModelState.ValidationState); System.Console.WriteLine("Diver ID: " + NewViewAddLog.NewDiverLog.DiverID); System.Console.WriteLine("Site ID: " + NewViewAddLog.NewDiverLog.DiveSiteID); System.Console.WriteLine("Dive Num: " + NewViewAddLog.NewDiverLog.DiveNumber); System.Console.WriteLine("Dive Date: " + NewViewAddLog.NewDiverLog.DiveDate); System.Console.WriteLine("Bottom Time: " + NewViewAddLog.NewDiverLog.BottomTime); System.Console.WriteLine("Max Depth: " + NewViewAddLog.NewDiverLog.MaxDepth); System.Console.WriteLine("Tank Start: " + NewViewAddLog.NewDiverLog.TankStartPSI); System.Console.WriteLine("Tank End: " + NewViewAddLog.NewDiverLog.TankEndPSI); System.Console.WriteLine("Dive Start: " + NewViewAddLog.NewDiverLog.DiveStartTime); System.Console.WriteLine("Dive Stop: " + NewViewAddLog.NewDiverLog.DiveStopTime); System.Console.WriteLine("Safety Time: " + NewViewAddLog.NewDiverLog.SafetyStopTime); System.Console.WriteLine("Safety Depth: " + NewViewAddLog.NewDiverLog.SafetyStopDepth); System.Console.WriteLine("PGEntry: " + NewViewAddLog.NewDiverLog.PressureGroupEntry); System.Console.WriteLine("PGExit: " + NewViewAddLog.NewDiverLog.PressureGroupExit); System.Console.WriteLine("SI: " + NewViewAddLog.NewDiverLog.SurfaceInterval); System.Console.WriteLine("Water Temp: " + NewViewAddLog.NewDiverLog.WaterTemp); int?diverid = HttpContext.Session.GetInt32("sessionid"); if (diverid != null) { System.Console.WriteLine("if statement 1 - session test"); System.Console.WriteLine(ModelState.IsValid); ViewAddLog NewDL = new ViewAddLog(); if (NewViewAddLog.NewDiverLog.DiveDate > DateTime.Now) { System.Console.WriteLine("if statement 2"); NewDL.ThisDiver = dbContext.Divers.Include(l => l.DiverLogs).SingleOrDefault(d => d.DiverID == diverid); ViewBag.LogNum = NewDL.ThisDiver.DiverLogs.Count() + 1; NewDL.DiveLocations = dbContext.DiveSites.ToList(); return(View("AddDive", NewDL)); } System.Console.WriteLine(ModelState.IsValid); if (ModelState.IsValid) { System.Console.WriteLine("if statement 3 - modelstate isvalid"); DiverLog CreateDiverLog = new DiverLog(); CreateDiverLog = NewViewAddLog.NewDiverLog; CreateDiverLog.DiverID = dbContext.Divers.SingleOrDefault(d => d.DiverID == (int)diverid).DiverID; CreateDiverLog.DiveSiteID = NewViewAddLog.NewDiverLog.DiveSiteID; CreateDiverLog.PressureGroupEntry = Char.ToUpper(NewViewAddLog.NewDiverLog.PressureGroupEntry); CreateDiverLog.PressureGroupExit = Char.ToUpper(NewViewAddLog.NewDiverLog.PressureGroupExit); dbContext.Add(CreateDiverLog); dbContext.SaveChanges(); // System.Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(CreateDiverLog)); return(Redirect("/displaylogs")); } NewDL.ThisDiver = dbContext.Divers.Include(l => l.DiverLogs).SingleOrDefault(d => d.DiverID == diverid); ViewBag.LogNum = NewDL.ThisDiver.DiverLogs.Count() + 1; NewDL.DiveLocations = dbContext.DiveSites.ToList(); return(View("AddDive", NewDL)); } return(Redirect("/")); }
public IActionResult AddDive() { int?diverid = HttpContext.Session.GetInt32("sessionid"); if (diverid != null) { ViewAddLog NewDL = new ViewAddLog(); NewDL.ThisDiver = dbContext.Divers.Include(l => l.DiverLogs).SingleOrDefault(d => d.DiverID == diverid); System.Console.WriteLine("Number of Logs: " + NewDL.ThisDiver.DiverLogs.Count()); ViewBag.LogNum = NewDL.ThisDiver.DiverLogs.Count() + 1; NewDL.DiveLocations = dbContext.DiveSites.ToList(); // System.Console.WriteLine(ModelState.Count); // System.Console.WriteLine(ModelState.ValidationState); // System.Console.WriteLine(ModelState.Values); return(View(NewDL)); } return(Redirect("/")); }