Esempio n. 1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("RelationshipId,FamilyId,Id,CreatedBy,CreatedAt,ChangedBy,ChangedAt")] FamilyRelationship familyRelationship)
        {
            if (id != familyRelationship.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(familyRelationship);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FamilyRelationshipExists(familyRelationship.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FamilyId"]       = new SelectList(_context.Families, "Id", "FamilyName", familyRelationship.FamilyId);
            ViewData["RelationshipId"] = new SelectList(_context.Relationships, "Id", "Id", familyRelationship.RelationshipId);
            return(View(familyRelationship));
        }
        public async Task <IActionResult> PutFamilyRelationship(Guid id, FamilyRelationship familyRelationship)
        {
            if (id != familyRelationship.Id)
            {
                return(BadRequest());
            }

            _context.Entry(familyRelationship).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FamilyRelationshipExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("RelationshipId,FamilyId,Id,CreatedBy,CreatedAt,ChangedBy,ChangedAt")] FamilyRelationship familyRelationship)
        {
            if (ModelState.IsValid)
            {
                familyRelationship.Id = Guid.NewGuid();
                _context.Add(familyRelationship);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FamilyId"]       = new SelectList(_context.Families, "Id", "FamilyName", familyRelationship.FamilyId);
            ViewData["RelationshipId"] = new SelectList(_context.Relationships, "Id", "Id", familyRelationship.RelationshipId);
            return(View(familyRelationship));
        }
Esempio n. 4
0
        private void AddOrUpdateMarriageRelationship(Family family, Person husband, Person wife)
        {
            var relationship = new FamilyRelationship()
            {
                FamilyId          = family.Id,
                PersonId          = husband.Id,
                RelatedPersonId   = wife.Id,
                PersonRole        = PersonRole.Husband,
                RelatedPersonRole = PersonRole.Wife,
                RelationshipType  = RelationshipType.Married
            };

            _context.FamilyRelationships.AddOrUpdate(r => new { r.PersonId, r.RelatedPersonId }, relationship);
            _context.SaveChanges();
        }
        public async Task <ActionResult <FamilyRelationship> > PostFamilyRelationship(FamilyRelationship familyRelationship)
        {
            _context.FamilyRelationships.Add(familyRelationship);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFamilyRelationship", new { id = familyRelationship.Id }, familyRelationship));
        }