Beispiel #1
0
        public async Task <ActionResult <bool> > CreateUserAttendance(
            [FromRoute] Guid classroomId,
            [FromRoute] Guid lessonId,
            [FromBody] int code
            )
        {
            var user = (ApplicationUser)HttpContext.Items["ApplicationUser"];

            Debug.Assert(user != null, nameof(user) + " != null");

            try
            {
                var classroom = await _classroomService.FindAsync(classroomId);

                var authorization = await _authorizationService.AuthorizeAsync(User, classroom, "IsInClassroom");

                if (!authorization.Succeeded)
                {
                    return(Forbid());
                }

                var lesson = await _lessonService.FindAsync(classroomId);

                var success = await _attendanceService.CreateUserAttendanceAsync(lesson, user, code);

                return(Ok(success));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }