Пример #1
0
        public async Task <ActionResult <Guid> > Post([FromBody] ClubDto club)
        {
            if (club == null)
            {
                throw new ArgumentNullException(nameof(club));
            }
            // special handling here, so that user can create new club if they have
            // global permissions.
            bool canEdit = false;

            if (club.Id == default)
            {
                canEdit = await _authService.CanUserEdit(User, club.Initials);
            }
            else
            {
                canEdit = await _authService.CanUserEdit(User, club.Id);
            }
            if (!canEdit)
            {
                return(Unauthorized());
            }

            var clubBizObj = _mapper.Map <Club>(club);
            await _clubService.SaveNewClub(clubBizObj);

            var savedClub = (await _clubService.GetClubs(false)).First(c => c.Initials == club.Initials);

            return(Ok(savedClub.Id));
        }
Пример #2
0
    public async Task ProcessRequest(
        Guid id,
        bool test,
        Guid?copyFromClubId)
    {
        var request = await _coreClubRequestService.GetRequest(id);

        request.ClubInitials = request.ClubInitials.ToUpperInvariant();

        Guid newClubId;

        if (copyFromClubId.HasValue && copyFromClubId.Value != Guid.Empty)
        {
            newClubId = await CopyClub(copyFromClubId.Value, request, test);

            request.TestClubId = newClubId;
            request.RequestApproved ??= DateTime.UtcNow;
            await _coreClubRequestService.UpdateRequest(request);
        }
        else
        {
            var baseScoringSystem = await _coreScoringService.GetSiteDefaultSystemAsync();

            ScoringSystem newScoringSystem = new ScoringSystem
            {
                ParentSystemId = baseScoringSystem.Id,
                Name           = $"{request.ClubInitials} scoring based on App. A Rule 5.3",
                DiscardPattern = "0,1"
            };

            var initialsToUse = request.ClubInitials + (test ? "TEST" : "");
            var club          = new Core.Model.Club
            {
                Id                   = Guid.Empty,
                Name                 = request.ClubName,
                Initials             = initialsToUse,
                IsHidden             = true,
                Url                  = request.ClubWebsite,
                DefaultScoringSystem = newScoringSystem,
                Description          = (String.IsNullOrWhiteSpace(request.ClubLocation) ? (string)null : "_" + request.ClubLocation + "_"),
                ScoringSystems       = new List <ScoringSystem> {
                    newScoringSystem
                }
            };

            newClubId = await _coreClubService.SaveNewClub(club);

            ClearClubMemoryCache();

            if (club.IsHidden)
            {
                request.TestClubId = newClubId;
            }
            else
            {
                request.VisibleClubId = newClubId;
            }
            request.RequestApproved ??= DateTime.UtcNow;
            await _coreClubRequestService.UpdateRequest(request);
        }

#pragma warning disable CA1308 // Normalize strings to uppercase
        // we are storing email in lowercase, and not round-tripping back to upper case.
        await _coreUserService.AddPermission(newClubId, request.ContactEmail.ToLowerInvariant());

#pragma warning restore CA1308 // Normalize strings to uppercase
    }