/// <summary> /// Create geocache item with give geocache item data. /// </summary> /// <param name="geocacheItem">The geocache item to create.</param> /// <returns>GeocacheItemModel of the created geocache item.</returns> public async Task <IGeocacheItemModel> CreateGeocacheItem(IGeocacheItemModel geocacheItem) { if (geocacheItem == null) { throw new ArgumentException("geocacheItem cannot be null."); } geocacheItem = await this.dataService.CreateGeocacheItem(geocacheItem); return(geocacheItem ?? new GeocacheItemModel()); }
/// <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); }
/// <summary> /// Validates the geocache item is valid. /// </summary> /// <param name="geocacheItem">The geocache item to validate.</param> /// <returns>List of strings with the collected error messages; if any.</returns> public async Task <IList <string> > ValidateGeocacheItem(IGeocacheItemModel geocacheItem) { var validationMessages = new List <string>(); if (geocacheItem == null) { validationMessages.Add("Invalid Geocache Item."); return(validationMessages); } if (geocacheItem.ActiveStartDate > geocacheItem.ActiveEndDate) { validationMessages.Add("Start Date cannot be after End Date."); } if (geocacheItem.GeocacheId <= 0) { validationMessages.Add("Invalid GeocacheId."); } var geocacheItemByName = await this.dataService.GetGeocacheItem(geocacheItem.Name); if ((geocacheItemByName?.Id > 0) && (geocacheItemByName.Id != geocacheItem.Id)) { validationMessages.Add("Geocache item name is already in use."); } if (geocacheItem.GeocacheId > 0) { if (!await this.dataService.GeocacheIdExists(geocacheItem.GeocacheId ?? 0)) { validationMessages.Add("Geocache does not exist."); } } return(validationMessages); }
public static async Task <GeocacheItem> CreateGeocacheItem(geocachingContext db, IGeocacheItemModel geocacheItem) { var createdItem = await Task.Run(() => { var newGeocacheItem = new GeocacheItem { Id = geocacheItem.Id, Name = geocacheItem.Name, GeocacheId = geocacheItem.GeocacheId, ActiveStartDate = geocacheItem.ActiveStartDate, ActiveEndDate = geocacheItem.ActiveEndDate }; db.GeocacheItem.Add(newGeocacheItem); db.SaveChanges(); return(newGeocacheItem); }); return(createdItem); }