public ActionResult SaveCreateData(TBL_MENU Menu, string menuProduct, string menuShift) { string flag = ""; try { dynamic MenuProduct = JArray.Parse(menuProduct); dynamic MenuShift = JArray.Parse(menuShift); Menu.UserCreate = int.Parse(Session["UserID"].ToString()); Menu.ModifiedDate = DateTime.Now; DA_Menu.Instance.Insert(Menu); int MenuID = DA_Menu.Instance.GetAll().OrderByDescending(x => x.MenuID).FirstOrDefault().MenuID; //Ghi log WriteLog("Menu", "Create", null, Menu); //List New Menu Product List <TBL_MENU_PRODUCT> newMenu_Product = new List <TBL_MENU_PRODUCT>(); for (int i = 0; i < MenuProduct.Count; i++) { TBL_MENU_PRODUCT Menu_Product = new TBL_MENU_PRODUCT(); Menu_Product.MenuID = MenuID; Menu_Product.ProductID = int.Parse(MenuProduct[i].Value); DA_MenuProduct.Instance.Insert(Menu_Product); //Add vào List New Menu Product newMenu_Product.Add(Menu_Product); } // Ghi log WriteLog("MenuProduct", "Create", null, newMenu_Product); //List New Menu Shift List <TBL_MENU_SHIFT> newMenu_Shift = new List <TBL_MENU_SHIFT>(); for (int i = 0; i < MenuShift.Count; i++) { TBL_MENU_SHIFT Menu_Shift = new TBL_MENU_SHIFT(); Menu_Shift.MenuID = MenuID; Menu_Shift.ShiftID = int.Parse(MenuShift[i].Value); DA_MenuShift.Instance.Insert(Menu_Shift); //Add vào List New Menu Shift newMenu_Shift.Add(Menu_Shift); } // Ghi log WriteLog("MenuShift", "Create", null, newMenu_Shift); flag = "1"; } catch (Exception) { flag = "-1"; throw; } return(Json(flag, JsonRequestBehavior.AllowGet)); }
public JsonResult Delete(int MenuID) { string flag = "1"; if (!DA_Menu.Instance.CheckBeforeDelete(MenuID)) { flag = "-1"; } else { // List Old Menu Shift List <TBL_MENU_SHIFT> oldMenuShift = new List <TBL_MENU_SHIFT>(); foreach (var shift in DA_MenuShift.Instance.GetAll().Where(x => x.MenuID == MenuID)) { // Add vào List Old Menu Shift oldMenuShift.Add(shift); DA_MenuShift.Instance.Delete(shift); } // Ghi log WriteLog("MenuShift", "Delete", oldMenuShift, null); // List Old Menu Product List <TBL_MENU_PRODUCT> oldMenuProduct = new List <TBL_MENU_PRODUCT>(); foreach (var product in DA_MenuProduct.Instance.GetAll().Where(x => x.MenuID == MenuID)) { // Add vào List Old Menu Product oldMenuProduct.Add(product); DA_MenuProduct.Instance.Delete(product); } //Ghi log WriteLog("MenuProduct", "Delete", oldMenuProduct, null); //Ghi log TBL_MENU oldMenu = DA_Menu.Instance.GetById(MenuID); WriteLog("Menu", "Delete", oldMenu, null); DA_Menu.Instance.Delete(MenuID); flag = "1"; } return(Json(flag, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveEditData(TBL_MENU Menu, string menuProduct, string menuShift) { string flag = ""; try { dynamic MenuProduct = JArray.Parse(menuProduct); dynamic MenuShift = JArray.Parse(menuShift); Menu.ModifiedUser = int.Parse(Session["UserID"].ToString()); Menu.ModifiedDate = DateTime.Now; DA_Menu.Instance.Update(Menu); // Ghi log TBL_MENU oldMenu = DA_Menu.Instance.GetById(Menu.MenuID); WriteLog("Menu", "Edit", oldMenu, Menu); // List Old Menu Product List <TBL_MENU_PRODUCT> oldMenu_Product = new List <TBL_MENU_PRODUCT>(); foreach (var menu_pro in DA_MenuProduct.Instance.GetAll().Where(x => x.MenuID == Menu.MenuID)) { //Add List Old Menu Product oldMenu_Product.Add(menu_pro); DA_MenuProduct.Instance.Delete(menu_pro); } // List New Menu Product List <TBL_MENU_PRODUCT> newMenu_Product = new List <TBL_MENU_PRODUCT>(); for (int i = 0; i < MenuProduct.Count; i++) { TBL_MENU_PRODUCT Menu_Product = new TBL_MENU_PRODUCT(); Menu_Product.MenuID = Menu.MenuID; Menu_Product.ProductID = int.Parse(MenuProduct[i].Value); DA_MenuProduct.Instance.Insert(Menu_Product); //Add List New Menu Product newMenu_Product.Add(Menu_Product); } // Ghi log WriteLog("MenuProduct", "Edit", oldMenu_Product, newMenu_Product); // List Old Menu Shift List <TBL_MENU_SHIFT> oldMenuShift = new List <TBL_MENU_SHIFT>(); foreach (var menu_shift in DA_MenuShift.Instance.GetAll().Where(x => x.MenuID == Menu.MenuID)) { // Add List Old Menu shift oldMenuShift.Add(menu_shift); DA_MenuShift.Instance.Delete(menu_shift); } // List New Menu Shift List <TBL_MENU_SHIFT> newMenuShift = new List <TBL_MENU_SHIFT>(); for (int i = 0; i < MenuShift.Count; i++) { TBL_MENU_SHIFT Menu_Shift = new TBL_MENU_SHIFT(); Menu_Shift.MenuID = Menu.MenuID; Menu_Shift.ShiftID = int.Parse(MenuShift[i].Value); DA_MenuShift.Instance.Insert(Menu_Shift); // Add List New Menu shift newMenuShift.Add(Menu_Shift); } // Ghi log WriteLog("MenuShift", "Edit", oldMenuShift, newMenuShift); flag = "1"; } catch (Exception) { flag = "-1"; throw; } return(Json(flag, JsonRequestBehavior.AllowGet)); }