//List<AdminUser> admindb.AdminUsers.ToList(); //AdminUser ları getiren metot public static List <AdminUser> GetAllAdminUsers() { using (BilgeAdamContext db = new BilgeAdamContext()) { return(db.AdminUsers.ToList()); } }
public static List <Product> GetAllProductsWithCount(int count) { using (BilgeAdamContext db = new BilgeAdamContext()) { return(db.Products.Take(count).ToList()); } }
public static List <Category> GetAllCategories() { using (BilgeAdamContext db = new BilgeAdamContext()) { return(db.Categories.Where(q => q.IsDeleted == false).ToList()); } }
//Dışarıdan alınan ID ye göre ürünü dönen metot public static Product GetProductbyID(int id) { using (BilgeAdamContext db = new BilgeAdamContext()) { return(db.Products.FirstOrDefault(x => x.ID == id && x.IsDeleted == false)); } }
public static List <WebUser> GetAllWebUsers() { using (BilgeAdamContext db = new BilgeAdamContext()) { return(db.WebUsers.Where(q => q.IsDeleted == false).ToList()); } }
//Dışarıdan aldığu stringe göre ürün adında o kelime geçen ÜRÜNLER public static List <Product> GetAllProductsbySearchProductName(string name) { using (BilgeAdamContext db = new BilgeAdamContext()) { return(db.Products.Where(q => q.ProductName.Contains(name)).ToList()); } }
//IsDeleted'ı false olan tüm ürünleri getirme public static List <Product> IsDeletedFalse(bool isDeleted) { using (BilgeAdamContext db = new BilgeAdamContext()) { return(db.Products.OrderBy(x => x.IsDeleted == false).ToList()); } }
//update metodu public static void UpdateProduct(Product product) { using (BilgeAdamContext db = new BilgeAdamContext()) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); } }
public static void UpdateSupplier(Supplier supplier) { using (BilgeAdamContext db = new BilgeAdamContext()) { db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); } }
//ürünün kategorisinin adı dışarıdan gelen string ile başlayan ÜRÜNLER public static List <Product> GetAllProductsbyCategoryName(string categoryname) { using (BilgeAdamContext db = new BilgeAdamContext()) { //patlayabilir ! return(db.Products.Where(q => q.Category.CategoryName.StartsWith(categoryname)).ToList()); } }
//id ye göre HARD silme metodu public static void HardDeleteProduct(int id) { using (BilgeAdamContext db = new BilgeAdamContext()) { Product product = db.Products.FirstOrDefault(q => q.ID == id); db.Products.Remove(product); db.SaveChanges(); } }
//En pahalı ürün public static Product GetProductMaxUnitPrice() { using (BilgeAdamContext db = new BilgeAdamContext()) { //test edilecek return(db.Products.OrderBy(q => q.UnitPrice).Max()); return(db.Products.OrderBy(q => q.UnitPrice).Take(1).FirstOrDefault()); } }
//idye göre silme public static void DeleteProduct(int id) { using (BilgeAdamContext db = new BilgeAdamContext()) { Product product = db.Products.FirstOrDefault(q => q.ID == id); product.IsDeleted = true; product.DeleteDate = DateTime.Now; db.SaveChanges(); } }
public static void DeleteCategory(int id) { using (BilgeAdamContext db = new BilgeAdamContext()) { Category category = db.Categories.FirstOrDefault(q => q.ID == id); category.IsDeleted = true; category.DeleteDate = DateTime.Now; db.SaveChanges(); } }
public static void DeleteSupplier(int id) { using (BilgeAdamContext db = new BilgeAdamContext()) { Supplier supplier = db.Suppliers.FirstOrDefault(q => q.ID == id); if (supplier != null) { supplier.IsDeleted = true; db.SaveChanges(); } } }
public static void AddSupplier(Supplier supplier) { using (BilgeAdamContext db = new BilgeAdamContext()) { supplier.AddDate = DateTime.Now; supplier.UpdateDate = DateTime.Now; supplier.IsDeleted = false; db.Suppliers.Add(supplier); db.SaveChanges(); } }
public static void AddCategory(Category category) { using (BilgeAdamContext db = new BilgeAdamContext()) { category.AddDate = DateTime.Now; category.IsDeleted = false; category.UpdateDate = DateTime.Now; db.Categories.Add(category); db.SaveChanges(); } }
//public static List<Product> GetAllProducts() //{ // using (BilgeAdamContext db = new BilgeAdamContext()) // { // return db.Products.Where(q => q.IsDeleted == false).ToList(); // } //} public static void AddProduct(Product product) { using (BilgeAdamContext db = new BilgeAdamContext()) { product.AddDate = DateTime.Now; product.IsDeleted = false; product.UpdateDate = DateTime.Now; db.Products.Add(product); db.SaveChanges(); } }
public static void AddAdminUser(AdminUser adminuser) { using (BilgeAdamContext db = new BilgeAdamContext()) { adminuser.InsertedUserID = 1; adminuser.UpdatedUserID = 1; adminuser.AddDate = DateTime.Now; adminuser.IsDeleted = false; adminuser.UpdateDate = DateTime.Now; db.AdminUsers.Add(adminuser); db.SaveChanges(); } }
//dışarıdan alınan isme göre ürün var mı? public static bool CheckProductwithProductName(string name) { using (BilgeAdamContext db = new BilgeAdamContext()) { bool result = db.Products.Any(q => q.ProductName == name); return(result); //Product product = db.Products.FirstOrDefault(q => q.ProductName == name); //if (product != null) // return true; //else // return false; } }
//db.Products = dbSet //db = context public GenericRepository() { db = new BilgeAdamContext(); this.dbSet = db.Set <TEntity>(); }