public static bool ChangePassword(int accountId, string oldPassword, string newPassword) { _db = new FoodStoreEntities(); bool flag = true; try { ACCOUNT account = GetById(accountId); if (account.Password == SaltEncrypt.HashCodeSHA1(oldPassword)) { account.Password = SaltEncrypt.HashCodeSHA1(newPassword); _db.SaveChanges(); } else { return false; } } catch (Exception) { flag = false; throw; } return flag; }
public static bool Insert(int id, String foodName, int foodPrice, int foodTypeId, String foodImage, String foodDetail) { bool flag = true; try { _db = new FoodStoreEntities(); var food = new FOOD(); var foodType = FoodTypeController.Get(foodTypeId, _db); food.ID = id; food.Name = foodName; food.Price = foodPrice; food.Detail = foodDetail; food.Image = foodImage; food.FOODTYPE = foodType; food.Alias = StringOperation.GetAlias(id, foodName); _db.AddToFOODs(food); _db.SaveChanges(); } catch (Exception) { flag = false; throw; } return flag; }
public Supplier GetSupplier(string supplierName) { FoodStoreEntities context = new FoodStoreEntities(); return((from s in context.Suppliers where s.vendor == supplierName select s).FirstOrDefault()); }
public static void GetMaxMinYear(ref int minYear,ref int maxYear) { _db = new FoodStoreEntities(); var min = _db.BILLs.Min(p => p.Date); var max = _db.BILLs.Max(p => p.Date); if (min != null) minYear = min.Value.Year; if (max != null) maxYear = max.Value.Year; }
public int GetNextProductId() { FoodStoreEntities context = new FoodStoreEntities(); //find max id of items in product table var query = context.Products .Select(p => p.productID).ToList(); int maxId = query.Max(); return(maxId + 1); }
public List <SupplierVM> GetDistinctSuppliers() { FoodStoreEntities context = new FoodStoreEntities(); List <SupplierVM> suppliers = context.Suppliers .Select(s => new SupplierVM { SupplierName = s.vendor }) .Distinct().ToList(); return(suppliers); }
public List <ManufacturerVM> GetAllManufacturers() { FoodStoreEntities context = new FoodStoreEntities(); List <ManufacturerVM> items = context.Manufacturers .Select(m => new ManufacturerVM { ManufacturerName = m.mfg }) .Distinct().ToList(); return(items); }
public static int GetPayment(int year,int month) { _db = new FoodStoreEntities(); var result = _db.BILLs.Where( p => p.Date != null && (p.Date.Value.Month == month && p.Date.Value.Year == year)).Sum(p => p.TotalPayment); if (result != null) return (int)result; else { return 0; } }
public static int GetMaxId() { int id; try { _db = new FoodStoreEntities(); id = _db.ORDERs.Max(p => p.ID) + 1; } catch (Exception) { id = 1; } return id; }
public static bool UpdateBill(int orderId, int state, int paymethod) { _db = new FoodStoreEntities(); bool flag = true; bool checkBill = true; ORDER order = OrderController.GetById(orderId, _db); if (order.BILLs.Count == 0) { checkBill = false; } if (checkBill) { BILL bill = _db.BILLs.Single(p => p.ORDER.ID == orderId); if (state != (int)ProjectEnum.OrderState.Finish) { _db.BILLs.DeleteObject(bill); } else { bill.PaymentMethor = paymethod; } } else { if (state == (int)ProjectEnum.OrderState.Finish) { BILL bill = new BILL(); bill.ID = GetMaxId(); bill.IDOrder = orderId; bill.Date = DateTime.Now; bill.TotalPayment = order.TotalPayment; bill.PaymentMethor = paymethod; _db.BILLs.AddObject(bill); } } try { _db.SaveChanges(); } catch (Exception) { flag = false; throw; } return flag; }
public static bool Delete(int id) { _db = new FoodStoreEntities(); bool flag = true; try { var foodType = _db.FOODTYPEs.Single(p => p.ID == id); _db.FOODTYPEs.DeleteObject(foodType); _db.SaveChanges(); } catch (Exception) { flag = false; throw; } return flag; }
public void AddProduct(Product product) { FoodStoreEntities context = new FoodStoreEntities(); int maxId = GetNextProductId(); Product newProduct = new Product { productID = maxId, name = product.name, price = product.price, mfg = product.mfg, vendor = product.vendor }; context.Products.Add(newProduct); context.SaveChanges(); NotifySubscribers(); }
public static bool Delete(int id) { bool flag = true; try { _db = new FoodStoreEntities(); var account = _db.ACCOUNTs.Single(p => p.ID == id); _db.ACCOUNTs.DeleteObject(account); _db.SaveChanges(); } catch (Exception) { flag = false; throw; } return flag; }
public static bool DeleteById(int id) { bool flag = true; _db = new FoodStoreEntities(); try { MANAGER manager = _db.MANAGERs.Single(p => p.ID == id); _db.MANAGERs.DeleteObject(manager); _db.SaveChanges(); } catch (Exception) { flag = false; throw; } return flag; }
public void AddManufacturer(Manufacturer newMfg) { FoodStoreEntities context = new FoodStoreEntities(); Manufacturer manufacturer = new Manufacturer { mfg = newMfg.mfg, mfgDiscount = newMfg.mfgDiscount }; try { context.Manufacturers.Add(manufacturer); context.SaveChanges(); } catch (Exception e) { throw e; } }
//join Product table with Manufacturer and Supplier to create a List of ProductVM. public List <ProductVM> getAllProductsInformation() { FoodStoreEntities context = new FoodStoreEntities(); var query1 = from product in context.Products from manufacturer in context.Manufacturers where manufacturer.mfg == product.mfg select new { product.productID, product.name, //product description product.price, product.mfg, //name of manufacturer manufacturer.mfgDiscount, product.vendor, //supplier }; var query2 = (from item in query1 from supplier in context.Suppliers where supplier.vendor == item.vendor select new { ID = item.productID, Description = item.name, Price = item.price, Manufacturer = item.mfg, Mfg_Discount = item.mfgDiscount, Supplier = item.vendor, SupplierContact = supplier.supplier_email }).ToList(); var query3 = (from item in query2 select new ProductVM { ID = item.ID, Description = item.Description, Price = item.Price.Value.ToString("C"), Manufacturer = item.Manufacturer, Mfg_Discount = item.Mfg_Discount.ToString(), Supplier = item.Supplier, SupplierContact = item.SupplierContact }).ToList(); return(query3); }
public static List<FManager> GetListFManage() { _db = new FoodStoreEntities(); List<MANAGER> list = _db.MANAGERs.ToList(); List<FManager> listFManage = new List<FManager>(); foreach (MANAGER manager in list) { String encrypted = manager.Encrypted; String decrypted = StringEncrypt.DecryptString(encrypted, Configuration.ENCRYPT_PASSWORD); string[] arr = decrypted.Split('*'); FManager fManager = new FManager(); fManager.ID = manager.ID; fManager.Name = manager.Name; fManager.Email = arr[0]; fManager.Enumrole = int.Parse(arr[2]); fManager.Role = ProjectEnum.PrintRole(fManager.Enumrole); listFManage.Add(fManager); } return listFManage; }
public void DeleteProduct(int productID) { FoodStoreEntities context = new FoodStoreEntities(); Product product = (from p in context.Products where p.productID == productID select p).FirstOrDefault(); if (product != null) { try { context.Products.Remove(product); context.SaveChanges(); NotifySubscribers(); } catch (Exception e) { throw e; } } }
public static bool Insert(int id,string foodTypeName) { bool flag = true; try { _db = new FoodStoreEntities(); var foodType = new FOODTYPE(); foodType.ID = id; foodType.Name = foodTypeName; foodType.Alias = StringOperation.GetAlias(id, foodTypeName); _db.AddToFOODTYPEs(foodType); _db.SaveChanges(); } catch (Exception) { flag = false; throw; } return flag; }
public static List<FOODTYPE> GetList() { _db = new FoodStoreEntities(); return _db.FOODTYPEs.ToList(); }
public static FOODTYPE GetById(int id) { _db = new FoodStoreEntities(); return _db.FOODTYPEs.Single(p => p.ID == id); }
public static FOODTYPE Get(int id,FoodStoreEntities db) { return db.FOODTYPEs.Single(p => p.ID == id); }
public static List<FOOD> GetList(string searchText) { _db = new FoodStoreEntities(); return _db.FOODs.ToList().Where(p => p.Name.ToLower().StartsWith(searchText.ToLower())).ToList(); }
public static List<CITY> GetList(string city) { _db = new FoodStoreEntities(); return _db.CITies.ToList().Where(p => p.Name.ToLower().StartsWith(city.ToLower())).ToList(); }
public static FOOD GetById(int id,FoodStoreEntities db) { return db.FOODs.Single(p => p.ID == id); }
public static QUESTION GetById(int id,FoodStoreEntities db) { return db.QUESTIONs.Single(p => p.ID == id); }
//Lấy câu hỏi by Id public static QUESTION GetById(int id) { _db = new FoodStoreEntities(); return _db.QUESTIONs.Single(p => p.ID == id); }
public static List<DISTRICT> GetListDistrictByCityId(int cityId) { _db = new FoodStoreEntities(); return _db.CITies.Single(p => p.ID == cityId).DISTRICTs.ToList(); }
public static List<DISTRICT> GetList(string district) { _db = new FoodStoreEntities(); return _db.DISTRICTs.Where(p =>p.Name.ToLower().StartsWith(district.ToLower())).ToList(); }
public static int GetIdByTerm(string district) { _db = new FoodStoreEntities(); return _db.DISTRICTs.Where(p => p.Name == district).Select(p => p.ID).ToList()[0]; }
public static int GetIdByTerm(string city) { _db = new FoodStoreEntities(); return _db.CITies.Where(p => p.Name == city).Select(p => p.ID).ToList()[0]; }
//Lấy câu hỏi by Id public static DISTRICT GetById(int id) { _db = new FoodStoreEntities(); return _db.DISTRICTs.Single(p => p.ID == id); }
public static bool Update(int id, string foodTypeName) { bool flag = true; _db = new FoodStoreEntities(); try { var foodType = _db.FOODTYPEs.Single(p => p.ID == id); foodType.Name = foodTypeName; foodType.Alias = StringOperation.GetAlias(id, foodTypeName); _db.SaveChanges(); } catch (Exception) { flag = false; throw; } return flag; }
//Lấy list câu hỏi public static List<QUESTION> GetList() { _db = new FoodStoreEntities(); return _db.QUESTIONs.ToList(); }
public static CITY GetById(int id,FoodStoreEntities db) { return db.CITies.Single(p => p.ID == id); }
//Lấy câu hỏi by Id public static CITY GetById(int id) { _db = new FoodStoreEntities(); return _db.CITies.Single(p => p.ID == id); }
public static DISTRICT GetById(int id,FoodStoreEntities db) { return db.DISTRICTs.Single(p => p.ID == id); }
/** * Xuất danh sách CITY */ public static List<CITY> GetList() { _db = new FoodStoreEntities(); return _db.CITies.ToList(); }