Exemple #1
0
        public void TestAddTask()
        {
            YouCompleteMe.Models.Task task = new YouCompleteMe.Models.Task();
            task.completed     = false;
            task.createdDate   = DateTime.Now;
            task.currentDate   = DateTime.Now;
            task.deadline      = DateTime.Now;
            task.taskType      = 2;
            task.task_owner    = 8;
            task.task_priority = 2;
            task.title         = "use for test unit test";

            int  taskID = TaskController.AddTask(task);
            Task result = TaskController.getATask(taskID);

            Assert.AreEqual(taskID, result.taskID);
        }
Exemple #2
0
        /*
         * This method use for add task into database.
         * It return the task id of new task.
         */
        public static int AddTask(YouCompleteMe.Models.Task task)
        {
            SqlConnection connection = DBConnection.GetConnection();

            connection.Open();
            //SqlTransaction sqlTransaction = connection.BeginTransaction();
            string insertStatement =
                "INSERT tasks " +
                "(task_owner, taskType, title, createdDate, currentDate, deadline, task_priority, completed, isMeeting) " +
                "VALUES (@task_owner, @taskType, @title, @createdDate, @currentDate, @deadline, @task_priority, @completed, @meeting)";
            SqlCommand insertCommand = new SqlCommand(insertStatement, connection);

            insertCommand.Parameters.AddWithValue("@task_owner", task.task_owner);
            insertCommand.Parameters.AddWithValue("@title", task.title);
            insertCommand.Parameters.AddWithValue("@createdDate", task.createdDate);
            insertCommand.Parameters.AddWithValue("@currentDate", task.currentDate);
            if (task.deadline == DateTime.MaxValue)
            {
                insertCommand.Parameters.AddWithValue("@deadline", DBNull.Value);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@deadline", task.deadline);
            }
            if (task.task_priority == -1)
            {
                insertCommand.Parameters.AddWithValue("@task_priority", DBNull.Value);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@task_priority", task.task_priority);
            }
            insertCommand.Parameters.AddWithValue("@completed", task.completed);
            insertCommand.Parameters.AddWithValue("@taskType", task.taskType);
            insertCommand.Parameters.AddWithValue("@meeting", task.isMeeting);
            try
            {
                insertCommand.ExecuteNonQuery();
                string selectStatement =
                    "SELECT IDENT_CURRENT('tasks') FROM tasks";
                SqlCommand selectCommand = new SqlCommand(selectStatement, connection);//, sqlTransaction);
                int        taskID        = Convert.ToInt32(selectCommand.ExecuteScalar());
                if (task.note != "")
                {
                    string insertNoteStatement = "INSERT note " +
                                                 "(taskID, subtaskID, note_message) " +
                                                 "VALUES (@taskID, @subtaskID, @note_message)";
                    SqlCommand insertNoteCommand = new SqlCommand(insertNoteStatement, connection);//, sqlTransaction);
                    insertNoteCommand.Parameters.AddWithValue("@taskID", taskID);
                    insertNoteCommand.Parameters.AddWithValue("@note_message", task.note);
                    insertNoteCommand.Parameters.AddWithValue("@subtaskID", DBNull.Value);
                    insertNoteCommand.ExecuteNonQuery();
                }
                //sqlTransaction.Commit();
                return(taskID);
            }
            catch (SqlException ex)
            {
                //sqlTransaction.Rollback();
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
 public static int AddTask(YouCompleteMe.Models.Task task)
 {
     return(TaskDAL.AddTask(task));
 }