/// <summary> /// 取得選單內容檔 /// </summary> /// <param name="muID"></param> /// <returns></returns> PTFunction GetProtorMentFunctionByID(string muID) { PTFunction pTFunction = this.PorDB.PTFunction.Where(o => o.MAP_MUID == muID).FirstOrDefault(); if (pTFunction == null) { throw new Exception("無法取得選單內容檔"); } return(pTFunction); }
public MenuDataModel SaveMenuData(DataSaveMode mode, MenuDataModel model) { MenuDataModel result = new MenuDataModel(); string muID = model.MenuID; PTMenu pTMenu = null; PTFunction pTFunction = null; try { if (mode == DataSaveMode.Add) { var chkHasMenu = this.GetMenuDataByID(muID); if (chkHasMenu != null) { throw new Exception("已有MenuID為:" + muID + " 的選單,目錄名稱為:" + chkHasMenu.MenuName); } //menu pTMenu = new PTMenu() { BUD_DTM = DateTime.UtcNow.AddHours(8), BUD_USRID = SignInProvider.Instance.User.ADAccount }; //function pTFunction = new PTFunction() { BUD_DTM = DateTime.UtcNow.AddHours(8), BUD_USRID = SignInProvider.Instance.User.ADAccount, }; } else if (mode == DataSaveMode.Edit) { //menu pTMenu = this.PorDB.PTMenu.Where(o => o.MUID == muID).FirstOrDefault(); if (pTMenu == null) { throw new Exception("無法取得選單主檔"); } //function pTFunction = this.GetProtorMentFunctionByID(muID); } else { throw new Exception("[儲存目錄]無法得知的儲存模式"); } pTMenu.MUID = model.MenuID; pTMenu.MU_NM = model.MenuName; pTMenu.MUICON = model.MenuIcon; pTMenu.ACT_FG = model.Enabled; pTMenu.MENU_FG = model.MenuEnabled; pTMenu.MUPID = model.ParentMenuID; pTMenu.UPD_DTM = DateTime.UtcNow.AddHours(8); pTMenu.UPD_USRID = SignInProvider.Instance.User.ADAccount; pTFunction.MAP_MUID = muID; pTFunction.SORT_SEQ = model.MenuSort; pTFunction.FN_DIR = model.MenuPathController; pTFunction.FN_KEY = model.MenuPathAction; pTFunction.FN_LINK = string.Concat(model.MenuPathController, "/", model.MenuPathAction); pTFunction.UPD_DTM = DateTime.UtcNow.AddHours(8); pTFunction.UPD_USRID = SignInProvider.Instance.User.ADAccount; if (mode == DataSaveMode.Add) { this.PorDB.PTMenu.Add(pTMenu); this.PorDB.PTFunction.Add(pTFunction); } else { this.PorDB.Entry(pTMenu).State = EntityState.Modified; this.PorDB.Entry(pTFunction).State = EntityState.Modified; } this.PorDB.SaveChanges(); result = this.GetMenuDataByID(muID); } catch (Exception ex) { throw ex; } if (result == null) { throw new Exception("儲存目錄後無法取得目錄資料"); } return(result); }