/// <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 <IGeocacheItemModel> PatchGeocacheItemGeocacheId(IGeocacheItemPatchGeocacheIdModel patchModel) { if ((patchModel.Id <= 0) || (patchModel.GeocacheId <= 0)) { throw new ArgumentException("Id's cannot be less than or equal to 0."); } var geocacheItem = await this.dataService.PatchGeocacheItemGeocacheId(patchModel); return(geocacheItem ?? new GeocacheItemModel()); }
/// <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); }
private void SetupGeocacheItems() { this.geocacheItemList = new List <GeocacheItemModel>(); this.geocacheItem = new GeocacheItemModel { Id = 4, Name = "Name", GeocacheId = 4, ActiveStartDate = Convert.ToDateTime("2020-02-02"), ActiveEndDate = Convert.ToDateTime("2022-02-02") }; this.geocacheItemList.Add(this.geocacheItem); this.patchGeocacheIdModel = new GeocacheItemPatchGeocacheIdModel { Id = 3, GeocacheId = 6 }; }
/// <summary> /// Validates the geocache item is valid for updating the geocache id. /// </summary> /// <param name="patchModel">The patch model to update the GeocacheId.</param> /// <returns>List of strings with the collected error messages; if any.</returns> public async Task <IList <string> > ValidateForPatchGeocacheId(IGeocacheItemPatchGeocacheIdModel patchModel) { var validationMessages = new List <string>(); var id = patchModel.Id; var geocacheId = patchModel.GeocacheId; var geocacheItem = await this.GetGeocacheItem(id); if (!(geocacheItem.Id > 0)) { validationMessages.Add("Geocache Item does not exist."); return(validationMessages); } if (!geocacheItem.IsActive) { validationMessages.Add("Geocache Item is inactive."); } if (geocacheId != null) { if (geocacheId <= 0) { validationMessages.Add("Invalid GeocacheId."); } else { var geocacheItemsInGeocache = await GetGeocacheItemsByGeocacheId(geocacheId ?? 0, true); if (geocacheItemsInGeocache.Count >= 3) { validationMessages.Add("Cannot assign to Geocache with 3 or more active items."); return(validationMessages); } } } return(validationMessages); }
public static async Task <GeocacheItem> UpdateGeocacheItemGeocacheId(geocachingContext db, IGeocacheItemPatchGeocacheIdModel patchModel) { var createdItem = await Task.Run(() => { var entityGeocacheItem = db.GeocacheItem.FirstOrDefault(i => i.Id == patchModel.Id); if (entityGeocacheItem == null) { throw new KeyNotFoundException(); } entityGeocacheItem.GeocacheId = patchModel.GeocacheId; db.SaveChanges(); return(entityGeocacheItem); }); return(createdItem); }