Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private static UserPickerEntity EnsureUser(UserPickerEntity entity, string listId, int listSource, string lookupKey)
        {
            if (entity.RosterLookupId != 0 && entity.IsResolved)
            {
                return(entity);
            }
            if (string.IsNullOrEmpty(entity.Key) && entity.RosterLookupId == 0)
            {
                throw new ArgumentException("To ensureUser please specify accountName OR rosterLookupId!");
            }

            UserPickerEntity dbUser = null;
            List <Tuple <string, string> > whereCriteria = new List <Tuple <string, string> >();

            if (!string.IsNullOrEmpty(entity.Key))
            {
                whereCriteria.Add(new Tuple <string, string>(FieldNames.USER_LOGIN_NAME, entity.Key));
            }
            else
            {
                whereCriteria.Add(new Tuple <string, string>(lookupKey, entity.RosterLookupId.ToString()));
            }
            var userFields = new[] { FieldNames.USER_LOGIN_NAME, FieldNames.USER_DISPLAY_NAME, FieldNames.USER_EMAIL, FieldNames.USER_SIP, FieldNames.USER_DEPARTMENT, FieldNames.USER_PRINCIPAL_TYPE };
            var users      = BLExtensions.SourceContent(listId, lookupKey, String.Join("$", userFields), listSource, whereCriteria);

            if (users == null || !users.Any())
            {
                // add new user
                int newLookupId = new RosterDataService().SaveRow(lookupKey, listId, entity.ToSyncObject());
                if (newLookupId == 0)
                {
                    throw new Exception("Cannot add user to system table");
                }
                else
                {
                    dbUser = entity;
                    dbUser.RosterLookupId = newLookupId;
                }
            }
            else
            {
                var user = users.First();
                if (entity.IsResolved)
                {
                    dbUser = entity;
                    dbUser.RosterLookupId = user.Item1;
                }
                else
                {
                    dbUser = new UserPickerEntity(user.Item1, user.Item2 as IDictionary <string, object>);
                }
            }

            return(dbUser);
        }
Ejemplo n.º 3
0
 public void PublishPlannedRoster(PublishQuery query)
 {
     DisableCaching();
     try
     {
         BLExtensions.PublishRosterEvent(query.ItemId, query.DaysAhead);
     }
     catch (Exception ex)
     {
         HandleException(ex);
     }
 }
Ejemplo n.º 4
0
        public LookupResult Lookup(LookupQuery query)
        {
            DisableCaching();
            var result = new LookupResult
            {
                Page  = query.Page,
                Items = new List <LookupResultItem>()
            };

            try
            {
                result.Page = query.Page;
                var queryTerm = query.Query.ToSafeString().ToLowerInvariant();
                var content   = BLExtensions.SourceContent(query.Source, query.Key.ToSafeString(), query.Fields,
                                                           query.ListType, GetCriteria(query))
                                .OrderBy(e => e.Item2.FirstValue())
                                .Where(i => i.Item2.ToSeparatedString().ToLowerInvariant().Contains(queryTerm));
                content.Take(PageSize).Skip(PageSize * result.Page).ToList().ForEach(item =>
                {
                    var resultItem = new LookupResultItem
                    {
                        id          = item.Item1,
                        name        = item.Item2.FirstValue(),
                        description = string.Empty,
                        property    = new List <LookupResultItemProperty>(),
                    };
                    foreach (var itemList in item.Item2)
                    {
                        resultItem.property.Add(new LookupResultItemProperty
                        {
                            Name  = string.Format("{0}_{1}", query.Source, itemList.Key),
                            Value = itemList.Value.ToSafeString()
                        });
                    }
                    ((List <LookupResultItem>)result.Items).Add(resultItem);
                });
            }
            catch (SqlException ex)
            {
                if (!ex.Message.Contains("Conversion failed"))
                {
                    HandleException(ex);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            return(result);
        }
 protected void btnSaveSync_Click(object sender, EventArgs e)
 {
     try
     {
         this.SaveMapping();
         BLExtensions.SyncList(this.ListId);
         // go back to List settings page
         this.GotoBackToSettingsPage();
     }
     catch (Exception ex)
     {
         pnlError.Controls.Add(new Label {
             Text = ex.Message, ForeColor = System.Drawing.Color.Red
         });
     }
 }
Ejemplo n.º 6
0
        public itemView <bool> PublishRoster(string version, ICollection <abstractSearch> filter)
        {
            DisableCaching();
            var result = new itemView <bool>();

            try
            {
                var id        = filter.filterTextValue("id").ToGuid();
                var daysAhead = filter.filterIntValue("daysAhead");
                BLExtensions.PublishRosterEvent(id, daysAhead);
                result.item = true;
            }
            catch (Exception ex)
            {
                //HandleException(ex);
            }
            return(result);
        }
Ejemplo n.º 7
0
        public override string GetFieldValueAsText(object dirtyValue)
        {
            if (dirtyValue == null)
            {
                return(string.Empty);
            }

            var lookupVals = BLExtensions.SourceContent(this.ListId, this.LookupKey, this.LookupField, this.ListSource, new List <Tuple <string, string> > {
                new Tuple <string, string>(this.LookupKey, dirtyValue.ToString())
            });

            if (lookupVals == null || !lookupVals.Any())
            {
                return("=deleted=");
            }
            else
            {
                var props = lookupVals.First().Item2 as IDictionary <string, object>;
                return((props == null || (this.LookupFields.Any() && !props.ContainsKey(this.LookupFields[0]))) ? string.Empty : props[this.LookupFields[0]].ToSafeString());
            }
        }
Ejemplo n.º 8
0
        public listView <Entity> DictionaryList(string version, ICollection <abstractSearch> filter, QueryDisplayParams query)
        {
            DisableCaching();
            var result = new listView <Entity>();

            try
            {
                var source    = filter.filterTextValue("source");
                var key       = filter.filterTextValue("key");
                var fields    = filter.filterTextValue("fields");
                var type      = filter.filterIntValue("type");
                var queryTerm = filter.filterTextValue("queryTerm");

                result.page = new pager <Entity>();

                var content = BLExtensions.SourceContent(source, key, fields, type)
                              .Where(i => i.Item2.ToSeparatedString().Contains(queryTerm)).ToList();
                result.total = content.Count();
                content.Take(query.currentPageSize).Skip(query.currentPageNum * query.currentPageSize).ToList().ForEach(item =>
                {
                    result.page.pageItems.Add(new Entity
                    {
                        Key    = item.Item1.ToSafeString(),
                        Name   = item.Item2.FirstValue(),
                        Fields = new List <named>()
                    });
                });
            }
            catch (Exception ex)
            {
                result.message.message      = ex.Message;
                result.message.messageLevel = messageLevelEnum.critical;
                //HandleException(ex);
            }
            return(result);
        }
Ejemplo n.º 9
0
 internal List <Tuple <int, ExpandoObject> > GetItemCollection(DbFieldLookup field)
 {
     return(field == null ? null : BLExtensions.SourceContent(field.ListId, field.LookupKey, field.LookupField, field.ListSource));
 }