Ejemplo n.º 1
0
 public User GetByEmail(string email)
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         return(context.Users.FirstOrDefault(u => u.EmailAddress == email));
     }
 }
Ejemplo n.º 2
0
        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();
            //}
        }
Ejemplo n.º 3
0
 public void SetCompleted(int taskId)
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         context.ExecuteCommand("UPDATE Tasks SET IsCompleted = 1 WHERE Id = {0}", taskId);
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
 public void AddTask(Task task)
 {
     using (var context = new SharedTasksDataContext(_connectionstring))
     {
         context.Tasks.InsertOnSubmit(task);
         context.SubmitChanges();
     }
 }
Ejemplo n.º 6
0
 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());
     }
 }