Exemple #1
0
        public async Task <IEnumerable <OrphanageDataModel.RegularData.Family> > GetFamilies(int Uid)
        {
            IList <OrphanageDataModel.RegularData.Family> familiesList = new List <OrphanageDataModel.RegularData.Family>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                var families = await _orphanageDBC.Families.AsNoTracking()
                               .Include(f => f.AlternativeAddress)
                               .Include(f => f.Bail)
                               .Include(f => f.Father)
                               .Include(f => f.Mother)
                               .Include(f => f.Orphans)
                               .Include(f => f.PrimaryAddress)
                               .Where(f => f.UserId == Uid)
                               .ToListAsync();

                foreach (var family in families)
                {
                    OrphanageDataModel.RegularData.Family familyToFill = family;
                    _selfLoopBlocking.BlockFamilySelfLoop(ref familyToFill);
                    _uriGenerator.SetFamilyUris(ref familyToFill);
                    familiesList.Add(familyToFill);
                }
            }
            return(familiesList);
        }
Exemple #2
0
        private async Task <IEnumerable <OrphanageDataModel.RegularData.Family> > prepareFamiliesList(IEnumerable <OrphanageDataModel.RegularData.Family> familiesList)
        {
            _logger.Information($"trying to prepare families list to return it");
            if (familiesList == null || familiesList.Count() == 0)
            {
                _logger.Information($"there is no family list to return, null will be returned");
                return(null);
            }
            IList <OrphanageDataModel.RegularData.Family> returnedFamiliesList = new List <OrphanageDataModel.RegularData.Family>();

            foreach (var family in familiesList)
            {
                OrphanageDataModel.RegularData.Family familyToFill = family;
                familyToFill.OrphansCount = await GetOrphansCount(family.Id);

                _selfLoopBlocking.BlockFamilySelfLoop(ref familyToFill);
                _uriGenerator.SetFamilyUris(ref familyToFill);
                returnedFamiliesList.Add(familyToFill);
            }
            _logger.Information($"{returnedFamiliesList.Count} records of families are ready and they will be returned");
            return(returnedFamiliesList);
        }
        public async Task <IEnumerable <OrphanageDataModel.RegularData.Family> > GetFamilies(int Bid)
        {
            _logger.Information($"Trying to get families those are related to the bail id {Bid}");
            IList <OrphanageDataModel.RegularData.Family> returnedFamilies = new List <OrphanageDataModel.RegularData.Family>();

            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var families = await(from orp in dbContext.Families.AsNoTracking()
                                     where orp.BailId == Bid
                                     select orp)
                               .Include(f => f.AlternativeAddress)
                               .Include(f => f.Bail)
                               .Include(f => f.Father)
                               .Include(f => f.Mother)
                               .Include(f => f.Orphans)
                               .Include(f => f.PrimaryAddress)
                               .ToListAsync();
                if (families != null && families.Count > 0)
                {
                    _logger.Information($"{families.Count} records of families already being got from the database");
                    foreach (var fam in families)
                    {
                        var famToFill = fam;
                        _selfLoopBlocking.BlockFamilySelfLoop(ref famToFill);
                        _uriGenerator.SetFamilyUris(ref famToFill);
                        fam.OrphansCount = await dbContext.Orphans.Where(o => o.FamilyId == fam.Id).AsNoTracking().CountAsync();

                        returnedFamilies.Add(famToFill);
                    }
                }
                else
                {
                    _logger.Warning("zero or null families records were being got from the database");
                }
            }
            _logger.Information($"{returnedFamilies.Count} records of families will be returned");
            return(returnedFamilies);
        }