示例#1
0
        public IActionResult Edit(int id)
        {
            NorthwndContext ctx = new NorthwndContext();
            ProductEditVm   vm  = new ProductEditVm();

            vm.ProducttoEdit = ctx.Products.SingleOrDefault(prd => prd.ProductID == id);

            vm.Categories = ctx.Categories.Select(cat => new SelectListItem()
            {
                Text     = cat.CategoryName,
                Value    = cat.CategoryID.ToString(),
                Selected = cat.CategoryID == vm.ProducttoEdit.CategoryId
            }).ToList();

            vm.Categories.Insert(0, new SelectListItem()
            {
                Text = "Seçiniz...", Value = "-1"
            });

            vm.Suppliers = ctx.Suppliers.Select(sup => new SelectListItem()
            {
                Text     = sup.CompanyName,
                Value    = sup.SupplierID.ToString(),
                Selected = sup.SupplierID == vm.ProducttoEdit.SupplierID
            }).ToList();
            vm.Suppliers.Insert(0, new SelectListItem()
            {
                Text = "Seçiniz...", Value = "-1"
            });

            return(View(vm));
        }
        public void Put(int id, [FromBody] Suppliers supplier)
        {
            var northwndContext = new NorthwndContext();

            northwndContext.Update(supplier);
            northwndContext.SaveChanges();
        }
        public void Post([FromBody] Suppliers supplier)
        {
            var northwndContext = new NorthwndContext();

            northwndContext.Add(supplier);
            northwndContext.SaveChanges();
        }
        public void Delete(int id)
        {
            var northwndContext = new NorthwndContext();
            var supplier        = northwndContext.Suppliers.Find(id);

            northwndContext.Suppliers.Remove(supplier);
            northwndContext.SaveChanges();
        }
示例#5
0
        public IActionResult Delete(int id)
        {
            NorthwndContext ctx             = new NorthwndContext();
            Product         productToDelete = ctx.Products.SingleOrDefault(prd => prd.ProductID == id);


            return(View(productToDelete));
        }
示例#6
0
        public IActionResult Delete(Product product)
        {
            NorthwndContext ctx = new NorthwndContext();
            Product         pr  = ctx.Products.SingleOrDefault(prd => prd.ProductID == product.ProductID);

            ctx.Products.Remove(pr);
            ctx.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
示例#7
0
文件: Program.cs 项目: zmjack/SQLib
        static string QueryRegion_EF(int regionId)
        {
            var options = new DbContextOptionsBuilder().UseSqlite("filename=northwnd.db").Options;

            using (var context = new NorthwndContext(options))
            {
                return(context.Regions.First(x => x.RegionID == regionId).RegionDescription);
            }
        }
示例#8
0
        public IActionResult NewProduct(Product product)
        {
            NorthwndContext ctx = new NorthwndContext();

            ctx.Products.Add(product); //insert Products(.....) values(....)
            ctx.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
 static void Main(string[] args)
 {
     EntityFrameworkProfiler.Initialize();
     using (var ctx = new NorthwndContext())
     {
         var customersV1 = ctx.Customers.Where(x => x.CompanyName.StartsWith("A")).ToList();
         var customersV2 = ctx.Customers.Where(x => EF.Functions.Like(x.CompanyName, "A%")).ToList();
         Console.WriteLine($"Version 1 returned {customersV1.Count} And 2 {customersV2.Count}");
     }
 }
示例#10
0
        static void Main(string[] args)
        {
            using (var sqlite = NorthwndContext.UseSqliteResource())
                using (var sqlserver = ApplicationDbContext.UseSqlServer())
                {
                    sqlite.WriteTo(sqlserver);
                }

            Console.WriteLine("Complete.");
        }
示例#11
0
        static void Main(string[] args)
        {
            using (var sqlite = NorthwndContext.UseSqliteResource())
                using (var mysql = ApplicationDbContext.UseMySql())
                {
                    sqlite.WriteTo(mysql);
                }

            Console.WriteLine("Complete.");
        }
示例#12
0
 static void Main(string[] args)
 {
     EntityFrameworkProfiler.Initialize();
     using (var ctx = new NorthwndContext())
     {
         var query = ctx.Customers.Where(x => x.CompanyName.StartsWith("A")).ToList();
         foreach (var result in query)
         {
             Console.WriteLine($"Company: {result.CompanyName}");
         }
     }
 }
示例#13
0
 private void Dispose(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     if (this.context == null)
     {
         return;
     }
     this.context.Dispose();
     this.context = null;
 }
 public IEnumerable <Suppliers> GetAgGridPage(string sort, string filter, int take, int skip)
 {
     try
     {
         var northwndContext = new NorthwndContext();
         var list            = northwndContext.Suppliers.OrderBy(s => s.CompanyName).ToList();
         return(list);
     }
     catch (Exception ex)
     {
         var ex2 = ex;
         return(new List <Suppliers>());
     }
 }
示例#15
0
        public IActionResult Edit(Product product)
        {
            NorthwndContext ctx = new NorthwndContext();

            Product prdToUpdate = ctx.Products.SingleOrDefault(prd => prd.ProductID == product.ProductID);

            prdToUpdate.CategoryId      = product.CategoryId;
            prdToUpdate.Discontinued    = product.Discontinued;
            prdToUpdate.ProductName     = product.ProductName;
            prdToUpdate.QuantityPerUnit = product.QuantityPerUnit;
            prdToUpdate.SupplierID      = product.SupplierID;
            prdToUpdate.UnitPrice       = product.UnitPrice;

            ctx.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
 public IEnumerable <Suppliers> Get()
 {
     try
     {
         var northwndContext = new NorthwndContext();
         var list            = northwndContext.Suppliers
                               .OrderBy(s => s.CompanyName)
                               //.Take(5)
                               .Include(supplier => supplier.Products)
                               .AsNoTracking()
                               .ToList()
         ;
         return(list);
     }
     catch (Exception ex)
     {
         var ex2 = ex;
         return(new List <Suppliers>());
     }
 }
示例#17
0
        public IActionResult Index()
        {
            NorthwndContext ctx = new NorthwndContext();
            //select ProductID,ProductName.... from Products
            //List<Product> products= ctx.Products.ToList();
            //-------------------------------------------

            HomeIndexVm vm = new HomeIndexVm();


            vm.Products = ctx.Products
                          .Include(prd => prd.Category)
                          .Include(prd => prd.Supplier)
                          .ToList();

            vm.Categories = ctx.Categories.Select(cat => new SelectListItem()
            {
                Text  = cat.CategoryName,
                Value = cat.CategoryID.ToString()
            }).ToList();

            vm.Categories.Insert(0, new SelectListItem()
            {
                Text = "Seçiniz...", Value = "-1"
            });

            vm.Suppliers = ctx.Suppliers.Select(sup => new SelectListItem()
            {
                Text  = sup.CompanyName,
                Value = sup.SupplierID.ToString()
            }).ToList();
            vm.Suppliers.Insert(0, new SelectListItem()
            {
                Text = "Seçiniz...", Value = "-1"
            });

            return(View(vm));
        }
示例#18
0
        public IActionResult NewProduct()
        {
            NorthwndContext ctx = new NorthwndContext();


            //NewProductVm vm = new NewProductVm();

            //vm.Categories= ctx.Categories.ToList();
            //vm.Suppliers= ctx.Suppliers.ToList();
            //-----------------------------------------
            NewProductVm vm = new NewProductVm();

            vm.Categories = ctx.Categories.Select(cat => new SelectListItem()
            {
                Text  = cat.CategoryName,
                Value = cat.CategoryID.ToString()
            }).ToList();

            vm.Categories.Insert(0, new SelectListItem()
            {
                Text = "Seçiniz...", Value = "-1"
            });

            vm.Suppliers = ctx.Suppliers.Select(sup => new SelectListItem()
            {
                Text  = sup.CompanyName,
                Value = sup.SupplierID.ToString()
            }).ToList();
            vm.Suppliers.Insert(0, new SelectListItem()
            {
                Text = "Seçiniz...", Value = "-1"
            });


            return(View(vm));
        }
示例#19
0
 public UnitOfWork(NorthwndContext context)
 {
     this.context = context;
 }
        public Suppliers Get(int id)
        {
            var northwndContext = new NorthwndContext();

            return(northwndContext.Suppliers.Find(id));
        }