// DELETE: api/Shops/5 public async Task Delete(Guid id) { using (var findShopContext = new FindShopContext()) { await findShopContext.Database.ExecuteSqlCommandAsync("DELETE FROM Shops WHERE Id = @p0", id); } }
// GET: api/Shops/5 public async Task <Shop> Get(Guid id) { using (var findShopContext = new FindShopContext()) { return(await findShopContext.Shops.SingleAsync(i => i.Id == id)); } }
// GET: api/Shops public async Task <IEnumerable <Shop> > Get() { using (var findShopContext = new FindShopContext()) { return(await findShopContext.Shops.Include(i => i.Locations).ToArrayAsync()); } }
// POST: api/Shops public async Task Post([FromBody] AddShopRequestViewModel addShopRequestViewModel) { using (var findShopContext = new FindShopContext()) { findShopContext.Shops.Add(new Shop() { Name = addShopRequestViewModel.Name }); await findShopContext.SaveChangesAsync(); } }
// PUT: api/Shops/5 public async Task Put(Guid id, [FromBody] AddLocationRequestViewModel addLocationRequestViewModel) { using (var findShopContext = new FindShopContext()) { findShopContext.Locations.Add(new Location() { Address = addLocationRequestViewModel.Address, Country = addLocationRequestViewModel.Country, PostalCode = addLocationRequestViewModel.PostalCode, Latitude = addLocationRequestViewModel.Latitude, Longitude = addLocationRequestViewModel.Longitude, Timestamp = DateTimeOffset.UtcNow, ShopId = id }); await findShopContext.SaveChangesAsync(); } }