예제 #1
0
        public void Update(Guid id, Todo todo)
        {
            Todo UplTodo;

            try
            {
                using (var context = new SqlDatabaseContext(SqlDatabaseContext.ops.dbOptions))
                {
                    UplTodo = context.todos.Find(id);
                }


                using (var context = new SqlDatabaseContext(SqlDatabaseContext.ops.dbOptions))
                {
                    if (UplTodo != null)
                    {
                        todo.Id = id;
                        context.todos.Update(todo);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new Exception("SQL Update error");
            }
        }
예제 #2
0
        public void DeleteById(Guid id)
        {
            Todo DelTodo;

            try
            {
                using (var context = new SqlDatabaseContext(SqlDatabaseContext.ops.dbOptions))
                {
                    DelTodo = context.todos.Find(id);
                }

                using (var context = new SqlDatabaseContext(SqlDatabaseContext.ops.dbOptions))
                {
                    if (DelTodo != null)
                    {
                        context.todos.Remove(DelTodo);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new Exception("SQL Delete error");
            }
        }
예제 #3
0
        public void TryGetTokenDocumentIDsTestInvertedIndexContainsToken()
        {
            var expectedResult = new List <string> {
                "testFile7"
            };
            var newToken = new Token {
                TokenText = "testToken7", Documents = new List <Document>()
            };
            var newDocument = new Document {
                DocumentPath = "testFile7", Tokens = new List <Token>()
            };

            newToken.Documents.Add(newDocument);
            localDatabaseContext.Documents.Add(newDocument);
            localDatabaseContext.Tokens.Add(newToken);
            localDatabaseContext.SaveChanges();
            database.TryGetTokenDocumentIDs("testToken7", out var testResult);
            Assert.Equal(expectedResult, testResult);
        }
예제 #4
0
 public void UpdateDatetime(Guid id, DateTime date)
 {
     try
     {
         using (var context = new SqlDatabaseContext(SqlDatabaseContext.ops.dbOptions))
         {
             Todo tempTodo = new Todo {
                 Id = id
             };
             tempTodo.Date = date;
             context.Entry(tempTodo).Property("Date").IsModified = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         throw new Exception("SQL UpdateDatetime error");
     }
 }
예제 #5
0
        public void Insert(Guid id, string task, string title, DateTime date)
        {
            Todo NewTodo = new Todo
            {
                Id    = id,
                Task  = task,
                Title = title,
                Date  = date
            };

            using (var context = new SqlDatabaseContext(SqlDatabaseContext.ops.dbOptions))
            {
                try
                {
                    context.todos.Add(NewTodo);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    throw new Exception("SQL insert error");
                }
            }
        }
예제 #6
0
 public int Complete()
 {
     return(_dbContext.SaveChanges());
 }