public async Task <ActionResult <AttendanceResponseViewModel> > Attendance(int eventId) { AttendanceResponseViewModel ret = null; try { var _event = await _repository.GetById(eventId); if (_event == null) { return(StatusCode(404, "Evento no encontrado")); } var attendance = new Attendance() { EventId = eventId, UserName = User.Identity.Name }; if (HttpContext.Request.Method == HttpMethods.Post) { await _repository.ConfirmAttendace(attendance, _attendanceRepository); } else { await _repository.CancelAttendace(attendance, _attendanceRepository); } int count = await _attendanceRepository.CountWhere(p => p.EventId == eventId); ret = new AttendanceResponseViewModel() { Id = eventId.ToString(), Attendances = count }; } catch (AttendanceExistsException ex) { LogException(ex); return(StatusCode(403, "Evento registrado para asistencia actualmente")); } catch (AttendenceNotExistsException ex) { LogException(ex); return(StatusCode(403, "Asistencia no registrada anteriormente")); } catch (Exception ex) { LogException(ex); string _action = HttpContext.Request.Method == HttpMethods.Delete ? "cancelar" : "registrar"; return(StatusCode(400, $"Error al {_action} la asistencia al evento")); } return(Ok(ret)); }