private ListItem[] GetDbFields() { var result = new List <ListItem>(); var editor = holderExtraSettings.FindControl(EDITOR_CONTROL_ID) as IDbFieldEditor; if (editor == null) { return(result.ToArray()); } var fld = editor.GetField(txtColName.Text); if (fld == null) { return(result.ToArray()); } lbNoFields.Visible = true; ddlTableFieldName.Visible = false; lbNoFields.Text = string.Format("There are no existing fields of selected type ({0}). The new field will be created.", fld.SqlType); var rosterConfigService = new RosterConfigService(); var lists = new List <ListMetadataField>(); var dependentLists = ReferenceListsGuids; if (dependentLists.IsEmpty()) { return(result.ToArray()); } var existingFields = List.ListMetadataFields.Select(item => item.InternalName).ToList(); dependentLists.ForEach(listId => { var list = rosterConfigService.GetList(listId); if (list != null) { lists.AddRange(list.ListMetadataFields.Where(item => item.FieldType == fld.SqlType && !existingFields.Contains(item.InternalName))); } }); if (!lists.Any()) { return(result.ToArray()); } var grouped = lists.GroupBy(item => item.InternalName).ToList(); if (!grouped.IsEmpty()) { grouped.ForEach(group => { var itemName = string.Format("{0} ({1})", @group.Key, string.Join(",", @group.Select(x => string.Format("{0} - {1}", x.FieldName, x.ListMetadata.Name)))); result.Add(new ListItem(itemName, @group.Key)); }); lbNoFields.Visible = false; ddlTableFieldName.Visible = true; } return(result.ToArray()); }
private List <Tuple <string, string> > GetCriteria(LookupQuery query) { var whereCriteria = new List <Tuple <string, string> >(); if (query.ParentKeyValue.ToInt() != 0) { var rosterConfigService = new RosterConfigService(); var field = rosterConfigService.GetField(query.MetadataId.ToGuid()); if (field == null) { throw new Exception(string.Format("Field '{0}' not found", query.MetadataId)); } var dbfield = field.GetDbField() as DbFieldLookup; if (dbfield != null) { var list = rosterConfigService.GetList(field.ListMetadataId); if (list == null) { throw new Exception(string.Format("List '{0}' not found", field.ListMetadataId)); } var parentField = list.ListMetadataFields.FirstOrDefault(item => item.InternalName == dbfield.DependentParent); if (parentField != null) { if (dbfield.DependentParentField == parentField.DataSourceKey) { whereCriteria.Add(new Tuple <string, string>(dbfield.FilterByField, query.ParentKeyValue.ToSafeString())); } else { var parentResults = BLExtensions.SourceContent(parentField.DataSource, parentField.DataSourceKey.ToSafeString(), parentField.DataSourceField, parentField.DataSourceType, new List <Tuple <string, string> > { new Tuple <string, string>(parentField.DataSourceKey.ToSafeString(), query.ParentKeyValue.ToSafeString()) }); if (!parentResults.IsEmpty()) { var firstOrDefault = parentResults.FirstOrDefault(); if (firstOrDefault != null) { var parentResult = (firstOrDefault.Item2 as IDictionary <string, object>); if (parentResult.ContainsKey(dbfield.DependentParentField)) { whereCriteria.Add(new Tuple <string, string>(dbfield.FilterByField, parentResult[dbfield.DependentParentField].ToSafeString())); } } } } } } } return(whereCriteria); }
protected void ColumnsMapperRep_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { var ddlCtrl = e.Item.FindControl("ddlTableFields"); var dd = ddlCtrl as DropDownList; if (dd == null) { return; } dd.Items.AddRange(_configService.GetList(new Guid(ddlRosterTables.SelectedValue)).ListMetadataFields.OrderBy(fld => fld.FieldName) .Select(fld => new ListItem(fld.FieldName, fld.InternalName)).ToArray()); string predefinedColumnName = (string)DataBinder.Eval(e.Item.DataItem, "DBColumnIntName"); if (!string.IsNullOrEmpty(predefinedColumnName)) { dd.SelectedValue = predefinedColumnName; dd.Enabled = (dd.SelectedIndex <= 0); } } }
public void SaveMasterAsTemplate(SaveAsTemplateQuery query) { DisableCaching(); try { // set flag IsTemplate for Master roster var _confService = new RosterConfigService(); var _dataService = new RosterDataService(); _dataService.SetAsTemplate(query.MasterId); // init filter by MasterRosterId var plannedRostersList = _confService.GetList(TableIDs.PLANNED_ROSTERS); var queryPar = new QueryParams(); var masterRosterFld = plannedRostersList.ListMetadataFields.FirstOrDefault(item => item.InternalName == FieldNames.MASTER_ROSTER_ID); queryPar.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(masterRosterFld, CompareType.Equal, ConcateOperator.And, query.MasterId, null)); // get Planned rosters by MasterRosterId var plannedRosters = _dataService.ListRosterEvents(plannedRostersList.Id, queryPar); // limit access to Planned rosters inside Template int rosterAdminGroupId = new RoleService().GetGroupIdForRole(Roster.Presentation.Constants.Role.RosterAdmins, SPContext.Current.Web); foreach (RosterEvent re in plannedRosters) { List <AccessControlItem> reRights = _confService.GetItemAccessControls(re.Id); // clear old if (reRights != null && reRights.Any()) { reRights.ForEach(ipItm => _confService.DeleteAccessControlItem(ipItm.Id)); } // add 'Edit' to RosterAdmins _confService.SaveAccessControlItem(new AccessControlItem { AccessRight = (int)AccessRight.Write, Id = Guid.NewGuid(), ItemId = re.Id, ListMetadataId = plannedRostersList.Id, TrusteeId = rosterAdminGroupId }); // add 'Read' to Everyone _confService.SaveAccessControlItem(new AccessControlItem { AccessRight = (int)AccessRight.Read, Id = Guid.NewGuid(), ItemId = re.Id, ListMetadataId = plannedRostersList.Id, TrusteeId = RoleService.ACCOUNT_ID_EVERYONE }); } } catch (Exception ex) { HandleException(ex); } }
public itemView <bool> SaveRosterEventItem(string version, string listId, int eventTypeId, Entity item) { DisableCaching(); var result = new itemView <bool>(); try { var service = new RosterDataService(); var config = new RosterConfigService(); var list = config.GetList(listId.ToGuid()); var entity = new RosterEvent { Id = item.Key.ToGuid(), EventTypeId = eventTypeId, RosterEventProperties = item.Fields.NamedToExpando() }; if (!entity.RosterEventDictionary.ContainsKey("ContentTypeId")) { entity.RosterEventDictionary.Add("ContentTypeId", 1); } if (!entity.RosterEventDictionary.ContainsKey("CreatedBy")) { entity.RosterEventDictionary.Add("CreatedBy", DbFieldUser.GetUserRosterId(SPContext.Current.Web.CurrentUser)); } if (!entity.RosterEventDictionary.ContainsKey("Created")) { entity.RosterEventDictionary.Add("Created", DateTime.Now); } if (!entity.RosterEventDictionary.ContainsKey("ModifiedBy")) { entity.RosterEventDictionary.Add("ModifiedBy", DbFieldUser.GetUserRosterId(SPContext.Current.Web.CurrentUser)); } if (!entity.RosterEventDictionary.ContainsKey("Modified")) { entity.RosterEventDictionary.Add("Modified", DateTime.Now); } if (!entity.RosterEventDictionary.ContainsKey("Id")) { entity.RosterEventDictionary.Add("Id", entity.Id); } if (!entity.RosterEventDictionary.ContainsKey("RosterEventId")) { entity.RosterEventDictionary.Add("RosterEventId", entity.Id); } var fields = list.ListMetadataFields.ToList(); fields.ForEach(_ => { if (!entity.RosterEventDictionary.ContainsKey(_.InternalName)) { if (_.ClrType == typeof(DateTime)) { entity.RosterEventDictionary.Add(_.InternalName, null); } else if (_.ClrType == typeof(Guid)) { entity.RosterEventDictionary.Add(_.InternalName, null); } else if (_.ClrType == typeof(Int32)) { entity.RosterEventDictionary.Add(_.InternalName, null); } else { entity.RosterEventDictionary.Add(_.InternalName, _.ClrType.DefaultValue()); } } }); service.SaveRosterEvent(entity, list.Id); result.item = true; } catch (Exception ex) { //HandleException(ex); result.message.message = ex.Message; result.message.messageLevel = messageLevelEnum.critical; } return(result); }
public static MigrateResult MigrateItems(MigrateQuery query) { MigrateResult result = new MigrateResult { Success = true }; try { bool needValidation = (string.IsNullOrEmpty(query.PaginInfo)); RosterConfigService _configSrv = new RosterConfigService(); SPList shpList = SPContext.Current.Web.Lists[new Guid(query.Mapping.ListId)]; ListMetadata dbList = _configSrv.GetList(new Guid(query.Mapping.TableId)); var dbList_Fields = dbList.ListMetadataFields; var _globalMapping = _configSrv.GetMapping(); // collect and validate MigrationMapping mapping = new MigrationMapping(shpList, dbList); mapping.ContentTypeMapping.AddRange(query.Mapping.ContentTypeMapping.Select(m => new MigrationCtMappingElem { ListCtId = m.ListCtId, TableCtId = m.TableCtId.ToInt() })); foreach (var mItm in query.Mapping.FieldMapping) { ListMetadataField dbField = dbList_Fields.FirstOrDefault(fld => fld.InternalName.Equals(mItm.TableColumnName)); SPField listField = shpList.Fields.GetFieldByInternalName(mItm.ListFieldName); if (needValidation && dbField.DataSourceType == (int)LookupSourceType.Table && !(listField is SPFieldUser)) { SPFieldLookup shpFieldLookup = listField as SPFieldLookup; if (shpFieldLookup == null) { throw new Exception("You cannot map non-lookup field " + mItm.ListFieldName + " to Lookup column"); } var _lookupFieldMapping = _globalMapping.FirstOrDefault(m => m.ListName == new Guid(shpFieldLookup.LookupList).ToString()); if (_lookupFieldMapping == null || _lookupFieldMapping.TableName != dbField.DataSource) { throw new Exception(listField.Title + " field error. Mapping does not exist or Lookup lists don't match!"); } } bool listField_isMultiple = (listField.Type == SPFieldType.Lookup && (listField as SPFieldLookup).AllowMultipleValues) || (listField.Type == SPFieldType.User && (listField as SPFieldLookup).AllowMultipleValues) || (listField.TypeAsString == "DualLookup" && (listField as SPFieldLookup).AllowMultipleValues); mapping.FieldMapping.Add(new MigrationMappingElem { ListField = listField, AllowMultipleValues = listField_isMultiple, TableColumn = dbField, TableDbColumn = dbField.GetDbField() }); } if (needValidation) { var repeatedShPFields = mapping.FieldMapping.GroupBy(x => x.TableColumn.InternalName).Where(gr => gr.Count() > 1).Select(gr => gr.Key); if (repeatedShPFields.Any()) { throw new Exception("Following DB columns selected more than once: " + string.Join(",", repeatedShPFields)); } } double step = Math.Round(((LIST_ROW_LIMIT * 100) / (double)mapping.List.ItemCount), 2); string _pagingInfo = Migrate(query.PaginInfo, mapping); result.PagingInfo = (string)_pagingInfo ?? string.Empty; result.CurrentIndex = (_pagingInfo == null) ? 100 : query.CurrentIndex + step; } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }