public static async Task <GeocacheItemModel> GetGeocacheItem(geocachingContext db, string name) { return(await Task.Run(() => (from ci in db.GeocacheItem where ci.Name == name select new GeocacheItemModel { Id = ci.Id, Name = ci.Name, GeocacheId = ci.GeocacheId, ActiveStartDate = ci.ActiveStartDate, ActiveEndDate = ci.ActiveEndDate }).FirstOrDefault())); }
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); }
public static async Task <IEnumerable <GeocacheModel> > GetGeocaches(geocachingContext db) { return(await Task.Run(() => { return (from c in db.Geocache join l in db.GeocacheLocation on c.LocationId equals l.Id select new GeocacheModel { Id = c.Id, Name = c.Name, Location = new GeocacheLocationModel { Id = l.Id, Latitude = l.Latitude, Longitude = l.Longitude } }).ToSafeList(); })); }
public static async Task <GeocacheModel> GetGeocache(geocachingContext db, int id) { return(await Task.Run(() => { return (from c in db.Geocache join l in db.GeocacheLocation on c.LocationId equals l.Id where c.Id == id select new GeocacheModel { Id = c.Id, Name = c.Name, Location = new GeocacheLocationModel { Id = l.Id, Latitude = l.Latitude, Longitude = l.Longitude } }).FirstOrDefault(); })); }
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); }
public DataService(geocachingContext context) { this.dbContext = context; }
public static async Task <IEnumerable <GeocacheItemModel> > GetGeocacheItemsByGeocacheId(geocachingContext db, int geocacheId) { return(await Task.Run(() => (from ci in db.GeocacheItem where ci.GeocacheId == geocacheId select new GeocacheItemModel { Id = ci.Id, Name = ci.Name, GeocacheId = ci.GeocacheId, ActiveStartDate = ci.ActiveStartDate, ActiveEndDate = ci.ActiveEndDate }).ToListAsync())); }