public void AddUser(User user) { var retrievedDep = _db.Departments.FirstOrDefault(d => d.DepartmentId == user.DepartmentId); if (retrievedDep != null) { _db.Users.Add(user); _db.SaveChanges(); } }
public async Task FilterWebPagesAsync() { // Arrange var options = new DbContextOptionsBuilder <WorkDbContext>() .UseInMemoryDatabase(databaseName: "FindSearches") .Options; // Act using (var context = new WorkDbContext(options)) { context.WebPages.Add(new WebPageEntity("My cat", "AAA", "AAA", "AAA", "Google")); context.WebPages.Add(new WebPageEntity("Her cats", "AAA", "AAA", "AAA", "Yandex")); context.WebPages.Add(new WebPageEntity("His dogs", "AAA", "AAA", "AAA", "Bing")); context.SaveChanges(); } // Assert using (var context = new WorkDbContext(options)) { var sut = new WebPageService(context); var result = await sut.GetWebPagesAsync("cat"); Assert.AreEqual(2, result.Count); } }
public void Save() { _Context.SaveChanges(); }
public void AddDepartment(Department department) { _db.Departments.Add(department); _db.SaveChanges(); }