public IActionResult LoadActivity(string roomCode, int activityId) { var authenticatedPersonId = HttpContext.Session.GetSessionPersonId(); var activity = _uActivity.GetById(activityId); var room = _uRoom.GetByCode(roomCode); var roomsIds = _uRelStudentRoom.GetRoomIdByPersonId(authenticatedPersonId); if (room == null) return BadRequest(ResponseContent.Create(null, HttpStatusCode.BadRequest, $"A sala com código \"{roomCode}\" não existe!")); if (activity == null) return BadRequest(ResponseContent.Create(null, HttpStatusCode.BadRequest, "A atividade não existe!")); if (room.CurrentState != (int)ERoomState.Open) return StatusCode((int)HttpStatusCode.Unauthorized, ResponseContent.Create(null, HttpStatusCode.Unauthorized, "Você não tem acesso a essa sala pois ela esta fechada!")); if (activity.CurrentState == (int)EActivityState.Building) return StatusCode((int)HttpStatusCode.Unauthorized, ResponseContent.Create(null, HttpStatusCode.Unauthorized, "Você não tem acesso a essa atividade!")); if (!roomsIds.Contains(room.Id)) return StatusCode((int)HttpStatusCode.Unauthorized, ResponseContent.Create(null, HttpStatusCode.Unauthorized, "Você não tem acesso a essa sala/atividade!")); var answer = _uAnswer.GetByUser(activityId, authenticatedPersonId); var uploads = _uRelUploadActivity.GetByActivity(activity.Id); var attachments = answer != null ? _uRelUploadAnswer.GetByAnswer(answer.Id) : new List<RelUploadAnswer>(); var response = new MViewActivity(activity, answer, null, uploads) { Answer = { Attachments = attachments?.Select(a => a.Document.FileName).ToList() } }; return Ok(ResponseContent.Create(response, HttpStatusCode.OK, null)); }
public IActionResult LoadActivity(string roomCode, int activityId) { var sessionPersonId = HttpContext.Session.GetSessionPersonId(); var activity = _uActivity.GetById(activityId); var room = _uRoom.GetByCode(roomCode); if (room == null) { return(BadRequest(ResponseContent.Create(null, HttpStatusCode.BadRequest, $"A sala com código \"{roomCode}\" não existe!"))); } if (activity == null) { return(BadRequest(ResponseContent.Create(null, HttpStatusCode.BadRequest, "A atividade não existe!"))); } if (activity.Person.Id != sessionPersonId || room.Person.Id != sessionPersonId) { return(StatusCode((int)HttpStatusCode.Unauthorized, ResponseContent.Create(null, HttpStatusCode.Unauthorized, "Você não tem acesso a essa sala/atividade!"))); } var answers = _uAnswer.GetByActivity(activity.Id); var uploads = _uRelUploadActivity.GetByActivity(activity.Id); var response = new MViewActivity(activity, null, answers, uploads) { Answers = answers?.Select(a => new MViewAnswer(a, _uRelUploadAnswer.GetByAnswer(a.Id))).ToList() ?? new List <MViewAnswer>() }; return(Ok(ResponseContent.Create(response, HttpStatusCode.OK, null))); }