Esempio n. 1
0
 public void UpdateTask(Task task)
 {
     using (SqlConnection cn = new SqlConnection(_connectionString))
     {
         cn.Open();
         cn.Execute("update Tasks set TaskName = @TaskName, PromptForDetails = @PromptForDetails where TaskID = @TaskID",
                        new { task.TaskName, task.PromptForDetails, task.TaskID });
         cn.Close();
     }
 }
Esempio n. 2
0
 public void CreateTask(Task task)
 {
     using (SqlConnection cn = new SqlConnection(_connectionString))
     {
         cn.Open();
         cn.Execute("insert into Tasks (TaskName, PromptForDetails) values (@TaskName, @PromptForDetails)",
             new { task.TaskName, task.PromptForDetails });
         cn.Close();
     }
 }
Esempio n. 3
0
 public ActionResult Edit(Task task)
 {
     try
     {
         new TaskDB().UpdateTask(task);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Esempio n. 4
0
 public ActionResult Delete(Task task)
 {
     try
     {
         new TaskDB().DeleteTask(task);
         return RedirectToAction("Index");
     }
     catch (Exception e)
     {
         ViewBag.ErrorText = e.Message;
         return View(task);
     }
 }
Esempio n. 5
0
        public ActionResult Create(Task task)
        {
            try
            {
                new TaskDB().CreateTask(task);

                return RedirectToAction("Index");
            }
            catch
            {
                return View(task);
            }
        }
Esempio n. 6
0
        public void DeleteTask(Task task)
        {
            using (SqlConnection cn = new SqlConnection(_connectionString))
            {
                cn.Open();

                //check to make sure the task is not used.
                if (cn.Query("select * from TaskLogEntries where TaskID = @TaskID", new { task.TaskID }).Any())
                {
                    cn.Close();
                    throw new Exception(String.Format("Unable to delete the task, {0} because it is used by task log entries.", task.TaskName));
                }

                //delete the task
                cn.Execute("delete from Tasks where TaskID = @TaskID", new { task.TaskID });
                cn.Close();
            }
        }