Esempio n. 1
0
 public bool Update(User user)
 {
     using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
     {
         return(linqToDbTodoDatabase.Update(userMapper.Map <LinqToDbUser>(user)) > 0);
     }
 }
Esempio n. 2
0
 public long Create(User user)
 {
     using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
     {
         return(linqToDbTodoDatabase.InsertWithInt64Identity(userMapper.Map <LinqToDbUser>(user)));
     }
 }
Esempio n. 3
0
 public bool Update(TodoItem todoItem)
 {
     using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
     {
         return(linqToDbTodoDatabase.Update(mapper.Map <LinqToDbTodoItem>(todoItem)) > 0);
     }
 }
Esempio n. 4
0
 public IEnumerable <TodoItem> ReadAll()
 {
     using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
     {
         return(mapper.Map <IEnumerable <TodoItem> >(linqToDbTodoDatabase.TodoItems));
     }
 }
Esempio n. 5
0
 public TodoItem Read(long id)
 {
     using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
     {
         return(mapper.Map <TodoItem>(linqToDbTodoDatabase.TodoItems.Where(t => t.Id == id).FirstOrDefault()));
     }
 }
Esempio n. 6
0
 public bool Delete(long id)
 {
     using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
     {
         return(linqToDbTodoDatabase.TodoItems.Where(t => t.Id == id).Delete() > 0);
     }
 }
Esempio n. 7
0
 public long Create(TodoItem todoItem)
 {
     using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
     {
         var mappedItem = mapper.Map <LinqToDbTodoItem>(todoItem);
         return(linqToDbTodoDatabase.InsertWithInt64Identity(mappedItem));
     }
 }
Esempio n. 8
0
        public IEnumerable <User> ReadAll()
        {
            using (var transaction = new TransactionScope())
            {
                using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
                {
                    var userList     = linqToDbTodoDatabase.Users.ToList();
                    var todoItemList = linqToDbTodoDatabase.TodoItems.ToList();

                    transaction.Complete();

                    return(userMapper.Map <IEnumerable <User> >(userList.Select(user => SelectTodoItems(user, todoItemList))));
                }
            }
        }
Esempio n. 9
0
        public bool Delete(long id)
        {
            using (var transaction = new TransactionScope())
            {
                using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
                {
                    linqToDbTodoDatabase.TodoItems.Where(t => t.User_Id == id).Delete();
                    var affectedRows = linqToDbTodoDatabase.Users.Where(u => u.Id == id).Delete();

                    transaction.Complete();

                    return(affectedRows > 0);
                }
            }
        }
Esempio n. 10
0
        public User Read(long id)
        {
            using (var transaction = new TransactionScope())
            {
                using (var linqToDbTodoDatabase = new LinqToDbTodoDatabase(dbConfigurationName))
                {
                    var user = linqToDbTodoDatabase.Users.Where(u => u.Id == id).FirstOrDefault();

                    if (user != null)
                    {
                        user.TodoItems = linqToDbTodoDatabase.TodoItems.Where(t => t.User_Id == id).ToList();
                    }

                    transaction.Complete();

                    return(userMapper.Map <User>(user));
                }
            }
        }