public User GetByEmail(string email)
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         return(context.Users.FirstOrDefault(u => u.EmailAddress == email));
     }
 }
        public void AddUser(User user, string password)
        {
            string salt         = PasswordHelper.GenerateSalt();
            string passwordHash = PasswordHelper.HashPassword(password, salt);

            user.PasswordSalt = salt;
            user.PasswordHash = passwordHash;
            using (var context = new SharedTasksDataContext(_connectionstring))
            {
                context.Users.InsertOnSubmit(user);
                context.SubmitChanges();
            }

            //using (var connection = new SqlConnection(_connectionstring))
            //using (var command = connection.CreateCommand())
            //{
            //    command.CommandText = "INSERT INTO [User](FirstName, LastName, EmailAddress, PasswordHash, PasswordSalt)" +
            //        " VALUES (@firstname, @lastname, @emailAddress, @passwordHash, @passwordSalt)";
            //    command.Parameters.AddWithValue("@firstname", user.FirstName);
            //    command.Parameters.AddWithValue("@lastname", user.LastName);
            //    command.Parameters.AddWithValue("@EmailAddress", user.EmailAddress);
            //    command.Parameters.AddWithValue("@passwordHash", passwordHash);
            //    command.Parameters.AddWithValue("@passwordSalt", salt);

            //    connection.Open();
            //    command.ExecuteNonQuery();
            //}
        }
 public void SetCompleted(int taskId)
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         context.ExecuteCommand("UPDATE Tasks SET IsCompleted = 1 WHERE Id = {0}", taskId);
     }
 }
 public void SetDoing(int userId, int taskId)
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         context.ExecuteCommand("UPDATE Tasks SET HandledBy = {0} WHERE Id = {1}", userId, taskId);
     }
 }
 public void AddTask(Task task)
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         context.Tasks.InsertOnSubmit(task);
         context.SubmitChanges();
     }
 }
 public IEnumerable <Task> GetActiveTasks()
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         var loadOptions = new DataLoadOptions();
         loadOptions.LoadWith <Task>(t => t.User);
         context.LoadOptions = loadOptions;
         return(context.Tasks.Where(t => !t.IsCompleted).ToList());
     }
 }