示例#1
0
        public ActionResult EditMealSet(string mealSetID)
        {
            try
            {
                int id = int.Parse(mealSetID);

                EditMealSetModel model = new EditMealSetModel();
                MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();
                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");
            }
        }
示例#2
0
        public ActionResult EditMealSet(EditMealSetModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();

            string updateBy = AccountInfo.GetUserName(Request);
            DateTime date = DateTime.Now;
            int mealSetID = model.MealSetID;
            string mealSetName = model.MealSetName;
            string description = model.Description;
            bool canEatMore = model.CanEatMore;

            DataTable dt = mealSetAdapter.GetDataByMealSetID(mealSetID);

            string savePath = "\\Images\\MealSetImages\\" + mealSetName.Replace(" ", "_") + ".jpg";

            if (!StringExtensions.EqualsInsensitive(dt.Rows[0]["Name"].ToString(), mealSetName))
            {
                DataTable mealSetDT = mealSetAdapter.GetDataByName(mealSetName);

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

                savePath = "\\Images\\MealSetImages\\" + mealSetName.Replace(" ", "_") + ".jpg";

            }
            if (model.Image != null)
            {
                if (model.Image.Contains("Temp2"))
                {
                    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
            {
                mealSetAdapter.UpdateMealSet(mealSetName, savePath, description, canEatMore, updateBy, date, mealSetID);
                XmlSync.SaveMealSetXml(mealSetID, mealSetName, canEatMore, date, updateBy, date, null);
                Log.ActivityLog("Update to MealSet Table: MealSetID = " + mealSetID);
                Session["editMealSet"] = "Cập nhật thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["editMealSet"] = "Cập nhật thành công!";
            }

            return RedirectToAction("EditMealSet", "MealSet", new { @mealSetID = model.MealSetID});
        }
示例#3
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");
            }
        }