public async Task <IActionResult> Create([Bind("Id,Date,StartTime,EndTime,Notes,Child_Id,Teacher_Id")] Nap nap) { if (ModelState.IsValid) { nap.Id = Guid.NewGuid(); nap.Date = DateTime.Now; string y = nap.StartTime.Remove(2, 1); string x = DateTime.ParseExact(y, "HHmm", CultureInfo.CurrentCulture).ToString("hh:mm tt"); nap.StartTime = x; string z = nap.EndTime.Remove(2, 1); string a = DateTime.ParseExact(z, "HHmm", CultureInfo.CurrentCulture).ToString("hh:mm tt"); nap.EndTime = a; var teacher = await _context.Teachers.FirstOrDefaultAsync(m => m.Id == nap.Teacher_Id); nap.TeacherName = teacher.FirstName + " " + teacher.LastName; _context.Add(nap); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { id = nap.Child_Id })); } ViewData["Teacher"] = new SelectList(_context.Teachers, "Id", "FirstName", nap.Teacher_Id); return(View(nap)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhotoPath")] Child child) { if (ModelState.IsValid) { child.Id = Guid.NewGuid(); _context.Add(child); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(child)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName")] Teacher teacher) { if (ModelState.IsValid) { teacher.Id = Guid.NewGuid(); _context.Add(teacher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(teacher)); }
public async Task <IActionResult> Create([Bind("Id,Contents,Notes,Date,Time,Child_Id,Teacher_Id")] Meal meal) { if (ModelState.IsValid) { meal.Id = Guid.NewGuid(); meal.Date = DateTime.Now; string y = meal.Time.Remove(2, 1); string x = DateTime.ParseExact(y, "HHmm", CultureInfo.CurrentCulture).ToString("hh:mm tt"); meal.Time = x; var teacher = await _context.Teachers.FirstOrDefaultAsync(m => m.Id == meal.Teacher_Id); meal.TeacherName = teacher.FirstName + " " + teacher.LastName; _context.Add(meal); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { id = meal.Child_Id })); } ViewData["Teacher"] = new SelectList(_context.Teachers, "Id", "FirstName", meal.Teacher_Id); return(View(meal)); }