Ejemplo n.º 1
0
        public ActionResult AddDish()
        {
            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in dishTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() });
            }
            ViewData["DishType"] = items;
            ViewBag.CheckRunTimes = "1";

            return View();
        }
Ejemplo n.º 2
0
        public ActionResult AddMealSetDish(string mealSetID, string search, string filter)
        {
            ViewBag.notExistMealSet = "";

            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "Tất Cả", Value = "" });
            foreach (DataRow row in dishTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() });
            }
            ViewData["DishType"] = items;

            DataTable dishDT = new DataTable();
            DishInfoDetailTableAdapter adapter = new DishInfoDetailTableAdapter();

            try
            {
                dishDT = adapter.GetData();
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            if (!(string.IsNullOrEmpty(search) && string.IsNullOrEmpty(filter)))
            {
                int type = -1;
                int.TryParse(filter, out type);

                string name = search;
                if (name == null)
                {
                    name = String.Empty;
                }

                var result = from row in dishDT.AsEnumerable()
                             where (name == String.Empty ? true : StringExtensions.ContainsInsensitive(row.Field<string>("Name"), name))
                             && (type < 1 ? true : row.Field<int>("DishTypeID") == type)
                             select row;

                try
                {
                    dishDT = result.CopyToDataTable();
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(search))
                    {
                        ViewBag.notExistMealSet = "Không tìm thấy kết quả nào";
                    }
                    else
                    {
                        ViewBag.notExistMealSet = "Không tìm thấy kết quả nào với từ khóa: " + search;
                    }
                    Log.ErrorLog(ex.Message);
                }
            }

            ViewData["listDish"] = dishDT;

            try
            {
                int id = int.Parse(mealSetID);
                MealSetDishInfoTableAdapter mealSetDishInfoAdapter = new MealSetDishInfoTableAdapter();
                ViewData["listMealSetDish"] = mealSetDishInfoAdapter.GetDataByMealSetID(id);

                MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();
                EditMealSetModel model = new EditMealSetModel();
                DataTable mealSetDT = mealSetAdapter.GetDataByMealSetID(id);

                model.MealSetID = id;
                model.MealSetName = mealSetDT.Rows[0]["Name"].ToString();
                model.Description = mealSetDT.Rows[0]["Description"].ToString();
                model.Image = mealSetDT.Rows[0]["Image"].ToString();
                model.CanEatMore = (bool)mealSetDT.Rows[0]["CanEatMore"];

                return View(model);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return RedirectToAction("Error", "Error");
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddDish(DishViewModel model)
        {
            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in dishTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() });
            }
            ViewData["DishType"] = items;
            ViewBag.CheckRunTimes = "2";

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string updateBy = AccountInfo.GetUserName(Request);
            DateTime date = DateTime.Now;
            string dishName = model.Dishname;
            int dishTypeID = model.DishTypeID;
            string description = model.Description;
            string imgPath = null;
            string savePath = null;

            DishTableAdapter dishAdapter = new DishTableAdapter();
            DataTable dishDT = dishAdapter.GetByName(dishName);

            foreach (DataRow row in dishDT.Rows)
            {
                if (StringExtensions.EqualsInsensitive(row["Name"].ToString(), dishName))
                {
                    ModelState.AddModelError("", "Tên món ăn đã tồn tại.");
                    return View(model);
                }
            }

            if (!string.IsNullOrEmpty(model.Image))
            {
                savePath = _sourcePath + dishName.Replace(" ", "_") + ".jpg";
                var sourcePath = AppDomain.CurrentDomain.BaseDirectory + model.Image;

                System.IO.File.Move(sourcePath, savePath);
                imgPath = "\\Images\\DishImages\\" + dishName.Replace(" ", "_") + ".jpg";
            }

            try
            {

                dishAdapter.InsertDish(dishName, dishTypeID, description, imgPath, date, updateBy, date);
                Log.ActivityLog("Insert into Dish Table: DishName = " + dishName);
                Session["addDish"] = "Thêm món ăn thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["addDish"] = "Thêm món ăn thất bại!";
            }
            return RedirectToAction("AddDish", "Dish");
        }
Ejemplo n.º 4
0
        public ActionResult ViewDish(string search, string filter)
        {
            ViewBag.notExistDish = "";

            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            ViewData["DishType"] = dishTypeDT;

            DishTableAdapter adapter = new DishTableAdapter();

            try
            {
                dishDT = adapter.GetData();
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            if (!(string.IsNullOrEmpty(search) && string.IsNullOrEmpty(filter)))
            {
                int type = -1;
                int.TryParse(filter, out type);

                string name = search;
                if (name == null)
                {
                    name = String.Empty;
                }

                var result = from row in dishDT.AsEnumerable()
                             where (name == String.Empty ? true : StringExtensions.ContainsInsensitive(row.Field<string>("Name"), name))
                             && (type < 1 ? true : row.Field<int>("DishTypeID") == type)
                             select row;
                try
                {
                    return View(result.CopyToDataTable());
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(search))
                    {
                        ViewBag.notExistDish = "Không tìm thấy kết quả nào";
                    }
                    else
                    {
                        ViewBag.notExistDish = "Không tìm thấy kết quả nào với từ khóa: " + search;
                    }
                    Log.ErrorLog(ex.Message);
                }
            }

            return View(dishDT);
        }
Ejemplo n.º 5
0
        public ActionResult ListDish(string search, string filter)
        {
            ViewBag.notExistDish = "";

            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();

            items.Add(new SelectListItem { Text = "Tất Cả", Value = "" });

            foreach (DataRow row in dishTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() });
            }
            ViewData["DishType"] = items;

            DishInfoDetailTableAdapter adapter = new DishInfoDetailTableAdapter();

            try
            {
                dishDT = adapter.GetData();
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            if (!(string.IsNullOrEmpty(search) && string.IsNullOrEmpty(filter)))
            {
                int type = -1;
                int.TryParse(filter, out type);

                string name = search;
                if (name == null)
                {
                    name = String.Empty;
                }

                var result = from row in dishDT.AsEnumerable()
                             where (name == String.Empty ? true : StringExtensions.ContainsInsensitive(row.Field<string>("Name"), name))
                             && (type < 1 ? true : row.Field<int>("DishTypeID") == type)
                             select row;

                try
                {
                    return View(result.CopyToDataTable());
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(search))
                    {
                        ViewBag.notExistDish = "Không tìm thấy kết quả nào";
                    }
                    else
                    {
                        ViewBag.notExistDish = "Không tìm thấy kết quả nào với từ khóa: " + search;
                    }
                    Log.ErrorLog(ex.Message);
                }
            }

            return View(dishDT);
        }
Ejemplo n.º 6
0
        public ActionResult EditDish(EditDishModel model)
        {
            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in dishTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() });
            }
            ViewData["DishType"] = items;

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            DishTableAdapter dishAdapter = new DishTableAdapter();

            string updateBy = AccountInfo.GetUserName(Request);
            DateTime date = DateTime.Now;
            int dishID = model.DishID;
            string dishName = model.Dishname;
            int dishTypeID = model.DishTypeID;
            string description = model.Description;

            DataTable dt = dishAdapter.GetDataByDishID(dishID);

            string savePath = "\\Images\\DishImages\\" + dishName.Replace(" ", "_") + ".jpg";

            if (!StringExtensions.EqualsInsensitive(dt.Rows[0]["Name"].ToString(), dishName))
            {
                DataTable dishDT = dishAdapter.GetByName(dishName);

                foreach (DataRow row in dishDT.Rows)
                {
                    if (StringExtensions.EqualsInsensitive(row["Name"].ToString(), dishName))
                    {
                        ModelState.AddModelError("", "Tên món ăn đã tồn tại.");
                        return View(model);
                    }
                }

                savePath = "\\Images\\DishImages\\" + dishName.Replace(" ", "_") + ".jpg";

            }

            if (model.Image != null)
            {
                if (model.Image.Contains("Temp"))
                {
                    string oldImage = dt.Rows[0]["Image"].ToString();
                    var oldImagePath = AppDomain.CurrentDomain.BaseDirectory + oldImage;
                    System.IO.File.Delete(oldImagePath);
                }

                System.IO.File.Move(AppDomain.CurrentDomain.BaseDirectory + model.Image, AppDomain.CurrentDomain.BaseDirectory + savePath);
            }
            else
            {
                savePath = null;
            }

            try
            {
                dishAdapter.UpdateDish(dishName, dishTypeID, description, savePath, updateBy, date, dishID);
                Log.ActivityLog("Update to Dish Table: DishID = " + dishID);
                Session["editDish"] = "Cập nhật thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["editDish"] = "Cập nhật thất bại!";
            }

            return RedirectToAction("EditDish", "Dish", new { @dishID = model.DishID});
        }
Ejemplo n.º 7
0
        public ActionResult EditDish(string dishID)
        {
            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            foreach (DataRow row in dishTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() });
            }
            ViewData["DishType"] = items;

            try
            {
                int id = int.Parse(dishID);

                EditDishModel model = new EditDishModel();
                DishTableAdapter dishAdapter = new DishTableAdapter();
                DataTable dishDT = dishAdapter.GetDataByDishID(id);
                model.DishID = id;
                model.Dishname = dishDT.Rows[0]["Name"].ToString();
                model.DishTypeID = (int)dishDT.Rows[0]["DishTypeID"];
                model.Description = dishDT.Rows[0]["Description"].ToString();
                model.Image = dishDT.Rows[0]["Image"].ToString();
                return View(model);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return RedirectToAction("Error", "Error");
            }
        }