示例#1
0
        private void SetupTestDatabase()
        {
            using (var context = new EintechSearchContext(options))
            {
                var g1 = new Group
                {
                    Name = "Lions"
                };
                var g2 = new Group
                {
                    Name = "Tigers"
                };
                context.AddRange(g1, g2);
                context.SaveChanges();

                var p1 = new Person
                {
                    FirstName = "Tommy",
                    LastName  = "Smith",
                    Created   = DateTime.Now,
                    Group     = g1
                };
                var p2 = new Person
                {
                    FirstName = "Tim",
                    LastName  = "Thorne",
                    Created   = DateTime.Now,
                    Group     = g1
                };
                var p3 = new Person
                {
                    FirstName = "Tammy",
                    LastName  = "Borne",
                    Created   = DateTime.Now,
                    Group     = g1
                };
                var p4 = new Person
                {
                    FirstName = "Timmy",
                    LastName  = "Smit",
                    Created   = DateTime.Now,
                    Group     = g2
                };
                var p5 = new Person
                {
                    FirstName = "Thomas",
                    LastName  = "Mith",
                    Created   = DateTime.Now,
                    Group     = g2
                };

                context.AddRange(p1, p2, p3, p4, p5);
                context.SaveChanges();
            }
        }
示例#2
0
        public PersonViewModel Insert(CreatePersonViewModel createPerson)
        {
            var group     = context.Group.First(x => x.Id == createPerson.GroupId);
            var newPerson = new Person
            {
                Created   = DateTime.Now,
                FirstName = createPerson.FirstName,
                LastName  = createPerson.LastName,
                Group     = group
            };

            context.Add(newPerson);
            context.SaveChanges();
            return(newPerson.ToViewModel());
        }