Exemple #1
0
        public async Task <Anag_Master> FindByAsync(
            int?id         = null,
            string taxCode = null,
            string vatNo   = null,
            int?userId     = null,
            int?athleteId  = null,
            SearchStringKindEnum searchStringKind = SearchStringKindEnum.Contains,
            bool includeAddresses         = false,
            bool includeContacts          = false,
            bool includeDocuments         = false,
            bool includeAthletes          = false,
            bool includeAthleteNavigation = false,
            bool includeSports            = false)
        {
            var spec = Spec.Any <Anag_Master>();

            if (id.HasValue)
            {
                spec &= AnagSpecifications.ByID(id.Value);
            }
            if (!string.IsNullOrWhiteSpace(taxCode))
            {
                spec &= AnagSpecifications.ByTaxCode(search: taxCode, stringKind: searchStringKind);
            }
            if (!string.IsNullOrWhiteSpace(vatNo))
            {
                spec &= AnagSpecifications.ByVATNo(search: vatNo, stringKind: searchStringKind);
            }
            if (userId.HasValue)
            {
                spec &= AnagSpecifications.ByUserID(userId.Value);
            }
            if (athleteId.HasValue)
            {
                spec &= AnagSpecifications.ByAthleteID(athleteId.Value);
            }

            var query = _repository.GetBySpecification(spec);

            if (query.Count() != 1)
            {
                return(null);
            }

            await _repository.Load_DirectNavigation(
                angIds : query.Select(t => t.Ang_ID).ToArray(),
                addresses : includeAddresses,
                contacts : includeContacts,
                documents : includeDocuments,
                athletes : includeAthletes,
                sports : includeSports);

            if (includeAthletes && includeAthleteNavigation)
            {
                await _repository.Load_AthleteNavigation(athIds : query.Where(t => t.Athlete_Master != null).Select(t => t.Athlete_Master.Ath_ID).ToArray());
            }

            return(query.FirstOrDefault());
        }
        public void Any()
        {
            // Arrange
            var rpi         = OrderItem.RaspberryPi3ModelB();
            var orangePiOne = OrderItem.OrangePiOne();
            var msOffice    = OrderItem.MicrosoftOffice2016();

            // Act/Assert
            new[] { rpi, orangePiOne, msOffice }.Are(Spec.Any <OrderItem>()).Should().BeTrue();
        }
Exemple #3
0
        public void Any()
        {
            // Arrange
            Drink blackberryJuice = Drink.BlackberryJuice();
            Drink appleJuice      = Drink.AppleJuice();
            Drink orangeJuice     = Drink.OrangeJuice();

            // Assert
            new[] { blackberryJuice, appleJuice, orangeJuice }.Are(Spec.Any <Drink>()).Should().BeTrue();
        }
Exemple #4
0
        public async Task <IQueryable <Todo_Master> > ListAsync(short[] statuses = null, string searchString = null)
        {
            var spec = Spec.Any <Todo_Master>();

            if (statuses?.Length > 0)
            {
                spec &= TodoSpecifications.ByStatusIDs(statuses);
            }
            if (!string.IsNullOrWhiteSpace(searchString))
            {
                spec &= TodoSpecifications.BySearchString(searchString);
            }
            var query = _repository.GetBySpecification(spec);

            return(await Task.FromResult(query));
        }
Exemple #5
0
        public async Task <List <ComuneItalianoCsv> > GetFromCsvByAsync(
            string nazione           = null,
            string comune            = null,
            string comuneInizio      = null,
            string comuneContiene    = null,
            string comuneInt         = null,
            string comuneIntInizio   = null,
            string comuneIntContiene = null,
            string codiceCatastale   = null,
            bool?archiviato          = null)
        {
            var spec = Spec.Any <ComuneItalianoCsv>();

            if (!string.IsNullOrWhiteSpace(nazione))
            {
                nazione = nazione.Replace(" ", "");
                spec   &= new Spec <ComuneItalianoCsv>(t => t.NAZIONE.ToUpper() == nazione.ToUpper());
            }
            if (!string.IsNullOrWhiteSpace(comune) || !string.IsNullOrWhiteSpace(comuneInt))
            {
                comune    = comune.Replace(" ", "").ToUpper();
                comuneInt = comuneInt.Replace(" ", "").ToUpper();
                spec     &= new Spec <ComuneItalianoCsv>(t => t.COMUNE.ToUpper().Equals(comune) || t.COMUNE_INT.ToUpper().Equals(comuneInt));
            }
            if (!string.IsNullOrWhiteSpace(comuneInizio) || !string.IsNullOrWhiteSpace(comuneIntInizio))
            {
                comuneInizio    = comuneInizio.Replace(" ", "").ToUpper();
                comuneIntInizio = comuneIntInizio.Replace(" ", "").ToUpper();
                spec           &= new Spec <ComuneItalianoCsv>(t => t.COMUNE.ToUpper().StartsWith(comuneInizio) || t.COMUNE_INT.ToUpper().StartsWith(comuneIntInizio));
            }
            if (!string.IsNullOrWhiteSpace(comuneContiene) || !string.IsNullOrWhiteSpace(comuneIntContiene))
            {
                comuneContiene    = comuneContiene.Replace(" ", "").ToUpper();
                comuneIntContiene = comuneIntContiene.Replace(" ", "").ToUpper();
                spec &= new Spec <ComuneItalianoCsv>(t => t.COMUNE.ToUpper().Contains(comuneContiene) || t.COMUNE_INT.ToUpper().Contains(comuneIntContiene));
            }
            if (!string.IsNullOrWhiteSpace(codiceCatastale))
            {
                codiceCatastale = codiceCatastale.Replace(" ", "");
                spec           &= new Spec <ComuneItalianoCsv>(t => t.CODICE_CATASTALE.ToUpper() == codiceCatastale.ToUpper());
            }
            if (archiviato != null)
            {
                spec &= new Spec <ComuneItalianoCsv>(t => t.ARCHIVIATO == archiviato);
            }
            return(await Task.FromResult(ListaComuniCsv.AsQueryable().Where(spec.Expression).ToList()));
        }
Exemple #6
0
        public async Task <IQueryable <Anag_Master> > ListAsync(
            AnagFilters filters,
            SearchStringKindEnum searchStringKind = SearchStringKindEnum.Contains,
            bool includeAddresses         = false,
            bool includeContacts          = false,
            bool includeDocuments         = false,
            bool includeAthletes          = false,
            bool includeAthleteNavigation = false,
            bool includeSports            = false)
        {
            var spec = Spec.Any <Anag_Master>();

            if (filters?.Roles?.Count() > 0)
            {
                spec &= AnagSpecifications.ByRoleIDs(filters.Roles.ToArray());
            }
            if (filters?.CorporateRoles?.Count() > 0)
            {
                spec &= AnagSpecifications.ByCorporateRoleIDs(filters.CorporateRoles.ToArray());
            }
            if (!string.IsNullOrWhiteSpace(filters?.SearchString))
            {
                ASpec <Anag_Master> searchSpec = AnagSpecifications.ByCompleteName(filters.SearchString);
                searchSpec |= AnagSpecifications.ByTaxCode(filters.SearchString);
                searchSpec |= AnagSpecifications.ByVATNo(filters.SearchString);
                spec       &= (searchSpec);
            }

            var query = _repository.GetBySpecification(spec);

            await _repository.Load_DirectNavigation(
                angIds : query.Select(t => t.Ang_ID).ToArray(),
                addresses : includeAddresses,
                contacts : includeContacts,
                documents : includeDocuments,
                athletes : includeAthletes,
                sports : includeSports);

            if (includeAthletes && includeAthleteNavigation)
            {
                await _repository.Load_AthleteNavigation(athIds : query.Where(t => t.Athlete_Master != null).Select(t => t.Athlete_Master.Ath_ID).ToArray());
            }

            return(query);
        }
Exemple #7
0
        public async Task <List <ComuneItalianoJson> > GetFromJsonByAsync(
            string CAP             = null,
            string codiceCatastale = null)
        {
            var spec = Spec.Any <ComuneItalianoJson>();

            if (!string.IsNullOrWhiteSpace(CAP))
            {
                CAP   = CAP.Replace(" ", "");
                spec &= new Spec <ComuneItalianoJson>(t => t.CAP.Any(i => i.ToUpper() == CAP.ToUpper()));
            }
            if (!string.IsNullOrWhiteSpace(codiceCatastale))
            {
                codiceCatastale = codiceCatastale.Replace(" ", "");
                spec           &= new Spec <ComuneItalianoJson>(t => t.CodiceCatastale.ToUpper() == codiceCatastale.ToUpper());
            }
            return(await Task.FromResult(ListaComuniJson.AsQueryable().Where(spec.Expression).ToList()));
        }
Exemple #8
0
        public EntityClass(
            EntityClass parent,
            entitySpec entitySpec,
            Type type,
            LinkedFieldInfo fieldInfo,
            Action <string> log,
            bool throwOnCircularReference)
            : base(entitySpec)
        {
            log?.Invoke(
                $"EntityClass ctor: {entitySpec.name}/{entitySpec.fields?.Count ?? 0} - {type?.Name} - {fieldInfo?.FieldType} - {fieldInfo?.IEnumerable?.Name}");

            TableName = parent != null && Spec.externalname == null
                ? string.Join("_", parent.TableName, ExternalName)
                : ExternalName;

            FieldInfo = fieldInfo;
            FieldType = fieldInfo?.FieldType;

            if (!Spec.Any() || isStarExpansionAndNoRealSubProperties(type))
            {
                // not sure if this should be allowed...
                Fields.Add(new EntitySolitaire(type));
            }

            breakDownSubEntities(type, log, throwOnCircularReference);

            // move the nosave fields to always be at the end of the list
            var noSaveFields = Fields.Where(_ => _.NoSave).ToList();

            Fields.RemoveAll(_ => _.NoSave);
            SaveableFieldCount = Fields.Count;
            Fields.AddRange(noSaveFields);

            // this is temporary - to be able to serialze a contract with "*" since it was digging up so much garbage...
            // need to investigae each "garbage" occurrence and handle it more elegantly
            Fields.RemoveAll(_ => _ is EntityPlainField && SqlHelpers.Field2Sql(_.NameAndType.Name, _.NameAndType.Type, false, 0, true) == null);
            Lists.RemoveAll(_ => !_.Fields.Any() && !_.Lists.Any());

            if (Fields.Count(_ => _.Spec.primarykey) > 1)
            {
                throw new Exception("There may be no more than one primary key field");
            }
            PrimaryKeyIndex = Fields.FindIndex(_ => _.Spec.primarykey);

            EffectiveFieldCount = Fields.Count + 1;
            for (var fi = 0; fi < Fields.Count; fi++)
            {
                Fields[fi].ParentInitialized(this, fi);
            }
            for (var li = 0; li < Lists.Count; li++)
            {
                Lists[li].ParentInitialized(this, li);
            }

            for (var i = 0; i < Fields.Count; i++)
            {
                Fields[i].ResultSetIndex = i;
            }

            var fieldsThenFormulas = Fields.Where(_ => !(_ is EntityAggregation)).ToList();

            SortWithFormulasLast(fieldsThenFormulas);
            _fieldsThenNonAggregatedFormulas = fieldsThenFormulas.Where(_ => !_.IsBasedOnAggregation).ToArray();
            _aggregatedFormulas = fieldsThenFormulas.Where(_ => _.IsBasedOnAggregation).ToArray();

            if (!string.IsNullOrEmpty(Spec.where))
            {
                _whereClause = new WhereClause(Spec.where, Fields, _fieldsThenNonAggregatedFormulas);
            }

            if (PrimaryKeyIndex >= 0 && Fields[PrimaryKeyIndex].IsBasedOnAggregation)
            {
                throw new Exception($"The primary key must not be based on an aggregation (table '{TableName}')");
            }
        }