예제 #1
0
        public async Task <bool> JoinPartyAsync(PartyCodeDTO partyCode, PartyGoer attendee)
        {
            try
            {
                Party party = await _partyRepository.GetAsync(partyCode);

                if (party == null)
                {
                    return(false);
                }

                return(await JoinPartyAsync(party.Id, attendee));
            }
            catch (Exception ex)
            {
                await _logService.LogExceptionAsync(ex, "Error occurred in JoinPartyAsync");

                return(false);
            }
        }
예제 #2
0
        public async Task <IActionResult> Get(ObjectId id)
        {
            if (!ModelState.IsValid || id == ObjectId.Empty)
            {
                return(BadRequest());
            }

            var obj = await _partyRepository.GetAsync(id);

            if (obj == null)
            {
                return(NotFound());
            }

            obj.CleanChildEntites();

            return(Ok(obj));
        }
예제 #3
0
        /// <summary>
        /// Try a cascading series of attempts to get a matching entity
        /// </summary>
        /// <param name="party"></param>
        private async Task <Party> RefreshParty(Party party)
        {
            // First try by id
            if (party.id.HasValue && party.id.Value != ObjectId.Empty)
            {
                var partyById = await _partyRepository.GetAsync(party.id.Value);

                if (!ReferenceEquals(partyById, null))
                {
                    return(partyById);
                }
            }

            _entityRefreshNeeded = true;

            // Then try a 'full' match
            var partyFull = await _partyRepository.FindAsync(party, false);

            if (!ReferenceEquals(partyFull, null))
            {
                return(partyFull);
            }

            // Try a 'min' match
            var partyMin = await _partyRepository.FindAsync(party, true);

            if (!ReferenceEquals(partyMin, null))
            {
                // Merge any details from the supplied entity into the found one
                // This does NOT merge IsInfrastructureOwner or the child entities of Party
                return(partyMin.Merge(party));
            }

            // There is still no match then save the supplied entity first
            party.id = await _partyRepository.AddOrUpdateAsync(party);

            return(party);
        }