public void AddNewsFeed(Models.NewsFeed newsFeed) { var entry = _context.Entry(newsFeed); entry.State = EntityState.Added; _context.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,Name,Birthday")] Profile profile) { if (ModelState.IsValid) { profile.Id = Guid.NewGuid(); db.Profiles.Add(profile); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(profile)); }
public void AddCategory(Category category) { var entry = _context.Entry(category); entry.State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); }
private void SetUpClient() { var builder = new WebHostBuilder() .UseStartup <Startup>() .ConfigureServices(services => { var context = new NewsFeedContext(new DbContextOptionsBuilder <NewsFeedContext>() .UseSqlite("DataSource=:memory:") .EnableSensitiveDataLogging() .Options); services.RemoveAll(typeof(NewsFeedContext)); services.AddSingleton(context); context.Database.OpenConnection(); context.Database.EnsureCreated(); context.SaveChanges(); // Clear local context cache foreach (var entity in context.ChangeTracker.Entries().ToList()) { entity.State = EntityState.Detached; } }); _server = new TestServer(builder); Client = _server.CreateClient(); }
public object Put(int id, bool subscribe) { NewsFeedContext db = new NewsFeedContext(); NewsFeedProvider provider = db.NewsFeedProviders.Where(prov => prov.Id == id).Single(); provider.isSubscribed = subscribe; db.SaveChanges(); return(db.NewsFeedProviders); }
public static void Initialize(NewsFeedContext context) { // context.Database.EnsureDeleted(); context.Database.EnsureCreated(); //Look for any News. if (context.News.Any()) { return; // DB has been seeded } var user1 = new UserInfo { UserEmail = "*****@*****.**", UserName = "******" }; var students = new News[] { new News { Message = "I hope you will have nice experience. All the best :)", DateCreated = DateTime.Now, UserInfo = user1 }, new News { Message = "Identity server with External Google Identity System using OIDC.", DateCreated = DateTime.Now, UserInfo = user1 }, new News { Message = "Login before posting news items and mark your identity in the News Feed world.", DateCreated = DateTime.Now, UserInfo = user1 }, new News { Message = "These posts are in datecreated order.!!", DateCreated = DateTime.Now, UserInfo = user1 }, new News { Message = "This is message from system administrator. Click my name below and send me an email.", DateCreated = DateTime.Now, UserInfo = user1 }, new News { Message = "Welcome to the Judges!!", DateCreated = DateTime.Now, UserInfo = user1 }, }; foreach (News s in students) { context.News.Add(s); } context.SaveChanges(); }
public void Save() { _context.SaveChanges(); }