Пример #1
0
        private async Task <IdResult> TryAddApprovedCommonPlace(
            string uniquePlaceId,
            string fullName,
            GeoCoordinate coordinate,
            List <CommonPlaceAzure> commonPlaces)
        {
            if (commonPlaces.Count < GameConstants.Mission.TemporaryCommonPlaceLimit)
            {
                return(null);
            }

            var distances = new List <double>();

            commonPlaces.ForEach(
                c => { distances.Add(c.Coordinate.ConvertToGeoCoordinate().GetDistanceTo(coordinate)); });
            var validDistances = distances.Where(d => d <= GameConstants.Mission.TemporaryCommonPlaceAccuracyRadius);

            if (validDistances.Count() < GameConstants.Mission.TemporaryCommonPlaceLimit)
            {
                return(null);
            }

            var commonPlace = new CommonPlace
            {
                Coordinate   = coordinate,
                IsApproved   = true,
                Name         = fullName,
                SettlementId = uniquePlaceId
            };

            var azureModel = commonPlace.ToAzureModel();

            return(await _azureManager.AddEntityAsync(azureModel));
        }
Пример #2
0
        /// <summary>
        ///     Adds the temp common place.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="commonPlaceAlias">The common place alias.</param>
        /// <param name="coordinate">The coordinate.</param>
        /// <returns>Task.</returns>
        public async Task <IdResult> AddCommonPlace(string userId, string commonPlaceAlias, GeoCoordinate coordinate)
        {
            var alias = await GetAlias(commonPlaceAlias);

            if (alias == null)
            {
                throw new ArgumentException("Alias invalid", nameof(commonPlaceAlias));
            }

            var user = await UserRepository.GetUser(userId);

            var uniqueCityId = user.UniqueCityId;
            var commonPlaces = (await GetCommonPlacesForAlias(uniqueCityId, alias)).ToList();

            if (commonPlaces.Any(c => c.IsApprovedCoordinate))
            {
                return(new IdResult(OperationResultStatus.Error, "Already exist approved coordinate"));
            }

            var approvedResult =
                await TryAddApprovedCommonPlace(uniqueCityId, alias.FullName, coordinate, commonPlaces);

            if (approvedResult != null)
            {
                return(approvedResult);
            }

            var commonPlace = new CommonPlace
            {
                Coordinate   = coordinate,
                IsApproved   = false,
                Name         = alias.FullName,
                SettlementId = uniqueCityId
            };

            var azureModel = commonPlace.ToAzureModel();

            return(await _azureManager.AddEntityAsync(azureModel));
        }