Exemplo n.º 1
0
        public async Task <IActionResult> CreateboardEnrollment([FromBody] BoardEnrollmentResource boardEnrollmentResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var boardEnrollment = mapper.Map <BoardEnrollmentResource, BoardEnrollment>(boardEnrollmentResource);

            boardEnrollment.Lecturer = await lecturerRepository.GetLecturer(boardEnrollmentResource.LecturerID);

            boardEnrollment.Board = await boardRepository.GetBoard(boardEnrollmentResource.BoardID);

            if (boardEnrollment.Score != null)
            {
                boardEnrollment.isMarked = true;
            }

            boardEnrollmentRepository.UpdateRecommendations(boardEnrollment, boardEnrollmentResource);

            boardEnrollmentRepository.AddBoardEnrollment(boardEnrollment);

            await unitOfWork.Complete();

            boardEnrollment = await boardEnrollmentRepository.GetBoardEnrollment(boardEnrollment.BoardEnrollmentId);

            var result = mapper.Map <BoardEnrollment, BoardEnrollmentResource>(boardEnrollment);

            return(Ok(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateRecommendation([FromBody] RecommendationResource recommendationResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var recommendation = mapper.Map <RecommendationResource, Recommendation>(recommendationResource);

            recommendationRepository.AddRecommendation(recommendation);

            recommendation.BoardEnrollment = await boardEnrollmentRepository.GetBoardEnrollment(recommendationResource.BoardEnrollmentId);

            await unitOfWork.Complete();

            recommendation = await recommendationRepository.GetRecommendation(recommendation.RecommendationId);

            var result = mapper.Map <Recommendation, RecommendationResource>(recommendation);

            return(Ok(result));
        }