public async Task CanAddAttendanceCanGetAttendance() { bool added = await gymRepository.addGym(new Gym { GymId = 15, GymName = "New", GymBranch = "Gym" }); Assert.True(added); GymAttendenceAddModel request = new GymAttendenceAddModel { gymid = 15, time = "15:00", day = 1, month = 9, year = 2020 }; var response = await attendanceController.addAttendence(request); Assert.IsType <OkObjectResult>(response.Result); var response1 = await attendanceController.getAttendence(15); Assert.NotEmpty(response1.Value); }
public async Task <ActionResult <GymAttendanceRecord> > addAttendence(GymAttendenceAddModel record) { Gym gym = await gymRepository.getGymById(record.gymid); if (gym == null) { return(StatusCode(StatusCodes.Status404NotFound, "Gym not found!")); } GymAttendanceRecord attendance = await gymAttendenceRepository.getAttendenceRecord(record.gymid, record.time, record.day, record.month, record.year); if (attendance == null) { attendance = new GymAttendanceRecord(); attendance.GymId = record.gymid; attendance.Time = record.time; attendance.Day = record.day; attendance.Month = record.month; attendance.Year = record.year; attendance.Count = 0; if (!await gymAttendenceRepository.addAttendence(attendance)) { return(StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while attempting to create a new record!")); } } attendance.Count++; if (await gymAttendenceRepository.updateAttendence(attendance)) { return(Ok(attendance)); } else { return(StatusCode(StatusCodes.Status500InternalServerError, "An error occured while updating the record in the database!")); } }