Exemplo n.º 1
0
 /// <summary>
 /// Our method to create a task
 /// </summary>
 public bool Add(Task newTask)
 {
     try
     {
         using (var context = new TestContext())
         {
             var task = context.Tasks.Create();
             task.title = newTask.title;
             task.completed = newTask.completed;
             task.lastUpdated = DateTime.Now;
             context.Tasks.Add(task);
             context.SaveChanges();
             Clients.taskAdded(task);
             return true;
         }
     }
     catch (Exception ex)
     {
         Caller.reportError("Unable to create task. Make sure title length is between 10 and 140");
         return false;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Update a task using
 /// </summary>
 public bool Update(Task updatedTask)
 {
     using (var context = new TestContext())
     {
         var oldTask = context.Tasks.FirstOrDefault(t => t.taskId == updatedTask.taskId);
         try
         {
             if (oldTask == null)
                 return false;
             else
             {
                 oldTask.title = updatedTask.title;
                 oldTask.completed = updatedTask.completed;
                 oldTask.lastUpdated = DateTime.Now;
                 context.SaveChanges();
                 Clients.taskUpdated(oldTask);
                 return true;
             }
         }
         catch (Exception ex)
         {
             Caller.reportError("Unable to update task. Make sure title length is between 10 and 140");
             return false;
         }
     }
 }