public async Task <IActionResult> GetProducts()
 {
     using (var ctx = new AdventureWorksLT2017Context())
     {
         var categories = ctx.Product.ToList();
         return(Ok(categories));
     }
 }
 public async Task <IActionResult> GetAveragePricePerCategory()
 {
     using (var ctx = new AdventureWorksLT2017Context())
     {
         var res = ctx.AveragePriceCategories.FromSqlRaw("select pc.Name, avg(p.ListPrice) as avg from SalesLT.Product p join SalesLT.ProductCategory pc on p.ProductCategoryID = pc.ProductCategoryID group by pc.ProductCategoryID, pc.Name order by avg")
                   .ToList();
         return(Ok(res));
     }
 }
 public async Task <IActionResult> GetProductsInCategory(int CategoryId)
 {
     using (var ctx = new AdventureWorksLT2017Context())
     {
         return(Ok(
                    ctx.Product.Where(p => p.ProductCategory.ProductCategoryId == CategoryId).ToList()
                    ));
     }
 }
Beispiel #4
0
 public async Task<IActionResult> GetCustomerById(int CustomerId)
 {
     using (var ctx = new AdventureWorksLT2017Context())
     {
         var res = from c in ctx.Customer
                   where c.CustomerId == CustomerId
                   select c;
         return Ok(res);
     }
 }
Beispiel #5
0
        public async Task<IActionResult> GetCustomers()
        {
            using (var ctx = new AdventureWorksLT2017Context())
            {
                var result = from c in ctx.Customer
                             select c;

                return Ok(result.ToList());
            }
        }
Beispiel #6
0
 public async Task<IActionResult> SearchCustomerByName(string Name)
 {
     using (var ctx = new AdventureWorksLT2017Context())
     {
         var res = from c in ctx.Customer
                   where c.FirstName.Contains(Name)
                   select c;
         
         return Ok(res.ToList());
     }
 }
        public async Task <IActionResult> GetCategories()
        {
            using (var ctx = new AdventureWorksLT2017Context())
            {
                var categories = ctx.ProductCategory
                                 .Where(p => p.ParentProductCategoryId != null)
                                 .Select(p => new { p.ProductCategoryId, p.Name, Count = p.Product.Count })
                                 .ToList();

                return(Ok(categories));
            }
        }
 public async Task <IActionResult> GetProductById(int ProductId)
 {
     using (var ctx = new AdventureWorksLT2017Context())
     {
         var p = ctx.Product.Find(ProductId);
         if (p == null)
         {
             return(NotFound(ProductId));
         }
         else
         {
             return(Ok(p));
         }
     }
 }
 public BikesController(AdventureWorksLT2017Context context)
 {
     db = context;
 }
 public MoviesController(AdventureWorksLT2017Context context)
 {
     _context = context;
 }