Exemplo n.º 1
0
 /// <summary>
 /// Update a task using
 /// </summary>
 public bool Update(Task updatedTask)
 {
     using (var context = new KsigDoContext())
     {
         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.All.taskUpdated(oldTask);
                 return true;
             }
         }
         catch (Exception ex)
         {
             Clients.Caller.reportError("Unable to update task. Make sure title length is between 10 and 140");
             return false;
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// To get all the tasks up on init
 /// </summary>
 public void GetAll()
 {
     using (var context = new KsigDoContext())
     {
         var res = context.Tasks.ToArray();
         Clients.Caller.taskAll(res);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Delete the task
 /// </summary>
 public bool Remove(int taskId)
 {
     try
     {
         using (var context = new KsigDoContext())
         {
             var task = context.Tasks.FirstOrDefault(t => t.taskId == taskId);
             context.Tasks.Remove(task);
             context.SaveChanges();
             Clients.All.taskRemoved(task.taskId);
             return true;
         }
     }
     catch (Exception ex)
     {
         Clients.Caller.reportError("Error : " + ex.Message);
         return false;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Our method to create a task
 /// </summary>
 public bool Add(Task newTask)
 {
     try
     {
         using (var context = new KsigDoContext())
         {
             var task = context.Tasks.Create();
             task.title = newTask.title;
             task.completed = newTask.completed;
             task.lastUpdated = DateTime.Now;
             context.Tasks.Add(task);
             context.SaveChanges();
             Clients.All.taskAdded(task);
             return true;
         }
     }
     catch (Exception ex)
     {
         Clients.Caller.reportError("Unable to create task. Make sure title length is between 10 and 140");
         return false;
     }
 }
Exemplo n.º 5
0
        void InitDatabase()
        {
            Database.SetInitializer<KsigDoContext>(new DropCreateDatabaseIfModelChanges<KsigDoContext>());

            using (var context = new KsigDoContext()) {
                if (context.Tasks.Count() == 0) {
                    context.Tasks.Add
                        (
                        new Task() {
                            title = "Need to buy my milk",
                            lastUpdated = DateTime.Now,
                        }
                    );

                    context.Tasks.Add
                        (
                        new Task() {
                            title = "Call my wife",
                            lastUpdated = DateTime.Now,
                        }
                    );
                }
            }
        }