public void Save(TaskItem newTask)
 {
     newTask.User = this.User;
     this.Database.Users.Attach(this.User);
     if (newTask.Id == 0)
     {
         newTask.Created = DateTime.UtcNow;
         this.Database.TaskItems.Add(newTask);
     }
     else
     {
         this.Database.TaskItems.Attach(newTask);
         this.Database.SetAsModified(newTask);
     }
     this.Database.SaveChanges();
 }
        public void Test_TaskService_Add_Get()
        {
            var mockDatabase = CreateDatabaseMock();
            var user = new User() { Name = "Test user", Email = "*****@*****.**", Id = 1 };
            using (var taskService = ServiceFactory.CreateTaskService(user, mockDatabase.Object))
            {
                Assert.IsNotNull(taskService);

                var task = new Two10.TaskList.Model.TaskItem() { Name = "Get milk" };
                taskService.Save(task);
                var task2 = taskService.Get(task.Id);

                Assert.IsNotNull(task2);
                Assert.AreEqual(task, task2);
                Assert.AreEqual(user, task.User, "The service should associate the task with the user");
                Assert.AreEqual(1, taskService.AllTasks().Count());
            }
        }
 public void Put(int id, TaskItem value)
 {
 }
 public void Post(TaskItem value)
 {
 }