public async Task <ActionResult> Get() { this._logger.LogInformation("Products /GET"); using var db = new EvtContext(); var products = await db.Set <Product>().ToListAsync(); return(Ok(products)); }
public async Task <ActionResult> Get() { _logger.LogInformation("Customers /GET"); using var db = new EvtContext(); var customers = await db.Set <Customer>().ToArrayAsync(); return(Ok(customers)); }
public async Task <ActionResult> Get(int customerId) { _logger.LogInformation($"Customers/{customerId} /GET"); using var db = new EvtContext(); var customer = await db.Set <Customer>().FindAsync(customerId); if (customer == null) { return(NotFound()); } return(Ok(customer)); }
public async Task <ActionResult> Get(int productId) { this._logger.LogInformation($"Products/{productId} /GET"); using var db = new EvtContext(); var product = await db.Set <Product>().FindAsync(productId); if (product == null) { return(NotFound()); } return(Ok(product)); }
public async Task <ActionResult> Delete(int customerId) { _logger.LogInformation($"Customers/{customerId} /DELETE"); using var db = new EvtContext(); var customer = await db.Set <Customer>().FindAsync(customerId); if (customer == null) { return(NotFound()); } db.Remove(customer); await db.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Delete(int productId) { _logger.LogInformation($"Products/{productId} /DELETE"); using var db = new EvtContext(); var product = await db.Set <Product>().FindAsync(productId); if (product == null) { return(NotFound()); } db.Remove(product); await db.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Delete(int orderId) { _logger.LogInformation($"Orders/{orderId} /DELETE"); using var db = new EvtContext(); var orders = await db.Set <Order>().FindAsync(orderId); if (orders == null) { return(NotFound()); } db.Remove(orders); await db.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Put(int customerId, Customer customer) { _logger.LogInformation($"Customers/{customerId} /PUT"); customer.UpdatedAt = DateTimeOffset.UtcNow; using var db = new EvtContext(); var exists = await db.Set <Customer>().AnyAsync(c => c.CustomerId == customerId); if (!exists) { return(NotFound()); } customer.CustomerId = customerId; db.Update(customer); await db.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Put(int productId, Product product) { this._logger.LogInformation($"Products/{productId} /PUT"); product.UpdatedAt = DateTimeOffset.UtcNow; using var db = new EvtContext(); var exists = await db.Set <Product>().AnyAsync(p => p.ProductId == productId); if (!exists) { return(NotFound()); } product.ProductId = productId; db.Update(product); await db.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult> Put(int orderId, Order order) { _logger.LogInformation($"Orders/{orderId} /PUT"); order.UpdatedAt = DateTimeOffset.UtcNow; using var db = new EvtContext(); var exists = await db.Set <Order>().AnyAsync(c => c.OrderId == orderId); if (!exists) { return(NotFound()); } order.OrderId = orderId; db.Update(order); await db.SaveChangesAsync(); return(NoContent()); }