예제 #1
0
        /// <summary>
        /// Get geocache item by Id.
        /// </summary>
        /// <param name="id">The id of the geocache item.</param>
        /// <returns>GeocacheItemModel of the geocache item.</returns>
        public async Task <GeocacheItemModel> GetGeocacheItem(int id)
        {
            if (id <= 0)
            {
                throw new ArgumentException("Invalid id in DataService.GetGeocacheItem(id)");
            }

            var geocacheItem = await GeocacheItemsQueries.GetGeocacheItem(this.dbContext, id);

            return(geocacheItem ?? new GeocacheItemModel());
        }
예제 #2
0
        /// <summary>
        /// Get geocache item by name.
        /// </summary>
        /// <param name="name">The name of the geocache item.</param>
        /// <returns>GeocacheItemModel of the geocache item.</returns>
        public async Task <GeocacheItemModel> GetGeocacheItem(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Invalid name in DataService.GetGeocacheItem(name)");
            }

            var geocacheItems = await GeocacheItemsQueries.GetGeocacheItem(this.dbContext, name);

            return(geocacheItems ?? new GeocacheItemModel());
        }
예제 #3
0
        /// <summary>
        /// Create geocache item with given geocache item data.
        /// </summary>
        /// <param name="geocacheItem">The geocache item data.</param>
        /// <returns>GeocacheItemModel of the created geocache item.</returns>
        public async Task <GeocacheItemModel> CreateGeocacheItem(IGeocacheItemModel geocacheItem)
        {
            if (geocacheItem == null)
            {
                throw new ArgumentException("Invalid geocacheItem in DataService.CreateGeocacheItem()");
            }

            var newGeocacheItem = await GeocacheItemsQueries.CreateGeocacheItem(this.dbContext, geocacheItem);

            geocacheItem = GeocacheItemModelFactory.ConvertFromGeocacheItem(newGeocacheItem);

            return((GeocacheItemModel)geocacheItem);
        }
예제 #4
0
        /// <summary>
        /// Get geocache items by geocache id.
        /// </summary>
        /// <param name="geocacheId">The geocache id to search for.</param>
        /// <param name="activeOnly"><c>true</c> to only include active geocache items; otherwise, <c>false</c> include all results.</param>
        /// <returns>List GeocacheItemModel of geocache items found by geocache id.</returns>
        public async Task <IEnumerable <GeocacheItemModel> > GetGeocacheItemsByGeocacheId(int geocacheId, bool activeOnly)
        {
            if (geocacheId <= 0)
            {
                throw new ArgumentException("Invalid geocacheId in DataService.GetGeocacheItemsByGeocacheId()");
            }

            var geocacheItems = await GeocacheItemsQueries.GetGeocacheItemsByGeocacheId(this.dbContext, geocacheId);

            if (activeOnly)
            {
                geocacheItems = geocacheItems.Where(x => x.IsActive);
            }

            return(geocacheItems.ToSafeList());
        }
예제 #5
0
        /// <summary>
        /// Updates the GeocacheId of the given Geocache item id.
        /// </summary>
        /// <param name="patchModel">The patch model to update the GeocacheId.</param>
        /// <returns>GeocacheItemModel of the updated geocache item.</returns>
        public async Task <GeocacheItemModel> PatchGeocacheItemGeocacheId(IGeocacheItemPatchGeocacheIdModel patchModel)
        {
            if (patchModel.Id <= 0)
            {
                throw new ArgumentException("Invalid id in DataService.PatchGeocacheItemGeocacheId()");
            }

            if (patchModel.GeocacheId <= 0)
            {
                throw new ArgumentException("Invalid geocacheId in DataService.PatchGeocacheItemGeocacheId()");
            }

            var newGeocacheItem = await GeocacheItemsQueries.UpdateGeocacheItemGeocacheId(this.dbContext, patchModel);

            var geocacheItemModel = GeocacheItemModelFactory.ConvertFromGeocacheItem(newGeocacheItem);

            return((GeocacheItemModel)geocacheItemModel);
        }