public static List <Order> GetListOrder(int id_cus) { using (var _context = new DBDongho()) { return(_context.Orders.Where(x => x.id_user == id_cus).Include("Product").Include("Delivery").Include("Status").ToList()); } }
public static void CreateOrder(int id_cus) { using (var _context = new DBDongho()) { var listCart = GetListCart(id_cus); foreach (var item in listCart) { Order order = new Order() { id_product = item.id_product, id_deli = 1, id_user = id_cus, addressTo = "TP.HCM", createDate = DateTime.Now, id_stt = 1, requireDate = DateTime.Now.AddDays(3), quantity = item.count, total = item.count * item.Product.Price }; var dbpro = _context.Products.Where(x => x.ID == item.id_product).FirstOrDefault(); dbpro.sold = dbpro.sold + item.count; dbpro.turnover = dbpro.turnover + dbpro.sold * dbpro.Price; _context.Products.AddOrUpdate(dbpro); _context.SaveChanges(); _context.Orders.Add(order); _context.SaveChanges(); } } DeleteAllCart(id_cus); }
public static Order GetOrder(int id_user, int id_pro) { using (var _context = new DBDongho()) { return(_context.Orders.Where(x => x.id_user == id_user && x.id_product == id_pro).Include("Product").Include("Delivery").Include("Status").SingleOrDefault()); } }
public static void createCategory(Category cate) { using (var _context = new DBDongho()) { _context.Categories.Add(cate); _context.SaveChanges(); } }
public static void createBrand(Brand brand) { using (var _context = new DBDongho()) { _context.Brands.Add(brand); _context.SaveChanges(); } }
public static Customer GetCustomer(string acc) { using (var _context = new DBDongho()) { var dbcus = (from c in _context.Customers where c.accuontName == acc select c).SingleOrDefault(); return(dbcus); } }
public static Product getProductById(int id) { using (var _context = new DBDongho()) { var dbpro = (from p in _context.Products where p.ID == id select p).SingleOrDefault(); return(dbpro); } }
public static List <Product> getAllProducts() { using (var _context = new DBDongho()) { _context.Configuration.LazyLoadingEnabled = false; var dbpro = (from pro in _context.Products select pro).ToList(); return(dbpro); } }
public static List <Category> getAllCategories() { using (var _context = new DBDongho()) { //_context.Configuration.LazyLoadingEnabled = false; var dbcat = (from cat in _context.Categories select cat).ToList(); return(dbcat); } }
public static List <Brand> getAllBrands() { using (var _context = new DBDongho()) { _context.Configuration.LazyLoadingEnabled = false; var dbbrand = (from br in _context.Brands select br).ToList(); return(dbbrand); } }
public static List <Cart> GetListCart(int id_user) { using (var _context = new DBDongho()) { var dbcart = (from c in _context.Carts.Include("Product") where c.id_user == id_user select c).ToList(); return(dbcart); } }
public static List <Product> FilterBrand(int id) { using (var _Context = new DBDongho()) { _Context.Configuration.LazyLoadingEnabled = false; var Listpro = (from pro in _Context.Products where pro.BrandID == id select pro).ToList(); return(Listpro); } }
public static void DeleteItemCart(int id_user, int id_pro) { using (var _context = new DBDongho()) { var dbcart = (from c in _context.Carts where c.id_product == id_pro && c.id_user == id_user select c).SingleOrDefault(); _context.Carts.Remove(dbcart); _context.SaveChanges(); } }
public static bool RegisterAdmin(Customer admin) { try { using (var _context = new DBDongho()) { _context.Customers.Add(admin); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static void DeleteAllCart(int id_user) { using (var _context = new DBDongho()) { var dbcart = (from c in _context.Carts where c.id_user == id_user select c).ToList(); foreach (var item in dbcart) { DeleteItemCart(item.id_user, item.id_product); } } }
public void XuatExcel() { var _context = new DBDongho(); string path = System.Reflection.Assembly.GetExecutingAssembly().Location; string fileName = Path.Combine(path, "Product.xlsx"); FileInfo newFile = new FileInfo(fileName); if (newFile.Exists) { newFile.Delete(); // ensures we create a new workbook newFile = new FileInfo(fileName); } List <Product> myProduct = new List <Product>(); myProduct = func.getAllProducts(); var listpro = (from pro in _context.Products join cate in _context.Categories on pro.categoryID equals cate.ID join bra in _context.Brands on pro.BrandID equals bra.ID select new { id = pro.productName, name = pro.productName, des = pro.productDescription, pri = pro.Price, datecrea = pro.createDate, cateName = cate.cateName, branName = bra.brandName }).ToList(); ExcelPackage.LicenseContext = LicenseContext.Commercial; ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (ExcelPackage pck = new ExcelPackage(newFile)) { ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Report"); ws.Cells["A1"].Value = "ID product"; ws.Cells["B1"].Value = "Name product"; ws.Cells["C1"].Value = "Description product"; ws.Cells["D1"].Value = "Price product"; ws.Cells["E1"].Value = "Date create product"; int rowstart = 2; foreach (var item in listpro) { ws.Cells[string.Format("A{0}", rowstart)].Value = item.id; ws.Cells[string.Format("B{0}", rowstart)].Value = item.name; ws.Cells[string.Format("C{0}", rowstart)].Value = item.des; ws.Cells[string.Format("D{0}", rowstart)].Value = item.pri; ws.Cells[string.Format("E{0}", rowstart)].Value = item.datecrea.ToString(); ws.Cells[string.Format("F{0}", rowstart)].Value = item.cateName; ws.Cells[string.Format("G{0}", rowstart)].Value = item.branName; rowstart++; } ws.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename=Product.xls"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); } }
public static bool LoginAdmin(string acc, string pass) { using (var _context = new DBDongho()) { var dbadmin = (from a in _context.Customers where a.accuontName == acc && a.passWord == pass select a).ToList(); if (dbadmin.Count() == 1) { return(true); } return(false); } }
public static bool register(Customer cus) { if (AccIsExists(cus) == false) { using (var _context = new DBDongho()) { cus.passWord = Encrypt.GetMD5(cus.passWord); _context.Customers.Add(cus); _context.SaveChanges(); return(true); } } return(false); }
public static bool EditProduct(Product prod) { try { using (var _context = new DBDongho()) { _context.Products.AddOrUpdate(prod); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool addPro(Product pro) { try { using (var _context = new DBDongho()) { _context.Products.Add(pro); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool EditBrand(Brand brand) { try { using (var _context = new DBDongho()) { _context.Brands.AddOrUpdate(brand); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool EditCategory(Category cate) { try { using (var _context = new DBDongho()) { _context.Categories.AddOrUpdate(cate); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool AccIsExists(Customer cus) { using (var _context = new DBDongho()) { var dbcus = (from c in _context.Customers where c.accuontName == cus.accuontName select c).SingleOrDefault(); if (dbcus != null) { return(true); } else { return(false); } } }
public static bool signIn(string acc, string pass) { using (var _context = new DBDongho()) { string password = Encrypt.GetMD5(pass); var dbcus = (from cus in _context.Customers where cus.accuontName == acc && cus.passWord == password select cus).ToList(); if (dbcus.Count == 1) { return(true); } else { return(false); } } }
public static bool delProduct(int id) { try { using (var _context = new DBDongho()) { var dbpro = (from pr in _context.Products where pr.ID == id select pr).SingleOrDefault(); _context.Products.Remove(dbpro); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool delCategory(int id) { try { using (var _context = new DBDongho()) { var dbcat = (from cat in _context.Categories where cat.ID == id select cat).SingleOrDefault(); _context.Categories.Remove(dbcat); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool delBrand(int id) { try { using (var _context = new DBDongho()) { var dbbr = (from br in _context.Brands where br.ID == id select br).SingleOrDefault(); _context.Brands.Remove(dbbr); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool Add_Item(int id_user, int id_pro, int quantity) { try { using (var _context = new DBDongho()) { var pro_count = _context.Products.Where(p => p.ID == id_pro).FirstOrDefault().viewCount; //kiem tra so luong ton co du ban khong if (pro_count < quantity) { return(false); } //Kiểm tra xem đã thêm sản phẩm này vào giỏ hàng chưa ? var item = (from c in _context.Carts where c.id_user == id_user && c.id_product == id_pro select c).FirstOrDefault(); //Tăng số lượng sản phẩm lên 1 nếu user đã thêm sản phẩm này vào giỏ hàng if (item != null) { item.count = item.count + quantity; _context.Carts.AddOrUpdate(item); _context.SaveChanges(); return(true); } else { Cart cart = new Cart() { id_user = id_user, id_product = id_pro, count = quantity }; _context.Carts.Add(cart); _context.SaveChanges(); return(true); } } } catch { return(false); } }