public async Task <IActionResult> Edit(Guid id, [Bind("RelationshipRoleDescription,Id,CreatedBy,CreatedAt,ChangedBy,ChangedAt")] RelationshipRole relationshipRole)
        {
            if (id != relationshipRole.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(relationshipRole);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RelationshipRoleExists(relationshipRole.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(relationshipRole));
        }
        public async Task <IActionResult> Create([Bind("RelationshipRoleDescription,Id,CreatedBy,CreatedAt,ChangedBy,ChangedAt")] RelationshipRole relationshipRole)
        {
            if (ModelState.IsValid)
            {
                relationshipRole.Id = Guid.NewGuid();
                _context.Add(relationshipRole);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(relationshipRole));
        }
Exemplo n.º 3
0
        private static RelationshipRole MapRelationshipRoleDTOToRelationshipRole(RelationshipRoleDTO r)
        {
            var relationship = new RelationshipRole()
            {
                RelationshipRoleName        = r.RelationshipRoleName,
                RelationshipRoleDescription = r.RelationshipRoleDescription
            };

            if (r.Id.ToString().Length == 36)
            {
                relationship.Id = r.Id;
            }

            MetaData.AddMetaData(relationship);

            return(relationship);
        }
Exemplo n.º 4
0
        private static void SeedPersonData(ApplicationDbContext ctx)
        {
            var superUser   = ctx.Users.Single(u => u.UserName.Equals("*****@*****.**"));
            var superUserId = superUser.Id;

            string[]   names             = new[] { "Tristan Krass", "Morris Mason", "Rose Mason", "Madeleine Mason", "Sophie Mason", "Charlotte Mason", "Isabelle Mason" };
            string[]   familyNames       = new[] { "Krass", "Mason", "Rose" };
            string[]   relationShipTypes = new[] { "Mom-Son", "Dad-Son", "Brother-Brother", "Brother-Sister", "Married" };
            string[]   relationShipRoles = new[] { "Mom", "Son", "Brother", "Sister", "Dad", "Wife", "Husband" };
            DateTime[] dateTimes         = new[] {
                new DateTime(1998, 6, 20),
                new DateTime(1950, 1, 12), new DateTime(1975, 3, 5),
                new DateTime(2004, 2, 15), new DateTime(1980, 12, 12),
                new DateTime(1970, 4, 20), new DateTime(1975, 12, 31),
            };
            ;

            foreach (var familyName in familyNames)
            {
                var family = new Family()
                {
                    FamilyName = familyName
                };

                MetaData.AddInitialClassMetaDataSeeding(family, superUserId);

                ctx.Families.Add(family);
                ctx.SaveChanges();
            }


            int i = 0;

            foreach (var name in names)
            {
                var person = new Person()
                {
                    FirstName   = name.Split()[0],
                    LastName    = name.Split()[1],
                    DateOfBirth = dateTimes[i],
                    AppUserId   = superUserId,
                    Sex         = i % 2 == 0 ? Sex.FEMALE : Sex.MALE
                };

                MetaData.AddInitialClassMetaDataSeeding(person, superUserId);

                ctx.Persons.Add(person);

                i++;
                ctx.SaveChanges();
            }



            foreach (var role in relationShipRoles)
            {
                var rL = new RelationshipRole()
                {
                    RelationshipRoleName = role
                };
                MetaData.AddInitialClassMetaDataSeeding(rL, superUserId);

                ctx.RelationshipRoles.Add(rL);
            }
            ctx.SaveChanges();

            foreach (var relationShipType in relationShipTypes)
            {
                var relationshipType = new RelationshipType()
                {
                    RelationshipTypeName = relationShipType
                };
                MetaData.AddInitialClassMetaDataSeeding(relationshipType, superUserId);
            }

            ctx.SaveChanges();
        }
Exemplo n.º 5
0
 private static RelationshipRoleDTO MapRelationshipRoleToRelationshipRoleDto(RelationshipRole r) => new RelationshipRoleDTO()
 {
     Id = r.Id,
     RelationshipRoleName        = r.RelationshipRoleName,
     RelationshipRoleDescription = r.RelationshipRoleDescription
 };