Esempio n. 1
0
 public static Person FlatMap(Repo.Core.Model.Person person, ClanAndPeopleService clanAndPeopleService)
 {
     if (person == null)
     {
         return(null);
     }
     return(new Person()
     {
         Address = person.Address1,
         Address1 = person.Address2,
         EmailAddress = person.EmailAddress,
         FirstName = person.FirstName,
         MiddleName = person.MiddleName,
         MaidenName = person.MaidenName,
         Phone = person.Phone,
         LastName = person.LastName,
         PostCode = person.PostCode,
         State = person.State,
         SubscribeToEmail = person.SubscribeToEmail,
         Suburb = person.Suburb,
         Occupation = person.Occupation,
         ClanName = clanAndPeopleService.Clans.FirstOrDefault(t => t.Id == person.ClandId)?.FormattedName,
         ClanId = person.ClandId,
         Id = person.ID,
         IsSpouse = person.IsSpouse,
         DateOfBirth = person.DateOfBirth,
         DateOfDeath = person.DateOfDeath,
         YearOfBirth = person.YearOfBirth,
         YearOfDeath = person.YearOfDeath,
         Gender = person.Gender,
         ParentRelationship = person.ParentRelationship,
         IsClanManager = person.IsClanManager,
         LastUpdated = person.LastUpdated
     });
 }
Esempio n. 2
0
        private void MapParents(Repo.Core.Model.Person dbPerson, List <Person> peopleList)
        {
            var person = peopleList.First(p => p.Id == dbPerson.ID);

            person.Father = peopleList.FirstOrDefault(f => f.Id == dbPerson.FatherID);
            person.Mother = peopleList.FirstOrDefault(f => f.Id == dbPerson.MotherID);
        }
Esempio n. 3
0
        private async Task ProcessDirectChildrenOfUnion(Repo.Core.Model.Union union, Repo.Core.Model.Person husband, Repo.Core.Model.Person wife, CancellationToken cancellationToken)
        {
            var children = await _readModel.GetChildrenByParents(union.PartnerID, union.Partner2ID, cancellationToken);

            children.ForEach(async c =>
            {
                c.ParentRelationship = union.ID;
                await _writeModel.Save(c, cancellationToken);
            });

            var children2 = await _readModel.GetChildrenByParents(union.Partner2ID, union.PartnerID, cancellationToken);

            children2.ForEach(async c =>
            {
                c.ParentRelationship = union.ID;
                await _writeModel.Save(c, cancellationToken);
            });
        }
Esempio n. 4
0
        public async Task <IActionResult> MasterList(List <IFormFile> files)
        {
            var cancellationToken = CancellationToken.None;

            if (files.Count > 0)
            {
                foreach (var file in files)
                {
                    using (var excel = new ExcelPackage(file.OpenReadStream()))
                    {
                        var sheet = excel.Workbook.Worksheets["Family Master"];
                        if (sheet != null)
                        {
                            var rowId = 2; // sheet has header row!
                            while (sheet.Cells[rowId, 1].Text != string.Empty)
                            {
                                var identifier = new PersonIdentifier()
                                {
                                    PersonId     = ReadIntCell(sheet, rowId, PersonImport.ID),
                                    FirstName    = ReadStringCell(sheet, rowId, PersonImport.FirstName).ToTitleCase(),
                                    LastName     = ReadStringCell(sheet, rowId, PersonImport.LastName).ToUpper(),
                                    EmailAddress = ReadStringCell(sheet, rowId, PersonImport.EmailAddress),
                                    MiddleName   = ReadStringCell(sheet, rowId, PersonImport.MiddleName).ToTitleCase()
                                };

                                var person = await _writeModel.FindByQuery(identifier, cancellationToken);

                                if (person == null)
                                {
                                    person = new Repo.Core.Model.Person()
                                    {
                                        ID = ReadIntCell(sheet, rowId, PersonImport.ID)
                                    };
                                }

                                person.FirstName    = ReadStringCell(sheet, rowId, PersonImport.FirstName).ToTitleCase();
                                person.LastName     = ReadStringCell(sheet, rowId, PersonImport.LastName).ToUpper();
                                person.EmailAddress = ReadStringCell(sheet, rowId, PersonImport.EmailAddress);
                                person.MiddleName   = ReadStringCell(sheet, rowId, PersonImport.MiddleName).ToTitleCase();
                                person.MaidenName   = ReadStringCell(sheet, rowId, PersonImport.MaindenName).ToUpper();
                                person.Phone        = ReadStringCell(sheet, rowId, PersonImport.PhoneNumber);
                                person.ClandId      = ReadNullableIntCell(sheet, rowId, PersonImport.Clan);
                                person.IsSpouse     = ReadStringCell(sheet, rowId, PersonImport.IsSpouse).Equals("y", StringComparison.CurrentCultureIgnoreCase);
                                person.MotherID     = GetNullableInt(sheet, PersonImport.MotherId, rowId);
                                person.FatherID     = GetNullableInt(sheet, PersonImport.FatherId, rowId);
                                person.Address1     = ReadStringCell(sheet, rowId, PersonImport.Address1);
                                person.Address2     = ReadStringCell(sheet, rowId, PersonImport.Address2);
                                person.Suburb       = ReadStringCell(sheet, rowId, PersonImport.Suburb).ToUpper();
                                person.State        = ReadStringCell(sheet, rowId, PersonImport.State).ToUpper();
                                person.PostCode     = ReadStringCell(sheet, rowId, PersonImport.PostCode);
                                person.Occupation   = ReadStringCell(sheet, rowId, PersonImport.Occupation);

                                if (ReadStringCell(sheet, rowId, PersonImport.DOB).Length == 4)
                                {
                                    person.YearOfBirth = ReadIntCell(sheet, rowId, PersonImport.DOB);
                                }
                                else
                                {
                                    person.DateOfBirth = ReadNullableDate(sheet, rowId, PersonImport.DOB);
                                }

                                if (ReadStringCell(sheet, rowId, PersonImport.DOD).Length == 4)
                                {
                                    person.YearOfDeath = ReadIntCell(sheet, rowId, PersonImport.DOD);
                                }
                                else
                                {
                                    person.DateOfDeath = ReadNullableDate(sheet, rowId, PersonImport.DOD);
                                }

                                person.Gender           = ReadStringCell(sheet, rowId, PersonImport.Gender);
                                person.IsClanManager    = false;
                                person.LastUpdated      = DateTime.Now;
                                person.SubscribeToEmail = !string.IsNullOrEmpty(person.EmailAddress);

                                try
                                {
                                    await _writeModel.Save(person, cancellationToken);
                                }
                                catch (Exception ex)
                                {
                                }

                                rowId++;
                            }

                            //do unions from pointers to parents
                            var parentChildRowId = 2;
                            while (sheet.Cells[parentChildRowId, 1].Text != string.Empty)
                            {
                                var father = string.IsNullOrWhiteSpace(sheet.Cells[parentChildRowId, 12].Text) ? null : await _writeModel.FindByQuery(new PersonIdentifier { PersonId = ReadIntCell(sheet, parentChildRowId, PersonImport.FatherId) },
                                                                                                                                                      cancellationToken);

                                var mother = string.IsNullOrWhiteSpace(sheet.Cells[parentChildRowId, 11].Text) ? null : await _writeModel.FindByQuery(new PersonIdentifier { PersonId = ReadIntCell(sheet, parentChildRowId, PersonImport.MotherId) },
                                                                                                                                                      cancellationToken);

                                if (father != null || mother != null) // we have a parent / parents
                                {
                                    //is there a union?
                                    var thisUnion = await _unionWriteRepository.FindByQuery(new UnionQuery
                                    {
                                        Partner1Id = father?.ID,
                                        Partner2Id = mother?.ID
                                    }, cancellationToken);

                                    if (thisUnion == null)
                                    {
                                        thisUnion = await _unionWriteRepository.FindByQuery(new UnionQuery
                                        {
                                            Partner1Id = mother?.ID,
                                            Partner2Id = father?.ID
                                        }, cancellationToken);
                                    }
                                    if (thisUnion == null)
                                    {
                                        thisUnion = new Repo.Core.Model.Union()
                                        {
                                            PartnerID  = father?.ID,
                                            Partner2ID = mother?.ID,
                                            ID         = Guid.NewGuid()
                                        };
                                        await _unionWriteRepository.Save(thisUnion, cancellationToken);
                                    }
                                    var child = await _writeModel.FindByQuery(new PersonIdentifier { PersonId = ReadIntCell(sheet, parentChildRowId, PersonImport.ID) },
                                                                              cancellationToken);

                                    child.ParentRelationship = thisUnion.ID;
                                    await _writeModel.Save(child, cancellationToken);
                                }
                                parentChildRowId++;
                            }
                        }

                        var spouseSheet = excel.Workbook.Worksheets["Spouses"];
                        if (spouseSheet != null)
                        {
                            var rowId = 2; // sheet has header row!
                            while (spouseSheet.Cells[rowId, 1].Text != string.Empty)
                            {
                                var clanMember = await _writeModel.FindByQuery(new PersonIdentifier { PersonId = ReadIntCell(spouseSheet, rowId, 1) },
                                                                               cancellationToken);

                                var spouse = await _writeModel.FindByQuery(new PersonIdentifier { PersonId = ReadIntCell(spouseSheet, rowId, 2) },
                                                                           cancellationToken);

                                var union = await _unionWriteRepository.FindByQuery(new UnionQuery
                                {
                                    Partner1Id = ReadNullableIntCell(spouseSheet, rowId, 1),
                                    Partner2Id = ReadNullableIntCell(spouseSheet, rowId, 2)
                                }, cancellationToken);

                                if (union == null)
                                {
                                    //is there one going the other way?
                                    union = await _unionWriteRepository.FindByQuery(new UnionQuery
                                    {
                                        Partner1Id = ReadNullableIntCell(spouseSheet, rowId, 2),
                                        Partner2Id = ReadNullableIntCell(spouseSheet, rowId, 1)
                                    }, cancellationToken);

                                    if (union == null)
                                    {
                                        union = new Repo.Core.Model.Union()
                                        {
                                            PartnerID  = ReadNullableIntCell(spouseSheet, rowId, 1),
                                            Partner2ID = ReadNullableIntCell(spouseSheet, rowId, 2),
                                            ID         = Guid.NewGuid()
                                        };
                                    }
                                }

                                union.MarriageDate = ReadNullableDate(spouseSheet, rowId, 3);
                                union.DivorceDate  = ReadNullableDate(spouseSheet, rowId, 4);
                                union.IsEnded      = string.IsNullOrEmpty(ReadStringCell(spouseSheet, rowId, 5)) ? false : true;

                                await _unionWriteRepository.Save(union, cancellationToken);

                                rowId++;
                            }
                        }
                    }
                }
                _clanAndPeopleService.ClearPeople();
            }
            return(RedirectToAction("Index"));
        }