Пример #1
0
 public void AddName(string name, string description)
 {
     if (!Names.Contains(name))
     {
         Names.Add(name);
     }
     if (!Descriptions.Contains(description))
     {
         Descriptions.Add(description);
     }
 }
Пример #2
0
        public PartFilterSpecification BuildSpecification(bool withBelongsTo = true, List <SortingInformation <Part> > orderby = null)
        {
            Query.Where(e => (string.IsNullOrEmpty(Id) || e.Id == Id));
            Query.Where(e => (string.IsNullOrEmpty(MainRecordId) || e.MainRecordId == MainRecordId));
            if (MainRecordIdIsNull)
            {
                Query.Where(e => e.MainRecordId == null);
            }
            Query.Where(e => (string.IsNullOrEmpty(RecordEditedBy) || e.RecordEditedBy == RecordEditedBy));
            Query.Where(e => (!DraftFromUpload.HasValue || e.DraftFromUpload == DraftFromUpload.Value));

            #region appgen: generated query
            if (Ids?.Count > 0)
            {
                if (_exact != null && _exact.ContainsKey("id") && _exact["id"] == 1)
                {
                    Query.Where(e => Ids.Contains(e.Id));
                }
                else
                {
                    var predicate = PredicateBuilder.False <Part>();
                    foreach (var item in Ids)
                    {
                        predicate = predicate.Or(p => p.Id.Contains(item));
                    }

                    Query.Where(predicate);
                }
            }

            if (PartNames?.Count > 0)
            {
                if (_exact != null && _exact.ContainsKey("partname") && _exact["partname"] == 1)
                {
                    Query.Where(e => PartNames.Contains(e.PartName));
                }
                else
                {
                    var predicate = PredicateBuilder.False <Part>();
                    foreach (var item in PartNames)
                    {
                        predicate = predicate.Or(p => p.PartName.Contains(item));
                    }

                    Query.Where(predicate);
                }
            }

            if (Descriptions?.Count > 0)
            {
                if (_exact != null && _exact.ContainsKey("description") && _exact["description"] == 1)
                {
                    Query.Where(e => Descriptions.Contains(e.Description));
                }
                else
                {
                    var predicate = PredicateBuilder.False <Part>();
                    foreach (var item in Descriptions)
                    {
                        predicate = predicate.Or(p => p.Description.Contains(item));
                    }

                    Query.Where(predicate);
                }
            }


            #endregion

            if (ShowDraftList > BaseEntity.DraftStatus.All)
            {
                Query.Where(e => e.IsDraftRecord == (int)ShowDraftList);
            }

            if (_skip.HasValue && _take.HasValue)
            {
                Query
                .Skip(_skip.Value)
                .Take(_take.Value);
            }

            if (orderby?.Count > 0)
            {
                foreach (var item in orderby)
                {
                    if (item.SortType == SortingType.Ascending)
                    {
                        Query.OrderBy(item.Predicate);
                    }
                    else
                    {
                        Query.OrderByDescending(item.Predicate);
                    }
                }
            }

            if (withBelongsTo)
            {
                #region appgen: belongsToList

                #endregion
            }

            return(this);
        }