public ActionResult Detail(modelMenu entity) { if (ModelState.IsValid) { if (entity.menuId > 0) { var model = _services.GetById(entity.menuId); model.menuName = entity.menuName; model.menuUrl = entity.menuUrl; model.parentId = entity.parentId; model.isIcon = entity.isIcon; model.isSort = entity.isSort; model.isTaget = entity.isTaget; _services.Update(model); _services.Save(); _serviceLog.Add(new ActionLog { actionLogStatus = 1, actionLogTime = DateTime.Now, actionLogType = 1, actionNote = "Cập nhật danh mục Id:" + model.menuId, userIp = "", userName = User.Identity.Name }); _serviceLog.Save(); } else { var model = new Menu(); model.menuName = entity.menuName; model.menuUrl = entity.menuUrl; model.parentId = entity.parentId; model.isIcon = entity.isIcon; model.isSort = entity.isSort; model.isTaget = entity.isTaget; model.isTrash = false; model.languageId = entity.languageId; _services.Add(model); _services.Save(); _serviceLog.Add(new ActionLog { actionLogStatus = 1, actionLogTime = DateTime.Now, actionLogType = 1, actionNote = "Thêm mới danh mục Id:" + model.menuId, userIp = "", userName = User.Identity.Name }); _serviceLog.Save(); } return(RedirectToAction("Index", new { _parentId = entity.parentId })); } var category = _services.Dropdownlist(0, entity.menuId, entity.languageId); ViewBag.ParentId = category.Select(x => new SelectListItem { Text = x.Text, Value = x.Value.ToString() }); return(View(entity)); }
public ActionResult Detail(int?Id) { modelMenu entity; int _languageId = 1; string cookieLanguage = "1"; if (Request.Cookies["cookieLanguage"] != null) { cookieLanguage = Request.Cookies["cookieLanguage"].Value.ToString(); } int.TryParse(cookieLanguage, out _languageId); if (Id.HasValue && Id > 0) { var model = _services.GetById(Id.Value); entity = new modelMenu { isIcon = model.isIcon, isSort = model.isSort, isTaget = model.isTaget, isTrash = model.isTrash, languageId = model.languageId, menuId = model.menuId, menuName = model.menuName, menuUrl = model.menuUrl, parentId = model.parentId }; ViewBag.Title = "Cập nhật danh mục"; } else { entity = new modelMenu { languageId = _languageId }; ViewBag.Title = "Thêm mới danh mục"; } var category = _services.Dropdownlist(0, entity.menuId, _languageId); ViewBag.ParentId = category.Select(x => new SelectListItem { Text = x.Text, Value = x.Value.ToString() }); return(View(entity)); }