Exemple #1
0
        public async Task <int> CreateAssignment(CreateAssignmentInputModel createAssignmentInputModel)
        {
            var mapInputModelToEntity = _mapper.Map <CreateAssignmentInputModel, Assignment>(createAssignmentInputModel);

            var createAssignmentCallback = await Task.FromResult(_assignmentRepository.CreateAssignment(mapInputModelToEntity));

            return(createAssignmentCallback.Result);
        }
        public AssignmentVM Post(string dictaatName, [FromBody] AssignmentFormVM form)
        {
            if (!AuthorizeResource(dictaatName))
            {
                return(null);
            }

            return(_assignmentRepo.CreateAssignment(dictaatName, form));
        }
        public ActionResult <AssignmentDto> createAssignment(AssignmentDto assignmentDto)
        {
            var assignmentToCreate = _mapper.Map <Assignment>(assignmentDto);

            _repository.CreateAssignment(assignmentToCreate);
            _repository.SaveChanges();

            var createdAssignment = _mapper.Map <AssignmentDto>(assignmentToCreate);

            return(CreatedAtRoute(nameof(findAssignmentById), new { Id = createdAssignment.AssignmentId }, assignmentDto));
        }
Exemple #4
0
        public async Task <AssignmentResponseDto> CreateAssignment(CreateAssignmentRequestDto createAssignmentRequestDto)
        {
            _logger.LogInfo("Creating new assignment ...");

            var assignment = _mapper.Map <Assignment>(createAssignmentRequestDto);
            await _assignmentRepository.CreateAssignment(assignment);

            if (await _assignmentRepository.SaveAll())
            {
                return(_mapper.Map <AssignmentResponseDto>(assignment));
            }
            else
            {
                _logger.LogError("Something went wront while trying to create new assignment ...");
                throw new UnknownException("Something went wront while trying to create new assignment.", DomainConsts.APPLICATION_NAME);
            }
        }
Exemple #5
0
        public Response CreateAssignment(AssignmentRequest request)
        {
            var result = assignementRequestValidator.Validate(request);

            if (!result.IsValid)
            {
                return(Response.CreateResponse(result.Messages));
            }

            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }

            var coach = memberQuery.GetCoach(request.CoachId);

            if (coach == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified coach does not exist")));
            }
            else if (coach.ClubId != club.Guid)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified coach does not belong to this club")));
            }

            var clubSquads = squadQuery.GetSquads(club.Guid);

            if (request.Squads?.Count() > 0)
            {
                var allOfRequestedSquadsBelongToClub = !request.Squads.Except(clubSquads.Select(s => s.Guid)).Any();
                if (!allOfRequestedSquadsBelongToClub)
                {
                    return(Response.CreateResponse(new IllegalOperationException("Not all of specified squads belong to this club")));
                }
            }

            if (request.Players?.Count() > 0)
            {
                var members = memberQuery.GetMembers(clubSquads.Select(s => s.Guid));
                var players = members.SelectMany(s => s.Members)?.Where(m => m.Membership.Equals("Player"));

                var allOfRequestedPlayersBelongToClub = !request.Players.Except(players.Select(p => p.Guid)).Any();
                if (!allOfRequestedPlayersBelongToClub)
                {
                    return(Response.CreateResponse(new IllegalOperationException("Not all of specified players belong to this club")));
                }
            }

            if (request.TrainingMaterials?.Count() > 0)
            {
                var clubLibrary = libraryQuery.GetTrainingMaterials(request.ClubId);
                var allOfRequestedMaterialsBelongToClub = !request.TrainingMaterials.Except(request.TrainingMaterials).Any();
                if (!allOfRequestedMaterialsBelongToClub)
                {
                    return(Response.CreateResponse(new IllegalOperationException("Not all of specified training materials belong to this club")));
                }
            }

            try
            {
                assignmentRepository.CreateAssignment(request);
                return(Response.CreateSuccessResponse());
            }catch (Exception ex)
            {
                return(Response.CreateResponse(ex));
            }
        }