Пример #1
0
        void InitDatabase()
        {
            Database.SetInitializer<TestContext>(new DropCreateDatabaseIfModelChanges<TestContext>());

            using (var context = new TestContext())
            {
                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,
                        }
                    );
                }
            }
        }
Пример #2
0
 public void GetAllCategories()
 {
     using (var context = new TestContext())
     {
         var res = context.Categories.ToArray();
         Caller.taskAll(res);
     }
 }
Пример #3
0
        /// <summary>
        /// To get all the tasks up on init
        /// </summary>
        public void GetAll()
        {
            using (var context = new TestContext())
            {
                //var res = context.Tasks.Include(ToArray();
                var res = context.Tasks.Include(x=>x.Category).ToArray();

                //var temp = context.Categories
                //    .Include(x => x.Tasks);

                //var temp2 = (from i in temp
                //       select i.Tasks);
                //var blah = temp.ToArray();
                //var res = temp2.ToArray();
                //var res = from item in context.Tasks.Include()
                Caller.taskAll(res);
            }
        }
Пример #4
0
 /// <summary>
 /// Delete the task
 /// </summary>
 public bool Remove(int taskId)
 {
     try
     {
         using (var context = new TestContext())
         {
             var task = context.Tasks.FirstOrDefault(t => t.taskId == taskId);
             context.Tasks.Remove(task);
             context.SaveChanges();
             Clients.taskRemoved(task.taskId);
             return true;
         }
     }
     catch (Exception ex)
     {
         Caller.reportError("Error : " + ex.Message);
         return false;
     }
 }
Пример #5
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;
     }
 }
Пример #6
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;
         }
     }
 }