Exemple #1
0
        //[HttpGet("new")]
        //public ActionResult Create() {
        //	var model = new EventViewModel { SquadList = GetSquadList(), EventTypes = GetEventTypeList() };
        //	return View(model);
        //}

        // POST: Sessions/Create
        //[HttpPost("new")]
        //[ValidateAntiForgeryToken]
        //public ActionResult Create(EventViewModel model) {
        //	if (!ModelState.IsValid) {
        //		model.SquadList = GetSquadList();
        //		return View(model);
        //	}

        //	try {
        //		EventSetupRequest request = Map(model);
        //		var response = eventService.CreateEvent(request);
        //		if (!response.RequestIsFulfilled) {
        //			foreach (var error in response.Errors)
        //				ModelState.AddModelError("", error);

        //			model.SquadList = GetSquadList();
        //			model.EventTypes = GetEventTypeList();
        //			return View(model);
        //		}

        //		return RedirectToAction(nameof(Index));
        //	} catch {
        //		return View();
        //	}
        //}

        private List <SelectListItem> GetSquadList()
        {
            var clubSquads = squadQuery.GetSquads(club.Guid);
            var squadList  = clubSquads.Select(s => new SelectListItem {
                Text = $"{s.Name}", Value = s.Guid.ToString()
            })
                             .OrderBy(s => s.Text)
                             .ToList();

            return(squadList);
        }
Exemple #2
0
        private List <SelectListItem> GetSquadList(Guid memberId)
        {
            var squads = squadQuery.GetSquads(club.Guid);

            if (!memberId.IsEmpty())
            {
                var player = memberQuery.GetPlayer(memberId);
                squads = squadQuery.GetMemberSquads(memberId, Membership.Player);
            }

            var squadList = squads.Select(s => new SelectListItem {
                Text = $"{s.Name}", Value = s.Guid.ToString()
            })
                            .OrderBy(s => s.Text)
                            .ToList();

            return(squadList);
        }
Exemple #3
0
        private (bool isValid, IEnumerable <Squad> squads, IEnumerable <TrainingMaterial> trainingMaterials, Response response) Validate(EventSetupRequest request)
        {
            var validationResult = setUpRequestValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(false, null, null, Response.CreateResponse(validationResult.Messages));
            }

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

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

            var clubSquads = squadQuery.GetSquads(club.Guid);
            var allOfRequestedSquadsBelongToClub = !request.Squads.Except(clubSquads.Select(s => s.Guid)).Any();

            if (!allOfRequestedSquadsBelongToClub)
            {
                return(false, null, null, Response.CreateResponse(new IllegalOperationException("Not all of specified squads belong to this club")));
            }

            List <TrainingMaterial> trainingMaterials = null;

            if (request.TrainingMaterials != null && request.TrainingMaterials.Any())
            {
                var clubTrainingMaterials = libraryQuery.GetTrainingMaterials(club.Guid);
                var allOfRequestedMaterialsBelongToClub = !request.TrainingMaterials.Except(clubTrainingMaterials.Select(t => t.Guid)).Any();
                if (!allOfRequestedMaterialsBelongToClub)
                {
                    return(false, null, null, Response.CreateResponse(new IllegalOperationException("Not all of specified materials belong to this club")));
                }

                trainingMaterials = request.TrainingMaterials.Join(clubTrainingMaterials, t1 => t1, t2 => t2.Guid, (guid, trainignMaterial) => trainignMaterial).ToList();
            }

            var squads = request.Squads.Join(clubSquads, s1 => s1, s2 => s2.Guid, (guid, squad) => squad).ToList();

            return(true, squads, trainingMaterials, Response.CreateSuccessResponse());
        }
Exemple #4
0
        public Response UpdateSquadProfile(SquadRequest request)
        {
            var errors = Validate(request, true);

            if (errors.Count() > 0)
            {
                return(Response.CreateResponse(errors));
            }

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

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

            var squad = squadQuery.GetSquad(request.SquadId.Value);

            if (squad == null || squad.ClubId != request.ClubId)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified squad does not exist")));
            }

            var squads = squadQuery.GetSquads(request.ClubId);

            try {
                squadRepository.UpdateSquad(new Squad(club.Guid, request.SquadId)
                {
                    Name = request.SquadName
                });
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }

            return(Response.CreateSuccessResponse());
        }
Exemple #5
0
        public Response Track(EventTrainingMaterialViewRequest request)
        {
            var validationResult = eventTrainingMaterialViewValidator.Validate(request);

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

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

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

            var @event = eventQuery.GetEvent(request.EventId);

            if (@event == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified event was not found")));
            }
            else if (@event.ClubId != request.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified event does not belong to this club")));
            }
            else if ([email protected]())
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified event is not attributed to any squad")));
            }

            var trainingMaterial = libraryQuery.GetTrainingMaterial(request.TrainingMaterialId);

            if (trainingMaterial == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified training material does not exist")));
            }
            else if ([email protected](t => t.Guid == request.TrainingMaterialId))
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified training material does not belong to this event")));
            }

            var    clubSquads = squadQuery.GetSquads(request.ClubId);
            Member member     = request.Membership == Core.Membership.Coach ? memberQuery.GetCoach(request.MemberId) as Member : memberQuery.GetPlayer(request.MemberId) as Member;
            var    l1         = member.Squads.Intersect(clubSquads.Select(s => s.Guid)).ToList();
            var    l2         = clubSquads.Select(s => s.Guid).Intersect(member.Squads).ToList();

            if (member == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified member does not exist")));
            }
            else if (clubSquads == null || !member.Squads.Intersect(clubSquads.Select(s => s.Guid)).Any())
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified member does not belong to any squad")));
            }
            else if ([email protected](s => s.Guid).Intersect(member.Squads).Any())
            {
                return(Response.CreateResponse(new IllegalOperationException("This member is not concerned by this event")));
            }

            try
            {
                trackerRepository.Track(request);
                return(Response.CreateSuccessResponse());
            }
            catch (Exception ex)
            {
                return(Response.CreateResponse(ex));
            }
        }
Exemple #6
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));
            }
        }