static int AddUsers(AsanaContext db) { if (db.Users.Where(u => u.Name == "Frank Zappa").FirstOrDefault() == null) { db.Users.Add(new AsanaUser { Name = "Frank Zappa", Email = "*****@*****.**" }); } if (db.Users.Where(u => u.Name == "Bob Dylan").FirstOrDefault() == null) { db.Users.Add(new AsanaUser { Name = "Bob Dylan", Email = "*****@*****.**" }); } if (db.Users.Where(u => u.Name == "Tom Waits").FirstOrDefault() == null) { db.Users.Add(new AsanaUser { Name = "Tom Waits", Email = "*****@*****.**" }); } return(db.SaveChanges()); }
static int AddTask(AsanaContext db) { var task = db.Tasks.Where(t => t.Name == "Make the tea").FirstOrDefault(); if (task == null) { task = db.Tasks.Create(); task.Name = "Make the tea"; task.CreatedAt = DateTime.Now; task.Followers.Add(db.Followers.Add(new Follower { User = db.Users.Where(u => u.Name == "Frank Zappa").FirstOrDefault() })); task.Followers.Add(db.Followers.Add(new Follower { User = db.Users.Where(u => u.Name == "Tom Waits").FirstOrDefault() })); db.Tasks.Add(task); } return(db.SaveChanges()); }