Beispiel #1
0
        public async Task <ActionResult <string> > CreateMeetingReport(string builderId, [FromBody] CreateMeetingReportModel createMeetingReportModel)
        {
            var currentUserId = User.Identity.Name;

            try
            {
                await _buildersService.CreateMeetingReportAsync(currentUserId, builderId, createMeetingReportModel);
            }
            catch (UnauthorizedAccessException e)
            {
                return(Unauthorized($"You are not authorized: {e.Message}"));
            }
            catch (Exception e)
            {
                return(BadRequest($"Their was an error creating the meeting report: {e.Message}"));
            }

            return(Ok());
        }
Beispiel #2
0
        // Manage meeting reports
        public async Task <string> CreateMeetingReportAsync(string currentUserId, string builderId, CreateMeetingReportModel toCreate)
        {
            Coach coach = await GetCoachFromUserId(currentUserId);

            if (coach == null)
            {
                throw new Exception("You are not a coach");
            }

            Builder builder = await GetBuilderFromBuilderId(builderId);

            if (builder == null)
            {
                throw new Exception("The builder for the meeting report doesn't exist...");
            }
            if (builder.CoachId != coach.Id)
            {
                throw new UnauthorizedAccessException("You are not the coach of the builder");
            }

            MeetingReport meetingReport = new MeetingReport()
            {
                BuilderId = builderId,
                CoachId   = coach.Id,

                Date            = DateTime.Now,
                NextMeetingDate = toCreate.NextMeetingDate,

                Objectif  = toCreate.Objectif,
                Evolution = toCreate.Evolution,
                WhatsNext = toCreate.WhatsNext,
                Comments  = toCreate.Comments
            };

            await _meetingRepors.InsertOneAsync(meetingReport);

            return(meetingReport.Id);
        }