private static string CreateOrUpdate(MenuDisplayNameDataModel data, RequestProfile requestProfile, string action) { var sql = "EXEC "; switch (action) { case "Create": sql += "dbo.MenuDisplayNameInsert " + " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) + ", " + ToSQLParameter(BaseDataModel.BaseDataColumns.ApplicationId, requestProfile.ApplicationId); break; case "Update": sql += "dbo.MenuDisplayNameUpdate " + " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId); break; default: break; } sql = sql + ", " + ToSQLParameter(data, MenuDisplayNameDataModel.DataColumns.MenuDisplayNameId) + ", " + ToSQLParameter(data, MenuDisplayNameDataModel.DataColumns.LanguageId) + ", " + ToSQLParameter(data, MenuDisplayNameDataModel.DataColumns.Value) + ", " + ToSQLParameter(data, MenuDisplayNameDataModel.DataColumns.MenuId) + ", " + ToSQLParameter(data, MenuDisplayNameDataModel.DataColumns.IsDefault); return(sql); }
private static void CreateChildMenuRecords(int newParentMenuId, string newApplicationModule, List <MenuDataModel> childMenuRecords, List <MenuDataModel> dataSourceMenu, List <MenuDisplayNameDataModel> menuDisplayNameList, int languageId, RequestProfile newRequestProfile) { if (childMenuRecords.Count > 0) { var sortOrderSeed = 1; foreach (MenuDataModel menuSourceRecord in childMenuRecords) { var menuModel = new MenuDataModel(); menuModel.Name = menuSourceRecord.Name; menuModel.Value = menuSourceRecord.Value; menuModel.Description = menuSourceRecord.Description; menuModel.IsVisible = menuSourceRecord.IsVisible; menuModel.IsChecked = menuSourceRecord.IsChecked; menuModel.PrimaryDeveloper = menuSourceRecord.PrimaryDeveloper; menuModel.NavigateURL = menuSourceRecord.NavigateURL; menuModel.ParentMenuId = newParentMenuId; menuModel.ApplicationId = newRequestProfile.ApplicationId; menuModel.ApplicationModule = newApplicationModule; menuModel.SortOrder = sortOrderSeed; if (!DoesExist(menuModel, newRequestProfile)) { var newMenuId = MenuDataManager.Create(menuModel, newRequestProfile); var menuDisplayNameValue = menuModel.Value; try { menuDisplayNameValue = menuDisplayNameList.Find(x => x.MenuId == menuSourceRecord.MenuId && x.IsDefault == 1).Value; } catch { } var dataDisplayName = new MenuDisplayNameDataModel(); dataDisplayName.MenuId = newMenuId; dataDisplayName.Value = menuDisplayNameValue; dataDisplayName.LanguageId = languageId; dataDisplayName.IsDefault = 1; // create display name entry according to the default display name MenuDisplayNameDataManager.Create(dataDisplayName, newRequestProfile); sortOrderSeed++; var childMenuRecordsList = dataSourceMenu .Where(t => t.ParentMenuId == menuSourceRecord.MenuId) .Select(t => t) .OrderBy(t => t.SortOrder).ToList(); CreateChildMenuRecords(newMenuId, newApplicationModule, childMenuRecordsList, dataSourceMenu, menuDisplayNameList, languageId, newRequestProfile); } } } }
public static DataTable Search(MenuDisplayNameDataModel data, RequestProfile requestProfile) { var list = GetEntityDetails(data, requestProfile); var table = list.ToDataTable(); return(table); }
public static void SyncWithMenu(int applicationId) { //MenuList var requestProfile = new RequestProfile(); requestProfile.AuditId = 10; requestProfile.ApplicationId = applicationId; const string sql = @"dbo.MenuList "; var parameters = new { AuditId = requestProfile.AuditId , ApplicationId = applicationId }; List <MenuDataModel> result; using (var dataAccess = new DataAccessBase(DataStoreKey)) { result = dataAccess.Connection.Query <MenuDataModel>(sql, parameters, commandType: CommandType.StoredProcedure).ToList(); } var menuDisplayNameData = new MenuDisplayNameDataModel(); var menuDisplayNameList = MenuDisplayNameDataManager.GetEntityDetails(menuDisplayNameData, requestProfile); // get Language id of "Standard" var languageData = new LanguageDataModel(); languageData.Name = "English"; var languageRecords = LanguageDataManager.GetEntityDetails(languageData, requestProfile, 0); if (languageRecords.Count > 0) { var languageId = languageRecords[0].LanguageId.Value; foreach (var menuSourceRecord in result) { var menuId = menuSourceRecord.MenuId; var displayNameRecord = menuDisplayNameList.Find(x => x.MenuId == menuSourceRecord.MenuId && x.IsDefault == 1); if (displayNameRecord == null) { var dataDisplayName = new MenuDisplayNameDataModel(); dataDisplayName.MenuId = menuSourceRecord.MenuId; dataDisplayName.Value = menuSourceRecord.Name; dataDisplayName.LanguageId = languageId; dataDisplayName.IsDefault = 1; // create display name entry according to the default display name MenuDisplayNameDataManager.Create(dataDisplayName, requestProfile); } } } }
public static DataTable DoesExist(MenuDisplayNameDataModel data, RequestProfile requestProfile) { var doesExistRequest = new MenuDisplayNameDataModel(); doesExistRequest.MenuId = data.MenuId; doesExistRequest.LanguageId = data.LanguageId; return(Search(doesExistRequest, requestProfile)); }
private void bindGrid() { var data = new MenuDisplayNameDataModel(); data.MenuId = MenuId; var dt = MenuDisplayNameDataManager.Search(data, SessionVariables.RequestProfile); dgvDisplayNames.DataSource = dt; dgvDisplayNames.DataBind(); }
public static bool DoesExist(MenuDisplayNameDataModel data, RequestProfile requestProfile) { var doesExistRequest = new MenuDisplayNameDataModel(); doesExistRequest.MenuId = data.MenuId; doesExistRequest.LanguageId = data.LanguageId; var list = GetEntityDetails(doesExistRequest, requestProfile); return(list.Count > 0); }
protected void lnkSave_Click(object sender, EventArgs e) { var data = new MenuDisplayNameDataModel(); data.MenuId = MenuId; data.LanguageId = Convert.ToInt32(drpLanguage.SelectedValue); data.Value = txtValue.Text.Trim(); data.IsDefault = chkIsDefault.Checked ? 1 : 0; MenuDisplayNameDataManager.Create(data, SessionVariables.RequestProfile); bindGrid(); formContainer.Visible = false; }
public override int?Save(string action) { var data = new MenuDataModel(); data.Name = Name; data.Description = Description; data.SortOrder = SortOrder; data.MenuDisplayName = DisplayName; data.NavigateURL = NavigateURL; data.IsChecked = IsChecked; data.IsVisible = IsVisible; data.ParentMenuId = ParentMenuId; data.PrimaryDeveloper = PrimaryDeveloper; data.ApplicationId = ApplicationId; data.ApplicationModule = ApplicationModule; if (action == "Insert") { var dtMenu = MenuDataManager.DoesExist(data, SessionVariables.RequestProfile); if (dtMenu.Rows.Count == 0) { data.MenuId = MenuDataManager.Create(data, SessionVariables.RequestProfile); var dataDisplayName = new MenuDisplayNameDataModel(); dataDisplayName.MenuId = data.MenuId; dataDisplayName.Value = DisplayName; dataDisplayName.LanguageId = ApplicationCommon.LanguageId; dataDisplayName.IsDefault = 1; MenuDisplayNameDataManager.Create(dataDisplayName, SessionVariables.RequestProfile); } else { throw new Exception("Record with given ID already exists."); } } else { data.MenuId = MenuId; MenuDataManager.Update(data, SessionVariables.RequestProfile); } // not correct ... when doing insert, we didn't get/change the value of ClientID ? return(data.MenuId); }
public static void Delete(MenuDisplayNameDataModel dataQuery, RequestProfile requestProfile) { const string sql = @"dbo.MenuDisplayNameDelete "; var parameters = new { AuditId = requestProfile.AuditId , MenuDisplayNameId = dataQuery.MenuDisplayNameId }; using (var dataAccess = new DataAccessBase(DataStoreKey)) { dataAccess.Connection.Execute(sql, parameters, commandType: CommandType.StoredProcedure); } }
protected void lnkDelete_Click(object sender, EventArgs e) { if (dgvDisplayNames.Rows.Count > 0) { foreach (GridViewRow dr in dgvDisplayNames.Rows) { var chkSelected = (CheckBox)dr.FindControl("chkSelected"); if (chkSelected != null) { if (chkSelected.Checked) { var data = new MenuDisplayNameDataModel(); data.MenuDisplayNameId = Convert.ToInt32(dgvDisplayNames.DataKeys[dr.DataItemIndex].Value); MenuDisplayNameDataManager.Delete(data, SessionVariables.RequestProfile); } } } } bindGrid(); }
public static List <MenuDisplayNameDataModel> GetEntityDetails(MenuDisplayNameDataModel dataQuery, RequestProfile requestProfile) { const string sql = @"dbo.MenuDisplayNameSearch "; var parameters = new { AuditId = requestProfile.AuditId , ApplicationId = dataQuery.ApplicationId , MenuId = dataQuery.MenuId , LanguageId = dataQuery.LanguageId , Value = dataQuery.Value }; List <MenuDisplayNameDataModel> result; using (var dataAccess = new DataAccessBase(DataStoreKey)) { result = dataAccess.Connection.Query <MenuDisplayNameDataModel>(sql, parameters, commandType: CommandType.StoredProcedure).ToList(); } return(result); }
protected void lnkUpdate_Click(object sender, EventArgs e) { if (dgvDisplayNames.Rows.Count > 0) { foreach (GridViewRow dr in dgvDisplayNames.Rows) { var data = new MenuDisplayNameDataModel(); data.MenuDisplayNameId = Convert.ToInt32(dgvDisplayNames.DataKeys[dr.DataItemIndex].Value); var chkIsDefault1 = (CheckBox)dr.FindControl("chkIsDefault"); var drpLanguage1 = (DropDownList)dr.FindControl("drpLanguage"); var txtValue1 = (TextBox)dr.FindControl("txtValue"); data.MenuId = MenuId; data.LanguageId = Convert.ToInt32(drpLanguage1.SelectedValue); data.Value = txtValue1.Text.Trim(); data.IsDefault = chkIsDefault1.Checked ? 1 : 0; MenuDisplayNameDataManager.Update(data, SessionVariables.RequestProfile); } } bindGrid(); }
public static string ToSQLParameter(MenuDisplayNameDataModel data, string dataColumnName) { var returnValue = "NULL"; switch (dataColumnName) { case MenuDisplayNameDataModel.DataColumns.MenuDisplayNameId: if (data.MenuDisplayNameId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, MenuDisplayNameDataModel.DataColumns.MenuDisplayNameId, data.MenuDisplayNameId); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, MenuDisplayNameDataModel.DataColumns.MenuDisplayNameId); } break; case MenuDisplayNameDataModel.DataColumns.MenuId: if (data.MenuId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, MenuDisplayNameDataModel.DataColumns.MenuId, data.MenuId); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, MenuDisplayNameDataModel.DataColumns.MenuId); } break; case MenuDisplayNameDataModel.DataColumns.IsDefault: if (data.IsDefault != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, MenuDisplayNameDataModel.DataColumns.IsDefault, data.IsDefault); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, MenuDisplayNameDataModel.DataColumns.IsDefault); } break; case MenuDisplayNameDataModel.DataColumns.Value: if (!string.IsNullOrEmpty(data.Value)) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, MenuDisplayNameDataModel.DataColumns.Value, data.Value.Trim()); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, MenuDisplayNameDataModel.DataColumns.Value); } break; case MenuDisplayNameDataModel.DataColumns.Menu: if (!string.IsNullOrEmpty(data.Menu)) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, MenuDisplayNameDataModel.DataColumns.Menu, data.Menu.Trim()); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, MenuDisplayNameDataModel.DataColumns.Menu); } break; case MenuDisplayNameDataModel.DataColumns.Language: if (!string.IsNullOrEmpty(data.Language)) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, MenuDisplayNameDataModel.DataColumns.Language, data.Language.Trim()); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, MenuDisplayNameDataModel.DataColumns.Language); } break; case MenuDisplayNameDataModel.DataColumns.LanguageId: if (data.LanguageId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, MenuDisplayNameDataModel.DataColumns.LanguageId, data.LanguageId); } else { returnValue = returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, MenuDisplayNameDataModel.DataColumns.LanguageId); } break; default: returnValue = StandardDataManager.ToSQLParameter(data, dataColumnName); break; } return(returnValue); }
public static void Update(MenuDisplayNameDataModel data, RequestProfile requestProfile) { var sql = CreateOrUpdate(data, requestProfile, "Update"); DBDML.RunSQL("MenuDisplayName.Update", sql, DataStoreKey); }
public static void Sync(int newApplicationId, int oldApplicationId, RequestProfile requestProfile, int languageId) { var tempMapping = new Dictionary <int, int>(); // get all records for old Application Id var menuData = new MenuDataModel(); menuData.ApplicationId = oldApplicationId; menuData.ParentMenuId = 12393; var menuList = MenuDataManager.GetEntityDetails(menuData, requestProfile, 0); var menuDisplayNameData = new MenuDisplayNameDataModel(); var menuDisplayNameList = MenuDisplayNameDataManager.GetEntityDetails(menuDisplayNameData, requestProfile); // formaulate a new request Profile which will have new Applicationid var newRequestProfile = new RequestProfile(); newRequestProfile.ApplicationId = newApplicationId; newRequestProfile.AuditId = requestProfile.AuditId; foreach (var menuItem in menuList) { var parentMenuName = menuItem.ParentMenu; //get new fc mode id based on fc mode name //var newParentMenuId = timeZoneList.Find(x => x.Name == fcModeName).TimeZoneId; var data = new MenuDataModel(); data.ApplicationId = newApplicationId; data.Name = menuItem.Name; data.ParentMenuId = menuItem.ParentMenuId; // check for existing record in new Application Id var dt = DoesExist(data, newRequestProfile); if (dt == null || dt.Rows.Count == 0) { data.Description = menuItem.Description; data.SortOrder = menuItem.SortOrder; data.IsChecked = menuItem.IsChecked; data.IsVisible = menuItem.IsVisible; data.NavigateURL = menuItem.NavigateURL; data.PrimaryDeveloper = menuItem.PrimaryDeveloper; data.Value = menuItem.Value; if (string.IsNullOrEmpty(data.PrimaryDeveloper)) { data.PrimaryDeveloper = " "; } var menuDisplayNameValue = menuItem.Value; try { menuDisplayNameValue = menuDisplayNameList.Find(x => x.MenuId == menuItem.MenuId && x.IsDefault == 1).Value; } catch { } //create in new application id var newMenuId = Create(data, newRequestProfile); var dataDisplayName = new MenuDisplayNameDataModel(); dataDisplayName.MenuId = newMenuId; dataDisplayName.Value = menuDisplayNameValue; dataDisplayName.LanguageId = languageId; dataDisplayName.IsDefault = 1; // create display name entry according to the default display name MenuDisplayNameDataManager.Create(dataDisplayName, newRequestProfile); tempMapping.Add(menuItem.MenuId.Value, newMenuId); } } //menuData.ApplicationId = newApplicationId; //var newMenuList = MenuDataManager.GetEntityDetails(menuData, newRequestProfile); //foreach (var newMenuItem in menuList) //{ // if (newMenuItem.ParentMenuId != null) // { // var newMenuData = new MenuDataModel(); // newMenuData.MenuId = newMenuItem.MenuId; // if (tempMapping.ContainsKey(newMenuItem.ParentMenuId.Value)) // { // menuData.ParentMenuId = tempMapping[newMenuItem.ParentMenuId.Value]; // try // { // UpdateParentMenuOnly(newMenuData, newRequestProfile.AuditId); // } // catch { } // } // } //} }
public static MenuDisplayNameDataModel GetDetails(MenuDisplayNameDataModel data, RequestProfile requestProfile) { var list = GetEntityDetails(data, requestProfile); return(list.FirstOrDefault()); }
public static void SyncModule(string newModule, int newApplicationId, string sourceModule, int sourceApplicationId, RequestProfile requestProfile) { var sourceRequestProfile = new RequestProfile(); sourceRequestProfile.ApplicationId = sourceApplicationId; sourceRequestProfile.AuditId = requestProfile.AuditId; var newRequestProfile = new RequestProfile(); newRequestProfile.ApplicationId = newApplicationId; newRequestProfile.AuditId = requestProfile.AuditId; // get Language id of "Standard" var languageData = new LanguageDataModel(); languageData.Name = "English"; var languageRecords = LanguageDataManager.GetEntityDetails(languageData, newRequestProfile, 0); if (languageRecords.Count > 0) { DeleteHardExistingRecords(newModule, newRequestProfile); var languageId = languageRecords[0].LanguageId.Value; var dataQuery = new MenuDataModel(); dataQuery.ApplicationModule = sourceModule; dataQuery.ApplicationId = sourceApplicationId; var dataSourceMenu = MenuDataManager.GetEntityDetails(dataQuery, sourceRequestProfile, 0); var menuDisplayNameData = new MenuDisplayNameDataModel(); var menuDisplayNameList = MenuDisplayNameDataManager.GetEntityDetails(menuDisplayNameData, sourceRequestProfile); var sortOrderSeed = 101; var listSourceRecords = dataSourceMenu .Where(t => t.ParentMenuId == null) .Select(t => t) .OrderBy(t => t.SortOrder).ToList(); if (listSourceRecords.Count > 0) { foreach (MenuDataModel menuSourceRecord in listSourceRecords) { var menuModel = new MenuDataModel(); menuModel.Name = menuSourceRecord.Name; menuModel.Value = menuSourceRecord.Value; menuModel.Description = menuSourceRecord.Description; menuModel.IsVisible = menuSourceRecord.IsVisible; menuModel.IsChecked = menuSourceRecord.IsChecked; menuModel.ParentMenuId = menuSourceRecord.ParentMenuId; menuModel.PrimaryDeveloper = menuSourceRecord.PrimaryDeveloper; menuModel.NavigateURL = menuSourceRecord.NavigateURL; menuModel.ApplicationId = newApplicationId; menuModel.ApplicationModule = newModule; menuModel.SortOrder = sortOrderSeed; if (!DoesExist(menuModel, newRequestProfile)) { var newMenuId = MenuDataManager.Create(menuModel, newRequestProfile); var menuDisplayNameValue = menuModel.Value; try { menuDisplayNameValue = menuDisplayNameList.Find(x => x.MenuId == menuSourceRecord.MenuId && x.IsDefault == 1).Value; } catch { } var dataDisplayName = new MenuDisplayNameDataModel(); dataDisplayName.MenuId = newMenuId; dataDisplayName.Value = menuDisplayNameValue; dataDisplayName.LanguageId = languageId; dataDisplayName.IsDefault = 1; // create display name entry according to the default display name MenuDisplayNameDataManager.Create(dataDisplayName, newRequestProfile); sortOrderSeed++; var childMenuRecordsList = dataSourceMenu .Where(t => t.ParentMenuId == menuSourceRecord.MenuId) .Select(t => t) .OrderBy(t => t.SortOrder).ToList(); CreateChildMenuRecords(newMenuId, newModule, childMenuRecordsList, dataSourceMenu, menuDisplayNameList, languageId, newRequestProfile); } } // get menu category id of "Standard" var menuCategoryData = new MenuCategoryDataModel(); menuCategoryData.Name = "Standard"; var menuCategoryRecords = MenuCategoryDataManager.GetEntityDetails(menuCategoryData, newRequestProfile, 0); if (menuCategoryRecords.Count > 0) { var menuCategoryId = menuCategoryRecords[0].MenuCategoryId; // get newly inserted records dataQuery = new MenuDataModel(); dataQuery.ApplicationModule = newModule; dataQuery.ApplicationId = newApplicationId; var newMenuRecords = GetEntityDetails(dataQuery, newRequestProfile); var listMenuIds = newMenuRecords.Select(x => x.MenuId.Value).ToArray(); // add MenuCategoryXMenu records MenuCategoryXMenuDataManager.CreateByMenuCategory(menuCategoryId.Value, listMenuIds, newRequestProfile); } } } }