Example #1
0
 /*Save  a single record for person based on 'Add or Update' */
 public bool SavePerson(Person person, String action)
 {
     if (action == "insert")
     {
         _context.Entry(person).State = EntityState.Added;
     }
     else
     {
         _context.Entry(person).State = EntityState.Modified;
     }
     return(_context.SaveChanges() >= 0);
 }
Example #2
0
        public PersonsController(PersonInfoContext context)
        {
            _context = context;

            if (_context.Persons.Count() == 0)
            {
                _context.Persons.Add(new Person()
                {
                    Id = 1, FirstName = "Fred", LastName = "Fredericson", Age = 41, StreetAddress = "123 SomeStreet", Interests = "Portlandia, WakeBoarding", PictureURL = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Fred_Armisen_2014_cropped_and_retouched.jpg/220px-Fred_Armisen_2014_cropped_and_retouched.jpg"
                });
                _context.Persons.Add(new Person()
                {
                    Id = 2, FirstName = "Jane", LastName = "Johnson", Age = 33, StreetAddress = "124 SomeAvenue", Interests = "Hiking, Rafting", PictureURL = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/JaneAsher.jpg/200px-JaneAsher.jpg"
                });
                _context.Persons.Add(new Person()
                {
                    Id = 3, FirstName = "Nancy", LastName = "Smith", Age = 39, StreetAddress = "124 NewStreet", Interests = "Social Media", PictureURL = "http://nancycampbell.co.uk/wp-content/uploads/Screen-Shot-2018-04-19-at-20.27.41-475x600.png"
                });
                _context.SaveChanges();
            }
        }
        public static void EnsureSeedDataForContext(this PersonInfoContext context)
        {
            if (context.AgeGroups.Any())
            {
                return;
            }

            // init seed data
            var AgeGroups = new List <AgeGroup>()
            {
                new AgeGroup()
                {
                    MinAge = null, MaxAge = 2, Description = "Toddler"
                },
                new AgeGroup()
                {
                    MinAge = 2, MaxAge = 14, Description = "Child"
                },
                new AgeGroup()
                {
                    MinAge = 14, MaxAge = 20, Description = "Teenager"
                },
                new AgeGroup()
                {
                    MinAge = 20, MaxAge = 25, Description = "Early twenties"
                },
                new AgeGroup()
                {
                    MinAge = 25, MaxAge = 30, Description = "Almost thirty"
                },
                new AgeGroup()
                {
                    MinAge = 30, MaxAge = 50, Description = "Very adult"
                },
                new AgeGroup()
                {
                    MinAge = 50, MaxAge = 70, Description = "Kinda old"
                },
                new AgeGroup()
                {
                    MinAge = 70, MaxAge = 99, Description = "Old"
                },
                new AgeGroup()
                {
                    MinAge = 99, MaxAge = 110, Description = "Very Old"
                },
                new AgeGroup()
                {
                    MinAge = 110, MaxAge = 199, Description = "Crazy ancient"
                },
                new AgeGroup()
                {
                    MinAge = 199, MaxAge = 4999, Description = "Vampire"
                },
                new AgeGroup()
                {
                    MinAge = 4999, MaxAge = null, Description = "Kauri tree"
                },
            };

            context.AgeGroups.AddRange(AgeGroups);
            context.SaveChanges();
        }