Esempio n. 1
0
 private void btnFamilyBrowse_Click(object sender, EventArgs e)
 {
     ChooserView.ChooserView chooserView = new ChooserView.ChooserView(_familiesSelectionList, Properties.Resources.ChooseFamily);
     chooserView.MultiSelect = false;
     chooserView.ShowDialog();
     if (chooserView.DialogResult == DialogResult.OK)
     {
         EnabledDisabledControl(true);
         _familyModel = (ViewModel.Family.FamilyModel)chooserView.SelectedObject;
         _family      = _AddOrphanViewModel.GetSourceFamily(_familyModel.Id);
         SetOtherCaregiversOptions();
         txtFatherName.Text = _familyModel.FatherFullName;
         txtMotherName.Text = _familyModel.MotherFullName;
         orphanNameForm.txtEnglishFather.Text = _family.Father.Name.EnglishFirst;
         orphanNameForm.txtFather.Text        = _family.Father.Name.First;
         orphanNameForm.txtLast.Text          = _family.Father.Name.Last;
         orphanNameForm.txtEnglishLast.Text   = _family.Father.Name.EnglishLast;
     }
     else
     {
         EnabledDisabledControl(false);
         _familyModel       = null;
         _brothersCaregiver = null;
         _motherCaregiver   = null;
         _family            = null;
         txtFatherName.Text = string.Empty;
         txtMotherName.Text = string.Empty;
     }
 }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private async void LoadFamily(int fatherId)
        {
            _Father = await _fatherEditViewModel.getFamily(fatherId);

            if (_Father != null)
            {
                familyBindingSource.DataSource           = _Father;
                _familyEntityValidator.controlCollection = Controls;
                _familyEntityValidator.DataEntity        = _Father;
                addressForm1.AddressDataSource           = _Father.PrimaryAddress;
                if (_Father.AlternativeAddress != null)
                {
                    addressForm2.AddressDataSource = _Father.AlternativeAddress;
                }
                else
                {
                    addressForm2.AddressDataSource = new Address();
                }
                SetData();
                txtAddress.Text  = addressForm1.FullAddress;
                txtAddress2.Text = addressForm2.FullAddress;
            }
            TranslateControls();
        }
Esempio n. 5
0
        public async Task <bool> SaveFamily(OrphanageDataModel.RegularData.Family family)
        {
            _logger.Information($"trying to save family");
            if (family == null)
            {
                _logger.Error($"family parameter is null, false will be returned");
                return(false);
            }
            _logger.Information($"trying to save family with id({family.Id})");

            using (var orphanageDbc = new OrphanageDbCNoBinary())
            {
                int ret = 0;
                orphanageDbc.Configuration.LazyLoadingEnabled       = true;
                orphanageDbc.Configuration.ProxyCreationEnabled     = true;
                orphanageDbc.Configuration.AutoDetectChangesEnabled = true;
                var savedFamily = await orphanageDbc.Families.
                                  Include(f => f.AlternativeAddress).
                                  Include(f => f.PrimaryAddress)
                                  .Where(fam => fam.Id == family.Id).FirstOrDefaultAsync();

                _logger.Information($"processing alternative address to the family with id({family.Id})");
                if (family.AlternativeAddress != null)
                {
                    if (savedFamily.AlternativeAddress == null)
                    {
                        var addressID = await _regularDataService.AddAddress(family.AlternativeAddress, orphanageDbc);

                        savedFamily.AlternativeAddressId = addressID;
                    }
                    else
                    {
                        ret += await _regularDataService.SaveAddress(family.AlternativeAddress, orphanageDbc);
                    }
                }
                else
                {
                    if (savedFamily.AlternativeAddress != null)
                    {
                        int alAdd = savedFamily.AlternativeAddressId.Value;
                        savedFamily.AlternativeAddressId = null;
                        await orphanageDbc.SaveChangesAsync();

                        await _regularDataService.DeleteAddress(alAdd, orphanageDbc);
                    }
                }
                _logger.Information($"processing primary address to the family with id({family.Id})");
                if (family.PrimaryAddress != null)
                {
                    if (savedFamily.PrimaryAddress == null)
                    {
                        var addressID = await _regularDataService.AddAddress(family.PrimaryAddress, orphanageDbc);

                        savedFamily.AddressId = addressID;
                        ret++;
                    }
                    else
                    {
                        ret += await _regularDataService.SaveAddress(family.PrimaryAddress, orphanageDbc);
                    }
                }
                else
                {
                    if (savedFamily.PrimaryAddress != null)
                    {
                        int Add = savedFamily.AddressId.Value;
                        savedFamily.AddressId = null;
                        await orphanageDbc.SaveChangesAsync();

                        await _regularDataService.DeleteAddress(Add, orphanageDbc);
                    }
                }
                savedFamily.FatherId = family.FatherId;
                ret += await _fatherDbService.SaveFather(family.Father);

                savedFamily.MotherId = family.MotherId;
                ret += await _motherDbService.SaveMother(family.Mother);

                savedFamily.BailId          = family.BailId;
                savedFamily.ColorMark       = family.ColorMark;
                savedFamily.FinncialStatus  = family.FinncialStatus;
                savedFamily.IsBailed        = family.IsBailed;
                savedFamily.IsExcluded      = family.IsExcluded;
                savedFamily.IsTheyRefugees  = family.IsTheyRefugees;
                savedFamily.Note            = family.Note;
                savedFamily.ResidenceStatus = family.ResidenceStatus;
                savedFamily.ResidenceType   = family.ResidenceType;
                ret += await orphanageDbc.SaveChangesAsync();

                if (ret > 0)
                {
                    _logger.Information($"family with id({family.Id}) has been successfully saved to the database, {ret} changes have been made");
                    return(true);
                }
                else
                {
                    _logger.Information($"nothing has changed, false will be returned");
                    return(false);
                }
            }
        }
Esempio n. 6
0
 public Task <bool> IsExist(OrphanageDataModel.RegularData.Family family)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 7
0
        public async Task <OrphanageDataModel.RegularData.Family> AddFamily(OrphanageDataModel.RegularData.Family family)
        {
            _logger.Information($"trying to add new family");
            if (family == null)
            {
                _logger.Error($"the given family parameter is null, null will be returned");
                return(null);
            }
            if (family.PrimaryAddress == null)
            {
                _logger.Error($"the given primary address of the given family parameter is null, null will be returned");
                return(null);
            }

            using (var orphanageDbc = new OrphanageDbCNoBinary())
            {
                using (var DbT = orphanageDbc.Database.BeginTransaction())
                {
                    if (!Properties.Settings.Default.ForceAdd)
                    {
                        _logger.Information($"ForceAdd option is not activated");
                        if (Properties.Settings.Default.CheckContactData)
                        {
                            _logger.Information($"CheckContactData option is activated, trying to get the equal contact data for the primary address from database");
                            var ret = GetFamiliesByAddress(family.PrimaryAddress, orphanageDbc).FirstOrDefault();
                            if (ret != null)
                            {
                                _logger.Error($"family with id({ret.Id}) has the same address, DuplicatedObjectException will be thrown");
                                throw new DuplicatedObjectException(family.GetType(), ret.GetType(), ret.Id);
                            }
                            else
                            {
                                _logger.Information($"didn't found any similar contact data to family primary address in the database");
                            }
                            if (family.AlternativeAddress != null)
                            {
                                _logger.Information($"CheckContactData option is activated, trying to get the equal contact data for the alternative address from database");
                                ret = GetFamiliesByAddress(family.AlternativeAddress, orphanageDbc).FirstOrDefault();
                                if (ret != null)
                                {
                                    _logger.Error($"family with id({ret.Id}) has the same address, DuplicatedObjectException will be thrown");
                                    throw new DuplicatedObjectException(family.GetType(), ret.GetType(), ret.Id);
                                }
                                else
                                {
                                    _logger.Information($"didn't found any similar contact data to family alternative address in the database");
                                }
                            }
                        }
                    }

                    var        addressPrim      = family.PrimaryAddress;
                    var        addressAlter     = family.AlternativeAddress;
                    var        father           = family.Father;
                    var        mother           = family.Mother;
                    var        taskPrimAddress  = _regularDataService.AddAddress(addressPrim, orphanageDbc);
                    Task <int> taskAlterAddress = null;
                    family.AddressId      = await taskPrimAddress;
                    family.PrimaryAddress = addressPrim;
                    if (family.AlternativeAddress != null)
                    {
                        taskAlterAddress = _regularDataService.AddAddress(addressAlter, orphanageDbc);
                    }
                    if (family.Orphans != null && family.Orphans.Count > 0)
                    {
                        family.Orphans = null;
                    }
                    if (taskAlterAddress != null)
                    {
                        family.AlternativeAddressId = await taskAlterAddress;
                        family.AlternativeAddress   = addressAlter;
                    }
                    // set father
                    var taskFather = _fatherDbService.AddFather(father, orphanageDbc);
                    family.FatherId = await taskFather;
                    family.Father   = null;
                    // set mother
                    var taskMother = _motherDbService.AddMother(mother, orphanageDbc);
                    family.MotherId = await taskMother;
                    family.Mother   = null;

                    if (family.Bail != null)
                    {
                        family.Bail = null;
                    }
                    if (family.ActingUser != null)
                    {
                        family.ActingUser = null;
                    }
                    if (family.Orphans != null)
                    {
                        family.Orphans = null;
                    }
                    orphanageDbc.Families.Add(family);
                    if (await orphanageDbc.SaveChangesAsync() > 0)
                    {
                        DbT.Commit();
                        _logger.Information($"family with id({family.Id}) has been successfully added to the database");
                    }
                    else
                    {
                        DbT.Rollback();
                        _logger.Information($"nothing has changed, family has not added, null will be returned");
                        return(null);
                    }
                }
            }
            return(await GetFamily(family.Id));
        }