public async Task <JsonResult> AddAttendance([FromBody] AddAttendanceViewModel addAttendanceViewModel) { bool isSuccessful = false; var eventId = addAttendanceViewModel.EventId; var familyId = addAttendanceViewModel.FamilyMemberId; var isExisting = Context.EventsFamilyMembers.Any(efm => efm.FamilyMemberId == addAttendanceViewModel.FamilyMemberId && efm.EventId == addAttendanceViewModel.EventId); if (!isExisting) { Context.EventsFamilyMembers.Add( new EventsFamilyMembers() { EventId = addAttendanceViewModel.EventId, FamilyMemberId = addAttendanceViewModel.FamilyMemberId } ); await Context.SaveChangesAsync(); isSuccessful = true; } return(Json(new { success = isSuccessful })); }
public async Task <IActionResult> CreateAttendance(AddAttendanceViewModel attendance, List <string> studentList) { { Classroom classroom = _context.Classroom.Include(c => c.Students) .Where(c => c.ClassName == attendance.Classroom).FirstOrDefault(); if (classroom == null) { return(NotFound()); } string students = studentList != null?String.Join(",", studentList) : ""; Attendance _attendance = new Attendance() { AttendanceDate = attendance.AttendanceDate, Classroom = classroom, PresetStudentMatricNumber = students, }; _context.Add(_attendance); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } }