public JsonResult UsernameExists(string username)
 {
     _db = new FoodStoreEntities();
     List<String> list = _db.ACCOUNTs.Select(x => x.Username).ToList();
     foreach (string s in list)
     {
         if (s.ToLower() == username.ToLower())
         {
             return Json("Username already exists", JsonRequestBehavior.AllowGet);
         }
     }
     return Json(true, JsonRequestBehavior.AllowGet);
 }
        public JsonResult District(string district)
        {
            _db = new FoodStoreEntities();
            try
            {
                DISTRICT dist = _db.DISTRICTs.Single(x => x.Name == district);
            }
            catch (Exception)
            {
                return Json("District isn't exists", JsonRequestBehavior.AllowGet);
            }

            return Json(true, JsonRequestBehavior.AllowGet);
        }
        public JsonResult City(string city)
        {
            _db = new FoodStoreEntities();
            try
            {
                CITY c = _db.CITies.Single(x => x.Name == city);
            }
            catch (Exception)
            {
                return Json("City isn't exists", JsonRequestBehavior.AllowGet);
            }

            return Json(true, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Edit(Edit edit)
        {
            int accountId = int.Parse(Session["id"].ToString());
            if (ModelState.IsValid)
            {
                int city = CityController.GetIdByTerm(edit.City);
                int district = DistrictController.GetIdByTerm(edit.District);

                if (Model.Controller.AccountController.Update(accountId, edit.Name, edit.Address, edit.Tel, edit.SocialId, city, district))
                {
                    return RedirectToAction("Index");
                }
            }

            var db = new FoodStoreEntities();

            return View();
        }
        public ActionResult Edit()
        {
            if (Session["login"] == null || (bool)Session["login"] == false)
            {
                return RedirectToAction("Login", "Account");
            }
            var db = new FoodStoreEntities();
             int accountId = int.Parse(Session["id"].ToString());
            ACCOUNT account = Model.Controller.AccountController.GetById(accountId);

            Edit edit = new Edit()
                            {
                                Address = account.Address,
                                //City = account.CITY.Name,
                                //District = account.DISTRICT.Name,
                                Name = account.Name,
                                SocialId = account.SocialID,
                                Tel = account.Tel,
                                Email = account.Email
                            };
            return View(edit);
        }
        public ActionResult Register(Register register)
        {
            if (ModelState.IsValid)
            {
                int city = CityController.GetIdByTerm(register.City);
                int district = DistrictController.GetIdByTerm(register.District);

                Model.Controller.AccountController.Insert(register.Username, register.Password, register.Name,
                                                          register.Address, register.Tel, register.SocialId,
                                                          register.Email, int.Parse(register.Question), register.Answer, city, district);
                return RedirectToAction("Login", "Account");
            }
            var db = new FoodStoreEntities();

            List<QUESTION> list = db.QUESTIONs.ToList();
            return View(register.ListQuestions = list);
        }
        public ActionResult Register()
        {
            var db = new FoodStoreEntities();

            List<QUESTION> list = db.QUESTIONs.ToList();
            return View(new Register
                            {
                                ListQuestions = list
                            });
        }
 public ActionResult OrderHistory()
 {
     if (Session["login"] == null || (bool)Session["login"] == false)
     {
         return RedirectToAction("Login", "Account");
     }
     var db = new FoodStoreEntities();
     int accountId = int.Parse(Session["id"].ToString());
     OrderHistory orderHistory = new OrderHistory()
                                     {
                                         Orders = db.ORDERs.Where(p => p.ACCOUNT.ID == accountId).ToList()
                                     };
     return View(orderHistory);
 }
 public ActionResult OrderDetail(int id)
 {
     if (Session["login"] == null || (bool)Session["login"] == false)
     {
         return RedirectToAction("Login", "Account");
     }
     var db = new FoodStoreEntities();
     int accountId = int.Parse(Session["id"].ToString());
     HistoryDetail historyDetail = new HistoryDetail()
                                       {
                                           OrderDetails = db.ORDERDETAILs.Where(p=>p.ORDER.ID == id).ToList()
                                       };
     return View(historyDetail);
 }