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> Post(Customer customer)
        {
            _logger.LogInformation($"Customers /POST");

            customer.CreatedAt = DateTimeOffset.UtcNow;

            using var db = new EvtContext();
            db.Add(customer);
            await db.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), customer.CustomerId));
        }
        public async Task <ActionResult> Post(Product product)
        {
            this._logger.LogInformation($"Products /POST");

            product.CreatedAt = DateTimeOffset.UtcNow;

            using var db = new EvtContext();
            db.Add(product);
            await db.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), product.ProductId));
        }
        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());
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        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());
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        public async Task <ActionResult> Get()
        {
            _logger.LogInformation("Orders /GET");

            using (var db = new EvtContext())
            {
                var order = from o in db.Orders
                            join p in db.Products on o.ProductId equals p.ProductId
                            join c in db.Customers on o.CustomerId equals c.CustomerId
                            select new
                {
                    o.OrderId,
                    c.FirstName,
                    c.LastName,
                    Product = p.Name,
                    p.Description,
                    p.Price,
                };

                return(Ok(await order.ToListAsync()));
            }
        }