예제 #1
0
 public User GetByEmail(string email)
 {
     using (var context = new TaskItemsContext(_connectionString))
     {
         return(context.Users.FirstOrDefault(u => u.Email == email));
     }
 }
예제 #2
0
 public TaskItem GetById(int id)
 {
     using (var context = new TaskItemsContext(_connectionString))
     {
         return(context.TaskItems.Include(t => t.User).FirstOrDefault(i => i.Id == id));
     }
 }
예제 #3
0
 public IEnumerable <TaskItem> GetActiveTasks()
 {
     using (var context = new TaskItemsContext(_connectionString))
     {
         return(context.TaskItems.Include(t => t.User)
                .Where(t => !t.IsCompleted).ToList());
     }
 }
예제 #4
0
 public void AddTask(TaskItem task)
 {
     using (var context = new TaskItemsContext(_connectionString))
     {
         context.TaskItems.Add(task);
         context.SaveChanges();
     }
 }
예제 #5
0
 public void SetCompleted(int taskId)
 {
     using (var context = new TaskItemsContext(_connectionString))
     {
         context.Database.ExecuteSqlCommand(
             "UPDATE TaskItems SET IsCompleted = 1 WHERE Id = @taskId",
             new SqlParameter("@taskId", taskId));
     }
 }
예제 #6
0
 public void SetDoing(int taskId, int userId)
 {
     using (var context = new TaskItemsContext(_connectionString))
     {
         context.Database.ExecuteSqlCommand(
             "UPDATE TaskItems SET HandledBy = @userId WHERE Id = @taskId",
             new SqlParameter("@userId", userId),
             new SqlParameter("@taskId", taskId));
     }
 }
예제 #7
0
        public void AddUser(User user, string password)
        {
            user.PasswordHash = PasswordHelper.HashPassword(password);

            using (var context = new TaskItemsContext(_connectionString))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }