コード例 #1
0
        public void AddUser(User user)
        {
            var retrievedDep = _db.Departments.FirstOrDefault(d => d.DepartmentId == user.DepartmentId);

            if (retrievedDep != null)
            {
                _db.Users.Add(user);
                _db.SaveChanges();
            }
        }
コード例 #2
0
ファイル: DataAccessTests.cs プロジェクト: e0gen/MultiSearch
        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);
            }
        }
コード例 #3
0
 public void Save()
 {
     _Context.SaveChanges();
 }
コード例 #4
0
 public void AddDepartment(Department department)
 {
     _db.Departments.Add(department);
     _db.SaveChanges();
 }