Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <OrphanageDataModel.RegularData.Family> > GetFamilies(int Gid)
        {
            _logger.Information($"Trying to get families that related to the Guarantor with id {Gid}");
            IList <OrphanageDataModel.RegularData.Family> returnedFamilies = new List <OrphanageDataModel.RegularData.Family>();

            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var families = await(from family in dbContext.Families.AsNoTracking()
                                     join ba in dbContext.Bails.AsNoTracking()
                                     on family.BailId equals ba.Id
                                     where ba.GuarantorID == Gid
                                     select family)
                               .Include(f => f.AlternativeAddress)
                               .Include(f => f.Bail)
                               .Include(f => f.Father)
                               .Include(f => f.Father.Name)
                               .Include(f => f.Mother)
                               .Include(f => f.Mother.Name)
                               .Include(f => f.Mother.Address)
                               .Include(f => f.Orphans)
                               .Include(f => f.PrimaryAddress)
                               .ToListAsync();

                if (families == null || families.Count == 0)
                {
                    _logger.Information($"guarantor with id({Gid}) has no families to return, null will be returned");
                    return(null);
                }
                foreach (var family in families)
                {
                    var familyToFill = family;
                    _selfLoopBlocking.BlockFamilySelfLoop(ref familyToFill);
                    _logger.Information($"adding family with id({family.Id}) to the returned List");
                    returnedFamilies.Add(familyToFill);
                }
            }
            _logger.Information($"({returnedFamilies.Count}) records of families will be returned");
            return(returnedFamilies);
        }
Ejemplo n.º 4
0
        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);
        }