Ejemplo n.º 1
0
 // 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);
     }
 }
Ejemplo n.º 2
0
 // 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));
     }
 }
Ejemplo n.º 3
0
 // GET: api/Shops
 public async Task <IEnumerable <Shop> > Get()
 {
     using (var findShopContext = new FindShopContext())
     {
         return(await findShopContext.Shops.Include(i => i.Locations).ToArrayAsync());
     }
 }
Ejemplo n.º 4
0
        // 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();
            }
        }
Ejemplo n.º 5
0
        // 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();
            }
        }