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 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 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;
 }
示例#5
0
        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();
        }
示例#6
0
        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;
            }
        }
示例#7
0
        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 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;
        }
        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;
        }
示例#10
0
        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;
        }
示例#11
0
        public static bool Update(int id, String foodName, int foodPrice, int foodTypeId, String foodImage,
                                  String foodDetail)
        {
            bool flag = true;
            _db = new FoodStoreEntities();
            try
            {
                var food = _db.FOODs.Single(p => p.ID == id);
                var foodType = FoodTypeController.Get(foodTypeId, _db);

                food.Name = foodName;
                food.Price = foodPrice;
                food.FOODTYPE = foodType;
                food.Detail = foodDetail;
                if (foodImage != null)
                    food.Image = foodImage;
                food.Alias = StringOperation.GetAlias(id, foodName);

                _db.SaveChanges();
            }
            catch (Exception)
            {
                flag = false;
                throw;
            }
            return flag;
        }
        public static bool Insert(int userId, String fullName, String address, String tel, DateTime orrdertime,
                                  String note, int state, int totalpayent, int idCity, int idDistrict, List<int> foods,
                                  List<int> count)
        {
            //Khởi tạo một đối tượng ACCOUNT

            bool flag = true;

            _db = new FoodStoreEntities();

            int id = GetMaxId();
            ORDER currentorder = null;
            var orderdetails = new List<ORDERDETAIL>();
            ACCOUNT account = AccountController.GetById(userId, _db);
            CITY city = CityController.GetById(idCity, _db);
            DISTRICT district = DistrictController.GetById(idDistrict, _db);
            try
            {
                var order = new ORDER
                                {
                                    ID = id,
                                    ACCOUNT = account,
                                    Name = fullName,
                                    Tel = tel,
                                    Address = address,
                                    Date = orrdertime,
                                    Note = note,
                                    State = state,
                                    TotalPayment = totalpayent,
                                    DISTRICT = district,
                                    CITY = city
                                };

                _db.ORDERs.AddObject(order);
                _db.SaveChanges();

                int n = foods.Count();
                for (int i = 0; i < n; i++)
                {
                    int fId = foods[i];
                    FOOD food = FoodController.GetById(fId, _db);
                    currentorder = GetById(id, _db);
                    var orderdetail = new ORDERDETAIL
                                          {
                                              ID = OrderDetailController.GetMaxId(),
                                              ORDER = currentorder,
                                              FOOD = food,
                                              Count = count[i],
                                              TotalPayment = count[i]*food.Price,
                                              Price = food.Price
                                          };
                    orderdetails.Add(orderdetail);
                    _db.ORDERDETAILs.AddObject(orderdetail);
                    _db.SaveChanges();
                }

                _db.AcceptAllChanges();
            }
            catch (Exception)
            {
                flag = false;
                throw;
            }
            if (flag)
            {
                StringBuilder body = new StringBuilder()
                    .AppendLine("A new order has been submitted")
                    .AppendLine("---")
                    .AppendLine("Items:");

                foreach (ORDERDETAIL i in orderdetails)
                {
                    int? subtotal = i.Price*i.Count;
                    body.AppendFormat("{0} x {1} (subtotal: {2:c})", i.Count,
                                      i.FOOD.Name,
                                      subtotal).AppendLine();
                }

                body.AppendLine()
                    .AppendFormat("Total order value: {0:c}", ((int)currentorder.TotalPayment).ToString("c"))
                    .AppendLine("---")
                    .AppendLine("Ship to:")
                    .AppendLine(currentorder.Name)
                    .AppendLine(currentorder.Note)
                    .AppendLine(currentorder.Tel)
                    .AppendLine(currentorder.Address)
                    .AppendLine(currentorder.DISTRICT.Name)
                    .AppendLine(currentorder.CITY.Name)
                    .AppendLine("---");

                Mail.SendOrderDetail(currentorder.Note, currentorder.Name, body);
            }

            return flag;
        }
        public static bool Insert(String encrypted, String name)
        {
            //Khởi tạo một đối tượng ACCOUNT
            bool flag = true;
            _db = new FoodStoreEntities();
            try
            {
                var manager = new MANAGER();
                manager.ID = GetMaxId();
                manager.Name = name;
                manager.Encrypted = encrypted;
                _db.MANAGERs.AddObject(manager);

                _db.SaveChanges();
            }
            catch (Exception)
            {
                flag = false;
                throw;
            }

            return flag;
        }
        public static bool Update(int id, String fullName, String address, String tel, String socialId, int idCity, int idDistrict)
        {
            //Khởi tạo một đối tượng ACCOUNT

            _db = new FoodStoreEntities();

            var account = GetById(id);

            account.Name = fullName;
            account.Address = address;
            account.Tel = tel;
            account.SocialID = socialId;
            account.CITY = CityController.GetById(idCity, _db);
            account.DISTRICT = DistrictController.GetById(idDistrict, _db);

            //Chèn đối tượng ACCOUNT vào CSDL
            bool flag = true;
            try
            {
                _db.SaveChanges();
            }
            catch (Exception)
            {
                flag = false;
                throw;
            }
            return flag;
        }
        public static bool Insert(String username, String password,String fullName, String address, String tel, String socialId, String email, int question, String answer, int idCity, int idDistrict)
        {
            //Khởi tạo một đối tượng ACCOUNT

            _db = new FoodStoreEntities();

            try
            {
                ACCOUNT check = _db.ACCOUNTs.Single(p => p.Username == username);
            }
            catch (Exception)
            {

                var account = new ACCOUNT();
                account.ID = GetMaxId();
                account.Username = username;
                account.Password = SaltEncrypt.HashCodeSHA1(password);
                account.Name = fullName;
                account.Address = address;
                account.Tel = tel;
                account.SocialID = socialId;
                account.Email = email;
                account.QUESTION = QuestionController.GetById(question, _db);
                account.Answer = answer;
                account.CITY = CityController.GetById(idCity, _db);
                account.DISTRICT = DistrictController.GetById(idDistrict, _db);

                //Chèn đối tượng ACCOUNT vào CSDL
                bool flag = true;
                try
                {

                    _db.AddToACCOUNTs(account);
                    _db.SaveChanges();
                }
                catch (Exception)
                {
                    flag = false;
                    throw;
                }
                return flag;
            }
            return false;
        }
 public static bool UpdateState(int id, int state)
 {
     bool flag = true;
     _db = new FoodStoreEntities();
     try
     {
         ORDER order = GetById(id, _db);
         order.State = state;
         _db.SaveChanges();
     }
     catch (Exception)
     {
         flag = false;
         throw;
     }
     return flag;
 }
示例#17
0
        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;
        }