public async Task <IActionResult> NewChild(NewChildModel model) { var cancellationToken = GetCancellationToken(); var parent1 = _clanAndPeopleService.People.FirstOrDefault(t => t.Id == model.Parent1); var parent2 = _clanAndPeopleService.People.FirstOrDefault(t => t.Id == model.Parent2); var newId = _clanAndPeopleService.People.Max(t => t.Id) + 1; var union = (await _unionReadRepository.GetAllUnions(cancellationToken)).FirstOrDefault(t => (t.PartnerID == model.Parent1 && t.Partner2ID == model.Parent2) || (t.PartnerID == model.Parent2 && t.Partner2ID == model.Parent1)); await _writeModel.Save(new Repo.Core.Model.Person() { ID = newId, ClandId = parent1.ClanId, DateOfBirth = model.DateOfBirth, FatherID = model.Parent1, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName.ToUpper(), Gender = model.Gender, IsClanManager = false, IsSpouse = false, MotherID = model.Parent2, ParentRelationship = union.ID, SubscribeToEmail = false }, cancellationToken); _clanAndPeopleService.ClearPeople(); return(RedirectToAction("Person", new { id = parent1.Id })); }
public IActionResult AddChild([FromRoute] int parent1Id, [FromRoute] int parent2Id) { var parents = _clanAndPeopleService.People.Where(p => p.Id == parent1Id || p.Id == parent2Id); var model = new NewChildModel( parents.Count() > 0 ? parents.FirstOrDefault() : null, parents.Count() > 1 ? parents.Skip(1).First() : null); return(View("NewChild", model)); }