Ejemplo n.º 1
0
        public async Task <IActionResult> CreateMeeting(int id, MeetingRequest request)
        {
            try
            {
                Optional <int> meetingId;

                if (request.DateTime != new DateTime().ToUniversalTime())
                {
                    meetingId = await _meetingService.CreateMeeting(request.DateTime.ToUniversalTime(), id);
                }
                else
                {
                    meetingId = await _meetingService.CreateMeeting(id);
                }


                if (meetingId.IsEmpty)
                {
                    return(StatusCode(500));
                }

                int meeting = meetingId.Value;

                int rowsAffected = await _meetingService.AddAllTasks(meeting, request.Tasks);

                if (rowsAffected < 0)
                {
                    return(StatusCode(500));
                }

                rowsAffected = await _meetingService.InviteAllUsers(meeting, request.InvitedUsers);

                if (rowsAffected < 0)
                {
                    return(StatusCode(500));
                }

                return(Ok(new MeetingIdResponse {
                    MeetingId = meeting
                }));
            }
            catch (UnauthorizedAccessException)
            {
                return(Forbid());
            }
            catch (InvalidOperationException e)
            {
                return(BadRequest(new ErrorResponse {
                    Message = e.Message
                }));
            }
        }