public CartController(NWContext context, SessionSettings ss)
        {
            _context = context;
            _ss      = ss;

            _rs = new RequestSettings(this);
        }
Beispiel #2
0
 public IList <Shipper> ListShippers()
 {
     using (var context = new NWContext())  // cleaner replaces Idisposable ... var try...diff than Javascript var typesafe
     {
         return(context.Shippers.ToList());
     }
 }
 public Supplier Supplier_Get(int supplierid)
 {
     using (var context = new NWContext())
     {
         return(context.Suppliers.Find(supplierid));
     }
 }
Beispiel #4
0
 public Region Regions_FindByID(int regionid)
 {
     using (var context = new NWContext())
     {
         return(context.Regions.Find(regionid));
     }
 }
Beispiel #5
0
 public Product GetProduct(int productID)
 {
     using (var context = new NWContext())
     {
         return(context.Products.Find(productID));
     }
 }
 public List <Products> GetAll()
 {
     using (NWContext context = new NWContext())
     {
         return(context.Products.ToList());
     }
 }
Beispiel #7
0
 public IList <Shipper> ListShippers()
 {
     using (var context = new NWContext())
     {
         return(context.Shippers.ToList());
     }
 }
 public List <Category> Categories_List()
 {
     using (var context = new NWContext())
     {
         return(context.Categories.ToList());
     }
 }
Beispiel #9
0
 public Shipper GetShipper(int shipperId)
 {
     using (var context = new NWContext())
     {
         return(context.Shippers.Find(shipperId));
     }
 }
 public List <Supplier> Supplier_List()
 {
     using (var context = new NWContext())
     {
         return(context.Suppliers.ToList());
     }
 }
 public List <Products> GetUnitePrice(decimal price)
 {
     using (NWContext context = new NWContext())
     {
         return(context.Products.Where(x => x.UnitPrice >= price).ToList());
     }
 }
Beispiel #12
0
 public HomeController(ILogger <HomeController> logger, NWContext context, SessionSettings ss)
 {
     _context = context;
     _logger  = logger;
     _ss      = ss;
     _rs      = new RequestSettings(this);
 }
 public Product Products_FindByID(int productid)
 {
     using (var context = new NWContext())
     {
         return(context.Products.Find(productid));
     }
 }
Beispiel #14
0
        public List <CustomerOrderSummary> GetCustomerOrderSummaries()
        {
            var dbContext = new NWContext();
            var data      = (from purchase in dbContext.Orders
                             where purchase.OrderDate.HasValue
                             select new CustomerOrderSummary()
            {
                OrderDate = purchase.OrderDate.Value,
                // see http://blog.dreamlabsolutions.com/post/2008/11/17/LINQ-Method-cannot-be-translated-into-a-store-expression.aspx
                Freight = purchase.Freight ?? 0m,             // purchase.Freight.GetValueOrDefault(),
                Subtotal = purchase.Order_Details
                           .Sum(x =>
                                (decimal?)(x.UnitPrice * x.Quantity)
                                ) ?? 0,                                                           // NOTE: See Footnote 1
                Discount = purchase.Order_Details
                           .Sum(x =>
                                x.UnitPrice * x.Quantity *
                                (((decimal)((int)(x.Discount * 100))) / 100)                     // NOTE: See Footnote 2
                                ),
                Total = purchase.Order_Details.Sum(x => (x.UnitPrice * x.Quantity) -
                                                   (x.UnitPrice * x.Quantity *
                                                    (((decimal)((int)(x.Discount * 100))) / 100)                  // NOTE: See Footnote 2
                                                   )
                                                   ),
                ItemCount = purchase.Order_Details.Count(),
                ItemQuantity = purchase.Order_Details.Sum(x => (short?)x.Quantity) ?? 0,
                AverageItemUnitPrice = purchase.Order_Details.Average(x => (decimal?)x.UnitPrice) ?? 0,
                CompanyName = purchase.Customer.CompanyName,
                ContactName = purchase.Customer.ContactName,
                ContactTitle = purchase.Customer.ContactTitle,
                CustomerId = purchase.CustomerID
            }).ToList();

            return(data);
        }
 public List <Product> Products_List()
 {
     using (var context = new NWContext())
     {
         return(context.Products.ToList());
     }
 }
        /// <summary>
        /// /Home/Index
        /// </summary>
        //public IActionResult Index(string filter = "")
        public IActionResult Index(ProductIndexViewModel vm)
        {
            var filter = HttpContext.Session.GetString(nameof(vm.Filter));

            vm.Filter = (vm.Filter ?? filter) ?? "";
            HttpContext.Session.SetString(nameof(vm.Filter), vm.Filter);

            if (vm.Filter != filter)
            {
                vm.Page = 1;
            }

            var result = new List <Product>();

            using (var db = new NWContext())
            {
                //result = db.Products.Where(p=> p.ProductName.Contains(filter)).ToList();
                //result = db.Products.Where(p => p.ProductName.Contains(vm.Filter)).ToList();
                vm.TotalCount = db.Products.Where(p => p.ProductName.Contains(vm.Filter)).Count();

                result = db.Products.Where(p => p.ProductName.Contains(vm.Filter))
                         .OrderBy(p => p.ProductName).Skip((vm.Page - 1) * vm.PageSize).
                         Take(vm.PageSize).ToList();
            }

            //var vm = new ProductIndexViewModel() { Products = result };
            vm.Products = result;

            // Dictionary
            //ViewData["products"] = result;
            //ViewBag.productsD = result;

            return(View(vm));
        }
Beispiel #17
0
 public List <Product> GetProducts()
 {
     using (var context = new NWContext())
     {
         var result = context.Products;
         return(result.ToList());
     }
 }
Beispiel #18
0
 public Product GetProduct(int productID)
 {
     using (var context = new NWContext())
     {
         return(context.Products.Find(productID));
     }
     throw new NotImplementedException();
 }
Beispiel #19
0
 public Shipper GetShipper(int shipperID)
 {
     using (var context = new NWContext())
     {
         return(context.Shippers.Find(shipperID));
     }
     throw new NotImplementedException();
 }
 public List <Products> GetUnitePrice(decimal max, decimal min)
 {
     using (NWContext context = new NWContext())
     {
         return(context.Products.Where(x => x.UnitPrice >= min && x.UnitPrice < max).ToList());
         //where ile direkt tablodan koşul ile veri alabiliyoruz
     }
 }
Beispiel #21
0
        public HomeController(ILogger <HomeController> logger, NWContext context, SessionSettings ss)
        {
            _context = context;

            _logger = logger;

            _ss = ss;
        }
Beispiel #22
0
 //TODO: Create a method called GetOrders() that will return a list of Order objets from teh database.
 public List <Order> GetOrders()
 {
     using (var context = new NWContext())
     {
         var result = context.Orders;
         return(result.ToList());
     }
 }
Beispiel #23
0
 public List <Region> GetRegions()
 {
     using (var context = new NWContext())
     {
         var result = context.Regions.Include(item => item.Territories).OrderBy(item => item.RegionDescription);
         return(result.ToList());
     }
 }
Beispiel #24
0
 public List <Employee> GetEmployees()
 {
     using (var context = new NWContext())
     {
         var result = context.Employees;
         return(result.ToList());
     }
 }
Beispiel #25
0
 public int AddShipper(Shipper info)
 {
     using (var context = new NWContext())
     {
         context.Shippers.Add(info);
         context.SaveChanges();
         return(info.ShipperID);
     }
 }
 public void Delete(Products products)
 {
     using (NWContext context = new NWContext())
     {
         var entity = context.Entry(products);
         entity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Beispiel #27
0
 public int AddProduct(Product info)
 {
     using (var context = new NWContext())
     {
         context.Products.Add(info);
         context.SaveChanges();
         return(info.ProductID);
     }
 }
Beispiel #28
0
 public void UpdateProduct(Product info)
 {
     using (var context = new NWContext())
     {
         context.Products.Attach(info);
         context.Entry(info).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 //Update
 //change the entire entity record
 //it does not matter LOGICALLY that you change a value to itself
 //by changing the entire entity, you change all fields that need to be altered
 //the value return is the number of rows affected
 public int Products_Update(Product item)
 {
     using (var context = new NWContext())
     {
         //Staging
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         //Commit and Feedback (rows affected)
         return(context.SaveChanges());
     }
 }
Beispiel #30
0
 public int AddProduct(Product info)
 {
     using (var context = new NWContext())
     {
         context.Products.Add(info);
         context.SaveChanges();
         return(info.ProductID);
     }
     throw new NotImplementedException("v.2.0");
 }