Пример #1
0
        public async Task <OrphanageDataModel.FinancialData.Bail> GetBailDC(int Bid)
        {
            _logger.Information($"Trying to get Bail with id {Bid}");
            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var bail = await dbContext.Bails.AsNoTracking()
                           .Include(b => b.Account)
                           .Include(b => b.Guarantor)
                           .Include(b => b.Guarantor.Name)
                           .FirstOrDefaultAsync(b => b.Id == Bid);

                if (bail == null)
                {
                    _logger.Warning($"Bail with id{Bid} cannot be found null is returned");
                    return(null);
                }
                bail.OrphansCount = await GetOrphansCount(Bid);

                bail.FamiliesCount = await GetFamiliesCount(Bid);

                _selfLoopBlocking.BlockBailSelfLoop(ref bail);
                _logger.Information($"returned Bail with id {Bid}");
                return(bail);
            }
        }
Пример #2
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Caregiver> > GetCaregivers(int Uid, int pageSize, int pageNum)
        {
            IList <OrphanageDataModel.Persons.Caregiver> caregiversList = new List <OrphanageDataModel.Persons.Caregiver>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped     = pageSize * pageNum;
                int caregiversCount = await _orphanageDBC.Caregivers.AsNoTracking().CountAsync();

                if (caregiversCount < totalSkiped)
                {
                    totalSkiped = caregiversCount - pageSize;
                }
                var caregivers = await _orphanageDBC.Caregivers.AsNoTracking()
                                 .OrderBy(c => c.Id).Skip(() => totalSkiped).Take(() => pageSize)
                                 .Include(c => c.Address)
                                 .Include(c => c.Name)
                                 .Include(c => c.Orphans)
                                 .Where(c => c.UserId == Uid)
                                 .ToListAsync();

                foreach (var caregiver in caregivers)
                {
                    OrphanageDataModel.Persons.Caregiver caregiverToFill = caregiver;
                    _selfLoopBlocking.BlockCaregiverSelfLoop(ref caregiverToFill);
                    _uriGenerator.SetCaregiverUris(ref caregiverToFill);
                    caregiversList.Add(caregiverToFill);
                }
            }
            return(caregiversList);
        }
Пример #3
0
        public async Task <OrphanageDataModel.Persons.Caregiver> GetCaregiver(int Cid)
        {
            _logger.Information($"Trying to get caregiver with id {Cid}");
            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var caregiver = await dbContext.Caregivers.AsNoTracking()
                                .Include(c => c.Address)
                                .Include(c => c.Name)
                                .Include(c => c.Orphans)
                                .Include(c => c.ActingUser.Name)
                                .FirstOrDefaultAsync(c => c.Id == Cid);

                if (caregiver == null)
                {
                    _logger.Warning($"caregiver with id{Cid} cannot be found null is returned");
                    return(null);
                }
                if (caregiver == null)
                {
                    throw new ObjectNotFoundException();
                }
                _selfLoopBlocking.BlockCaregiverSelfLoop(ref caregiver);
                _uriGenerator.SetCaregiverUris(ref caregiver);
                caregiver.Address = caregiver.Address.Clean();
                _logger.Information($"returned caregiver with id {Cid}");
                return(caregiver);
            }
        }
Пример #4
0
        public async Task <IEnumerable <OrphanageDataModel.FinancialData.Bail> > GetBails(int pageSize, int pageNum)
        {
            _logger.Information($"Trying to get Bails with pageSize {pageSize} and pageNumber {pageNum}");
            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped = pageSize * pageNum;
                int bailsCount  = 0;

                bailsCount = await _orphanageDBC.Bails.AsNoTracking().CountAsync();

                if (bailsCount < totalSkiped)
                {
                    _logger.Warning($"Total skipped bails({totalSkiped}) are more than the count of all bails ({bailsCount})");
                    totalSkiped = bailsCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    _logger.Warning($"Total skipped bails({totalSkiped}) are less than zero");
                    totalSkiped = 0;
                }
                var bails = await _orphanageDBC.Bails.AsNoTracking()
                            .OrderBy(c => c.Id).Skip(() => totalSkiped).Take(() => pageSize)
                            .Include(b => b.Account)
                            .Include(b => b.Guarantor)
                            .Include(b => b.Guarantor.Name)
                            .ToListAsync();

                return(await prepareBailsList(bails));
            }
        }
Пример #5
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Guarantor> > GetGuarantors(int Uid, int pageSize, int pageNum)
        {
            IList <OrphanageDataModel.Persons.Guarantor> guarantorsList = new List <OrphanageDataModel.Persons.Guarantor>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped     = pageSize * pageNum;
                int guarantorsCount = await _orphanageDBC.Guarantors.AsNoTracking().CountAsync();

                if (guarantorsCount < totalSkiped)
                {
                    totalSkiped = guarantorsCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    totalSkiped = 0;
                }
                var guarantors = await _orphanageDBC.Guarantors.AsNoTracking()
                                 .OrderBy(c => c.Id).Skip(() => totalSkiped).Take(() => pageSize)
                                 .Include(g => g.Address)
                                 .Include(c => c.Name)
                                 .Include(g => g.Account)
                                 .Where(g => g.UserId == Uid)
                                 .ToListAsync();

                foreach (var guarantor in guarantors)
                {
                    OrphanageDataModel.Persons.Guarantor guarantorToFill = guarantor;
                    _selfLoopBlocking.BlockGuarantorSelfLoop(ref guarantorToFill);
                    guarantorsList.Add(guarantorToFill);
                }
            }
            return(guarantorsList);
        }
Пример #6
0
        public async Task <bool> DeleteHealth(int healthId, OrphanageDbCNoBinary orphanageDBC)
        {
            _logger.Information($"trying to delete Health with id({healthId})");
            var healthTodelete = await orphanageDBC.Healthies.FirstOrDefaultAsync(a => a.Id == healthId);

            if (healthTodelete == null)
            {
                _logger.Error($"Health with id({healthId}) cannot be found, false will be returned");
                return(false);
            }
            if (healthTodelete.Orphans == null || healthTodelete.Orphans.Count == 0)
            {
                orphanageDBC.Healthies.Remove(healthTodelete);
                var ret = await orphanageDBC.SaveChangesAsync() > 0 ? true : false;

                if (ret)
                {
                    _logger.Information($"Health with id({healthId}) has been deleted, true will be returned");
                }
                else
                {
                    _logger.Warning($"Health with id({healthId}) has been not deleted, false will be returned");
                }
                return(ret);
            }
            else
            {
                _logger.Warning($"Health with id({healthId}) has been not deleted, it has foreign key on orphans, false will be returned");
                return(false);
            }
        }
Пример #7
0
        public async Task <bool> DeleteStudy(int studyId, OrphanageDbCNoBinary orphanageDBC)
        {
            _logger.Information($"trying to delete study with id({studyId})");
            var studyTodelete = await orphanageDBC.Studies.Include(s => s.Orphans).FirstOrDefaultAsync(a => a.Id == studyId);

            if (studyTodelete == null)
            {
                _logger.Error($"study with id({studyId}) cannot be found, false will be returned");
                return(false);
            }
            if (studyTodelete.Orphans == null || studyTodelete.Orphans.Count == 0)
            {
                orphanageDBC.Studies.Remove(studyTodelete);
                var ret = await orphanageDBC.SaveChangesAsync() > 0 ? true : false;

                if (ret)
                {
                    _logger.Information($"study with id({studyId}) has been deleted, true will be returned");
                }
                else
                {
                    _logger.Warning($"study with id({studyId}) has been not deleted, false will be returned");
                }
                return(ret);
            }
            else
            {
                _logger.Warning($"study with id({studyId}) has been not deleted, it has foreign key on orphans, false will be returned");
                return(false);
            }
        }
Пример #8
0
        public async Task <IEnumerable <OrphanageDataModel.RegularData.Family> > GetFamilies(int pageSize, int pageNum)
        {
            _logger.Information($"trying to get families by paging, pageSize({pageSize}) pageNumber({pageNum})");
            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped = pageSize * pageNum;
                _logger.Information($"total page to skip equals ({totalSkiped})");
                int FamiliesCount = await GetFamiliesCount();

                if (FamiliesCount < totalSkiped)
                {
                    totalSkiped = FamiliesCount - pageSize;
                    _logger.Information($"families count is smaller than total skipped families, reset total skipped families to ({totalSkiped})");
                }
                if (totalSkiped < 0)
                {
                    totalSkiped = 0;
                    _logger.Information($"total skipped families is less than zero, reset total skipped families to ({totalSkiped})");
                }
                var families = await _orphanageDBC.Families.AsNoTracking()
                               .OrderBy(o => o.Id).Skip(() => totalSkiped).Take(() => pageSize)
                               .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();

                return(await prepareFamiliesList(families));
            }
        }
Пример #9
0
        public async Task <OrphanageDataModel.RegularData.Family> GetFamily(int FamId)
        {
            _logger.Information($"trying to get family with id ({FamId})");
            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                var family = await _orphanageDBC.Families.AsNoTracking()
                             .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)
                             .FirstOrDefaultAsync(f => f.Id == FamId);

                if (family == null)
                {
                    _logger.Error($"family with id ({FamId}) has not been found, ObjectNotFoundException will be thrown");
                    return(null);
                }

                OrphanageDataModel.RegularData.Family familyToFill = family;
                familyToFill.OrphansCount = await GetOrphansCount(family.Id);

                _selfLoopBlocking.BlockFamilySelfLoop(ref familyToFill);
                _uriGenerator.SetFamilyUris(ref familyToFill);
                _logger.Information($"family object with id({FamId}) will be returned");
                return(familyToFill);
            }
        }
Пример #10
0
        public async Task <int> SaveAddress(Address address, OrphanageDbCNoBinary orphanageDBC)
        {
            _logger.Information($"trying to save address with id({address.Id})");
            var orginalAddress = await orphanageDBC.Addresses.Where(a => a.Id == address.Id).FirstOrDefaultAsync();

            if (orginalAddress == null)
            {
                _logger.Error($"address with id({address.Id}) cannot be found, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            var cleanAddress = address.Clean();

            orginalAddress.Note      = cleanAddress.Note;
            orginalAddress.CellPhone = cleanAddress.CellPhone;
            orginalAddress.City      = cleanAddress.City;
            orginalAddress.Country   = cleanAddress.Country;
            orginalAddress.Facebook  = cleanAddress.Facebook;
            orginalAddress.HomePhone = cleanAddress.HomePhone;
            orginalAddress.Street    = cleanAddress.Street;
            orginalAddress.Town      = cleanAddress.Town;
            orginalAddress.Twitter   = cleanAddress.Twitter;
            orginalAddress.WorkPhone = cleanAddress.WorkPhone;
            orginalAddress.Fax       = cleanAddress.Fax;
            orginalAddress.Email     = cleanAddress.Email;
            var ret = await orphanageDBC.SaveChangesAsync();

            _logger.Information($"({ret}) changes has been made to address with id({address.Id})");
            return(ret);
        }
Пример #11
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.User> > GetUsers(int pageSize, int pageNum)
        {
            IList <OrphanageDataModel.Persons.User> usersList = new List <OrphanageDataModel.Persons.User>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped = pageSize * pageNum;
                int usersCount  = await _orphanageDBC.Users.AsNoTracking().CountAsync();

                if (usersCount < totalSkiped)
                {
                    totalSkiped = usersCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    totalSkiped = 0;
                }
                var users = await _orphanageDBC.Users.AsNoTracking()
                            .OrderBy(o => o.Id).Skip(() => totalSkiped).Take(() => pageSize)
                            .Include(u => u.Name)
                            .Include(u => u.Address)
                            .ToListAsync();

                foreach (var user in users)
                {
                    var userTofill = user;
                    _selfLoopBlocking.BlockUserSelfLoop(ref userTofill);
                    usersList.Add(userTofill);
                }
            }
            return(usersList);
        }
Пример #12
0
        public async Task <bool> DeleteMother(int Mid, OrphanageDbCNoBinary orphanageDb)
        {
            if (Mid == 0)
            {
                throw new NullReferenceException();
            }

            var mother = await orphanageDb.Mothers.Where(m => m.Id == Mid)
                         .Include(m => m.Name)
                         .Include(m => m.Address)
                         .Include(m => m.Families)
                         .FirstOrDefaultAsync();

            if (mother.Families.Count > 0)
            {
                //the mother has another family
                return(true);
            }
            var motherName    = mother.Name;
            var motherAddress = mother.Address;

            orphanageDb.Mothers.Remove(mother);
            orphanageDb.Names.Remove(motherName);
            orphanageDb.Addresses.Remove(motherAddress);
            if (await orphanageDb.SaveChangesAsync() > 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #13
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Orphan> > GetOrphans(int Mid)
        {
            IList <OrphanageDataModel.Persons.Orphan> returnedOrphans = new List <OrphanageDataModel.Persons.Orphan>();

            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var orphans = await(from orp in dbContext.Orphans.AsNoTracking()
                                    join fam in dbContext.Families.AsNoTracking() on orp.Family.MotherId equals fam.MotherId
                                    where orp.Family.MotherId == Mid
                                    select orp)
                              .Include(o => o.Education)
                              .Include(o => o.Name)
                              .Include(o => o.Caregiver.Name)
                              .Include(o => o.Caregiver.Address)
                              .Include(o => o.Family.Father.Name)
                              .Include(o => o.Family.Mother.Name)
                              .Include(o => o.Family.Mother.Address)
                              .Include(o => o.Family.PrimaryAddress)
                              .Include(o => o.Family.AlternativeAddress)
                              .Include(o => o.Guarantor.Name)
                              .Include(o => o.Bail)
                              .Include(o => o.HealthStatus)
                              .ToListAsync();
                foreach (var orphan in orphans)
                {
                    var orpToFill = orphan;
                    _selfLoopBlocking.BlockOrphanSelfLoop(ref orpToFill);
                    _uriGenerator.SetOrphanUris(ref orpToFill);
                    returnedOrphans.Add(orpToFill);
                }
            }
            return(returnedOrphans);
        }
Пример #14
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Guarantor> > GetGuarantors(int pageSize, int pageNum)
        {
            _logger.Information($"Trying to get Guarantors with pageSize {pageSize} and pageNumber {pageNum}");

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped = pageSize * pageNum;

                int guarantorsCount = await _orphanageDBC.Guarantors.AsNoTracking().CountAsync();

                if (guarantorsCount < totalSkiped)
                {
                    _logger.Warning($"Total skipped guarantors({totalSkiped}) are more than the count of all guarantors ({guarantorsCount})");
                    totalSkiped = guarantorsCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    _logger.Warning($"Total skipped guarantors({totalSkiped}) are less than zero");
                    totalSkiped = 0;
                }
                var guarantors = await _orphanageDBC.Guarantors.AsNoTracking()
                                 .OrderBy(c => c.Id).Skip(() => totalSkiped).Take(() => pageSize)
                                 .Include(g => g.Address)
                                 .Include(c => c.Name)
                                 .Include(g => g.Account)
                                 .ToListAsync();

                return(prepareGuarantorsList(guarantors));
            }
        }
Пример #15
0
        public async Task <OrphanageDataModel.Persons.Guarantor> GetGuarantor(int Gid)
        {
            _logger.Information($"Trying to get Guarantor with id {Gid}");
            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var guarantor = await dbContext.Guarantors.AsNoTracking()
                                .Include(g => g.Address)
                                .Include(c => c.Name)
                                .Include(g => g.Account)
                                .FirstOrDefaultAsync(c => c.Id == Gid);

                if (guarantor == null)
                {
                    _logger.Warning($"Guarantor with id{Gid} cannot be found null is returned");
                    return(null);
                }
                _selfLoopBlocking.BlockGuarantorSelfLoop(ref guarantor);
                if (guarantor.Address != null)
                {
                    guarantor.Address = guarantor.Address.Clean();
                }
                _logger.Information($"returned Guarantor with id {Gid}");
                return(guarantor);
            }
        }
Пример #16
0
        public async Task <IEnumerable <OrphanageDataModel.FinancialData.Bail> > GetBails(int Gid)
        {
            _logger.Information($"Trying to get Bails that related to the Guarantor with id {Gid}");
            IList <OrphanageDataModel.FinancialData.Bail> returnedBails = new List <OrphanageDataModel.FinancialData.Bail>();

            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var bails = await(from bail in dbContext.Bails.AsNoTracking()
                                  where bail.GuarantorID == Gid
                                  select bail)
                            .Include(b => b.Account)
                            .ToListAsync();

                if (bails == null || bails.Count == 0)
                {
                    _logger.Information($"guarantor with id({Gid}) has no bails to return, null will be returned");
                    return(null);
                }
                foreach (var bail in bails)
                {
                    var bailToFill = bail;
                    _selfLoopBlocking.BlockBailSelfLoop(ref bailToFill);
                    _logger.Information($"adding bail with id({bail.Id}) to the returned List");
                    returnedBails.Add(bailToFill);
                }
            }
            _logger.Information($"({returnedBails.Count}) records of bails will be returned");
            return(returnedBails);
        }
Пример #17
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Mother> > GetMothers(int Uid, int pageSize, int pageNum)
        {
            IList <OrphanageDataModel.Persons.Mother> mothersList = new List <OrphanageDataModel.Persons.Mother>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped  = pageSize * pageNum;
                int MothersCount = await _orphanageDBC.Mothers.AsNoTracking().CountAsync();

                if (MothersCount < totalSkiped)
                {
                    totalSkiped = MothersCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    totalSkiped = 0;
                }
                var mothers = await _orphanageDBC.Mothers.AsNoTracking()
                              .OrderBy(o => o.Id).Skip(() => totalSkiped).Take(() => pageSize)
                              .Include(f => f.Families)
                              .Include(f => f.Name)
                              .Where(m => m.UserId == Uid)
                              .ToListAsync();

                foreach (var mother in mothers)
                {
                    OrphanageDataModel.Persons.Mother motherToFill = mother;
                    MotherDbService.setMotherEntities(ref motherToFill, _orphanageDBC);
                    _selfLoopBlocking.BlockMotherSelfLoop(ref motherToFill);
                    _uriGenerator.SetMotherUris(ref motherToFill);
                    mothersList.Add(motherToFill);
                }
            }
            return(mothersList);
        }
Пример #18
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Orphan> > GetOrphans(int Fid)
        {
            _logger.Information($"Trying to get all orphan those related to the fathers with id ({Fid})");
            IList <OrphanageDataModel.Persons.Orphan> returnedOrphans = new List <OrphanageDataModel.Persons.Orphan>();

            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var orphans = await(from orp in dbContext.Orphans.AsNoTracking()
                                    join fath in dbContext.Families.AsNoTracking() on orp.Family.FatherId equals fath.FatherId
                                    where orp.Family.FatherId == Fid
                                    select orp)
                              .Include(o => o.Education)
                              .Include(o => o.Name)
                              .Include(o => o.Caregiver.Name)
                              .Include(o => o.Caregiver.Address)
                              .Include(o => o.Family.Father.Name)
                              .Include(o => o.Family.Mother.Name)
                              .Include(o => o.Family.PrimaryAddress)
                              .Include(o => o.Family.AlternativeAddress)
                              .Include(o => o.Guarantor.Name)
                              .Include(o => o.Bail)
                              .Include(o => o.HealthStatus)
                              .ToListAsync();
                foreach (var orphan in orphans)
                {
                    var orpToFill = orphan;
                    _selfLoopBlocking.BlockOrphanSelfLoop(ref orpToFill);
                    _uriGenerator.SetOrphanUris(ref orpToFill);
                    returnedOrphans.Add(orpToFill);
                }
            }
            _logger.Information($"father with id({Fid}) has {returnedOrphans.Count} related orphans.");
            return(returnedOrphans);
        }
Пример #19
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Orphan> > GetOrphans(int Uid)
        {
            IList <OrphanageDataModel.Persons.Orphan> orphansList = new List <OrphanageDataModel.Persons.Orphan>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                var orphans = await _orphanageDBC.Orphans.AsNoTracking()
                              .Include(o => o.Name)
                              .Include(o => o.Caregiver.Name)
                              .Include(o => o.Caregiver.Address)
                              .Include(o => o.Family.Father.Name)
                              .Include(o => o.Family.Mother.Name)
                              .Include(o => o.Family.PrimaryAddress)
                              .Include(o => o.Family.AlternativeAddress)
                              .Include(o => o.Guarantor.Name)
                              .Where(o => o.UserId == Uid)
                              .ToListAsync();

                foreach (var orphan in orphans)
                {
                    var orphanTofill = orphan;
                    _selfLoopBlocking.BlockOrphanSelfLoop(ref orphanTofill);
                    _uriGenerator.SetOrphanUris(ref orphanTofill);
                    orphansList.Add(orphanTofill);
                }
            }
            return(orphansList);
        }
Пример #20
0
        public async Task <OrphanageDataModel.Persons.Father> GetFather(int Fid)
        {
            _logger.Information($"trying to get father with Id ({Fid})");
            using (var dbContext = new OrphanageDbCNoBinary())
            {
                var father = await dbContext.Fathers.AsNoTracking()
                             .Include(f => f.Families)
                             .Include(f => f.Name)
                             .FirstOrDefaultAsync(f => f.Id == Fid);

                if (father == null)
                {
                    _logger.Warning($"Father with id{Fid} cannot be found null is returned");
                    return(null);
                }
                _selfLoopBlocking.BlockFatherSelfLoop(ref father);
                setFatherEntities(ref father, dbContext);
                _uriGenerator.SetFatherUris(ref father);
                father.OrphansCount = await GetOrphansCount(Fid, dbContext);

                father.WifeName = await(GetWifeName(father));
                _logger.Information($"returned Father with id {Fid}");
                return(father);
            }
        }
Пример #21
0
        public async Task <OrphanageDataModel.Persons.User> AuthenticateUser(string userName, string password)
        {
            _logger.Information($"trying to authenticate user, username={userName}");
            if (userName == null || userName.Length == 0)
            {
                _logger.Error("username is empty, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            if (password == null || password.Length == 0)
            {
                _logger.Error("password is empty, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            using (var orphanageDBC = new OrphanageDbCNoBinary())
            {
                var user = await orphanageDBC.Users.FirstOrDefaultAsync(u => u.UserName == userName);

                if (user == null)
                {
                    _logger.Warning($"username is not existed, AuthenticationException will be thrown");
                    throw new AuthenticationException($"username={userName}");
                }
                if (!_passwordHasher.Verify(password, user.Password))
                {
                    _logger.Warning($"password doesn't match, AuthenticationException will be thrown");
                    throw new AuthenticationException($"wrong password");
                }
                _logger.Information($"username={userName} is successfully authenticated");
                return(user);
            }
        }
Пример #22
0
        public async Task <IEnumerable <OrphanageDataModel.Persons.Father> > GetFathers(IList <int> fathersIds)
        {
            _logger.Information($"trying to get fathers with the given Id list");
            if (fathersIds == null || fathersIds.Count() == 0)
            {
                _logger.Information($"the given Id list is null or empty, null will be returned");
                return(null);
            }
            IList <OrphanageDataModel.Persons.Father> fathersList = new List <OrphanageDataModel.Persons.Father>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                var fathers = await _orphanageDBC.Fathers.AsNoTracking()
                              .Where(m => fathersIds.Contains(m.Id))
                              .Include(f => f.Families)
                              .Include(f => f.Name)
                              .ToListAsync();

                foreach (var father in fathers)
                {
                    OrphanageDataModel.Persons.Father fatherToFill = father;
                    setFatherEntities(ref fatherToFill, _orphanageDBC);
                    _selfLoopBlocking.BlockFatherSelfLoop(ref fatherToFill);
                    _uriGenerator.SetFatherUris(ref fatherToFill);
                    father.OrphansCount = await GetOrphansCount(father.Id, _orphanageDBC);

                    father.WifeName = await(GetWifeName(father));
                    fathersList.Add(fatherToFill);
                }
            }
            _logger.Information($"{fathersList.Count} records of fathers will be returned");
            return(fathersList);
        }
Пример #23
0
        public async Task <IEnumerable <OrphanageDataModel.RegularData.Family> > GetFamilies(IEnumerable <int> familiesIds)
        {
            _logger.Information($"trying to get families with the given Id list");
            if (familiesIds == null || familiesIds.Count() == 0)
            {
                _logger.Information($"the given Id list is null or empty, null will be returned");
                return(null);
            }
            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                var families = await _orphanageDBC.Families.AsNoTracking()
                               .Where(f => familiesIds.Contains(f.Id))
                               .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();

                return(await prepareFamiliesList(families));
            }
        }
Пример #24
0
        public async Task <IEnumerable <OrphanageDataModel.FinancialData.Bail> > GetBails(int Uid, int pageSize, int pageNum)
        {
            IList <OrphanageDataModel.FinancialData.Bail> bailsList = new List <OrphanageDataModel.FinancialData.Bail>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped = pageSize * pageNum;
                int bailsCount  = await _orphanageDBC.Bails.AsNoTracking().CountAsync();

                if (bailsCount < totalSkiped)
                {
                    totalSkiped = bailsCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    totalSkiped = 0;
                }
                var bails = await _orphanageDBC.Bails.AsNoTracking()
                            .OrderBy(c => c.Id).Skip(() => totalSkiped).Take(() => pageSize)
                            .Include(b => b.Account)
                            .Include(b => b.Guarantor)
                            .Where(b => b.UserId == Uid)
                            .ToListAsync();

                foreach (var bail in bails)
                {
                    OrphanageDataModel.FinancialData.Bail bailsToFill = bail;
                    _selfLoopBlocking.BlockBailSelfLoop(ref bailsToFill);
                    bailsList.Add(bailsToFill);
                }
            }
            return(bailsList);
        }
Пример #25
0
        public async Task <IEnumerable <OrphanageDataModel.FinancialData.Account> > GetAccounts(int pageSize, int pageNum)
        {
            IList <OrphanageDataModel.FinancialData.Account> accountsList = new List <OrphanageDataModel.FinancialData.Account>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped   = pageSize * pageNum;
                int accountsCount = await _orphanageDBC.Bails.AsNoTracking().CountAsync();

                if (accountsCount < totalSkiped)
                {
                    totalSkiped = accountsCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    totalSkiped = 0;
                }
                var accounts = await _orphanageDBC.Accounts.AsNoTracking()
                               .OrderBy(c => c.Id).Skip(() => totalSkiped).Take(() => pageSize)
                               .Include(a => a.Bails)
                               .Include(b => b.Guarantors)
                               .ToListAsync();

                foreach (var account in accounts)
                {
                    OrphanageDataModel.FinancialData.Account accountToFill = account;
                    _selfLoopBlocking.BlockAccountSelfLoop(ref accountToFill);
                    accountsList.Add(accountToFill);
                }
            }
            return(accountsList);
        }
Пример #26
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);
        }
Пример #27
0
        public async Task <bool> SaveBail(OrphanageDataModel.FinancialData.Bail bailToSave)
        {
            _logger.Information($"Trying to save Bail");
            if (bailToSave == null)
            {
                _logger.Error($"the parameter object bailToSave is null, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            if (bailToSave.AccountID <= 0)
            {
                _logger.Error($"the AccountId of the parameter object bailToSave equals {bailToSave.AccountID}, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            if (bailToSave.GuarantorID <= 0)
            {
                _logger.Error($"the GuarantorID of the parameter object bailToSave equals {bailToSave.GuarantorID}, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            using (OrphanageDbCNoBinary orphanageDc = new OrphanageDbCNoBinary())
            {
                int ret = 0;
                orphanageDc.Configuration.LazyLoadingEnabled       = true;
                orphanageDc.Configuration.ProxyCreationEnabled     = true;
                orphanageDc.Configuration.AutoDetectChangesEnabled = true;

                var orginalBail = await orphanageDc.Bails.
                                  Include(m => m.Account).
                                  Include(c => c.Guarantor).
                                  FirstOrDefaultAsync(m => m.Id == bailToSave.Id);

                if (orginalBail == null)
                {
                    _logger.Error($"the original bail object with id {bailToSave.Id} object is not founded, ObjectNotFoundException will be thrown");
                    throw new Exceptions.ObjectNotFoundException();
                }

                orginalBail.AccountID     = bailToSave.AccountID;
                orginalBail.Amount        = bailToSave.Amount;
                orginalBail.EndDate       = bailToSave.EndDate;
                orginalBail.GuarantorID   = bailToSave.GuarantorID;
                orginalBail.IsExpired     = bailToSave.IsExpired;
                orginalBail.IsFamilyBail  = bailToSave.IsFamilyBail;
                orginalBail.IsMonthlyBail = bailToSave.IsMonthlyBail;
                orginalBail.StartDate     = bailToSave.StartDate;
                orginalBail.Note          = bailToSave.Note;
                ret += await orphanageDc.SaveChangesAsync();

                if (ret > 0)
                {
                    _logger.Information($"the object bail with id {orginalBail.Id} has been saved successfully, {ret} changes has been made ");
                    return(true);
                }
                else
                {
                    _logger.Information($"the object bail with id {orginalBail.Id} has been saved successfully, nothing has changed");
                    return(false);
                }
            }
        }
Пример #28
0
 public void TestIsFamilyCardNumberExist()
 {
     using (var orphanageDbc = new OrphanageDbCNoBinary())
     {
         var ret = _CheckerService.IsFamilyCardNumberExist("1498906", orphanageDbc).Result;
         ret.ShouldNotBeNull();
     }
 }
Пример #29
0
 public void TestIsIdentityNumberExist()
 {
     using (var orphanageDbc = new OrphanageDbCNoBinary())
     {
         var ret = _CheckerService.IsIdentityNumberExist("04180075865", orphanageDbc).Result;
         ret.ShouldNotBeNull();
     }
 }
Пример #30
0
        public async Task <int> SaveMother(OrphanageDataModel.Persons.Mother mother)
        {
            if (mother == null)
            {
                throw new NullReferenceException();
            }
            using (OrphanageDbCNoBinary orphanageDc = new OrphanageDbCNoBinary())
            {
                int ret = 0;
                orphanageDc.Configuration.AutoDetectChangesEnabled = true;
                var motherToReplace = await orphanageDc.Mothers.Include(m => m.Address).Where(m => m.Id == mother.Id).FirstAsync();

                if (motherToReplace == null)
                {
                    throw new ObjectNotFoundException();
                }
                if (mother.Address != null)
                {
                    if (motherToReplace.Address != null)
                    {
                        ret += await _regularDataService.SaveAddress(mother.Address, orphanageDc);
                    }
                    else
                    {
                        var addressId = await _regularDataService.AddAddress(mother.Address, orphanageDc);

                        motherToReplace.AddressId = addressId;
                        ret++;
                    }
                }
                else
                if (motherToReplace.Address != null)
                {
                    int alAdd = motherToReplace.AddressId.Value;
                    motherToReplace.AddressId = null;
                    await orphanageDc.SaveChangesAsync();

                    await _regularDataService.DeleteAddress(alAdd, orphanageDc);
                }
                ret += await _regularDataService.SaveName(mother.Name, orphanageDc);

                motherToReplace.Birthday      = mother.Birthday;
                motherToReplace.ColorMark     = mother.ColorMark;
                motherToReplace.DateOfDeath   = mother.DateOfDeath;
                motherToReplace.HasSheOrphans = mother.HasSheOrphans;
                motherToReplace.HusbandName   = mother.HusbandName;
                motherToReplace.IsDead        = mother.IsDead;
                motherToReplace.IsMarried     = mother.IsMarried;
                motherToReplace.Jop           = mother.Jop;
                motherToReplace.NameId        = mother.NameId;
                motherToReplace.Note          = mother.Note;
                motherToReplace.Salary        = mother.Salary;
                motherToReplace.Story         = mother.Story;
                ret += await orphanageDc.SaveChangesAsync();

                return(ret);
            }
        }