public BirthdayPageViewModel(int id)
 {
     using (var context = new Context()) {
         birthday = context.GetOrCreateBirthday(id);
         Categories = context.Categories.Select(x => x.Name).ToList();
     }
 }
 public void Refresh()
 {
     using (var context = new Context()) {
         BirthdayLists = new ObservableCollection<BirthdayList>(context
             .GetCategories().Select(category => new BirthdayList(context.BirthdaysForCategory(category))));
     }
 }
 public void Save()
 {
     using (var context = new Context())
     {
         context.Birthdays.InsertOnSubmit(birthday);
         context.SubmitChanges();
     }
 }
Beispiel #4
0
        public static void InitializeIfEmpty()
        {
            using (var context = new Context())
            {
                if (!context.DatabaseExists()) {
                    // create database if it does not exist
                    context.CreateDatabase();
                }

                if (context.Birthdays.Any()) return;

                var categories = new Category[]
                                     {
                                         new Category("general"),
                                         new Category("friends"),
                                         new Category("family"),
                                     };
                var demo = new Birthday[]
                           {
                               new Birthday() { Name = "Jos", Category = categories[0], Date = new DateTime(2011, 03, 11) },
                               new Birthday() { Name = "Frank", Category = categories[0], Date = new DateTime(2010, 4, 22) },
                               new Birthday() { Name = "Lowie", Category = categories[1], Date = new DateTime(2009, 4, 30) },
                               new Birthday() { Name = "Ludovic", Category = categories[2], Date = new DateTime(1975, 8, 29) },
                               new Birthday() { Name = "Jan", Category = categories[0], Date = new DateTime(1983, 11, 1) },
                               new Birthday() { Name = "Erik", Category = categories[2], Date = new DateTime(1967, 10, 9) },
                               new Birthday() { Name = "Lisa", Category = categories[1], Date = new DateTime(1994, 12, 3) },
                               new Birthday() { Name = "Bertha", Category = categories[2], Date = new DateTime(2003, 03, 5) },
                               new Birthday() { Name = "Ellen", Category = categories[0], Date = new DateTime(2005, 04, 11) },
                           };

                foreach (var category in categories) {
                    context.Categories.InsertOnSubmit(category);
                }
                foreach (var birthday in demo)
                {
                    context.Birthdays.InsertOnSubmit(birthday);
                }
                context.SubmitChanges();
            }
        }