public bool AddNewTask(Task task) { List<string> to = new List<string>(); foreach (Faculty f in task.AssignedTo) { to.Add(f.EmailID); } Communication.Sendmail("*****@*****.**", task.Name, to, "You have been assigned a task by " + task.AssignedBy.Name, task.Description + "<br/>" + "The deadline for this task is: <b>" + task.EndDate.ToString("dd-MMMM-yy") + "</b>"); return repository.AddNewTask(task); }
/// <summary> /// This method gets all the tasks that are assigned to the faculty based on the id of the faculty. /// </summary> /// <param name="facultyID">An integer parameter containing the ID of the faculty.</param> /// <returns>It returns a dictionary of tasks assigned to the faculty along with the status of each task.</returns> public Dictionary<Task, TaskStatusType> GetAllTasksAssignedToAFaculty(int facultyID) { SqlParameter FacultyID = new SqlParameter("facultyID", facultyID); List<SqlParameter> parameterCollection = new List<SqlParameter>(){FacultyID}; DataTable taskTable = new DataTable(); using(DBDataHelper helper = new DBDataHelper()) { taskTable = helper.GetDataTable("dbo.GetAllTasksAssignedToAFaculty", SQLTextType.Stored_Proc, parameterCollection); } //List<Task> tasks = new List<Task>(); Dictionary<Task, TaskStatusType> tasks = new Dictionary<Task, TaskStatusType>(); foreach (DataRow row in taskTable.Rows) { Task task = new Task() { ID = int.Parse(row["TaskID"].ToString()), Name = row["Name"].ToString(), Priority = (PriorityType)(Enum.Parse(typeof(PriorityType), row["PriorityID"].ToString())), StartDate = DateTime.Parse(row["StartDate"].ToString()), EndDate = DateTime.Parse(row["EndDate"].ToString()), Description = row["Description"].ToString(), Type = (TaskType)(Enum.Parse(typeof(TaskType), row["TaskTypeID"].ToString())) }; TaskStatusType taskStatus = (TaskStatusType)(Enum.Parse(typeof(TaskStatusType),row["TaskStatusID"].ToString())); DataTable table = new DataTable(); SqlParameter HODID = new SqlParameter("ID",row["HODID"]); List<SqlParameter> collection = new List<SqlParameter>(){HODID}; using(DBDataHelper helper = new DBDataHelper()) { table = helper.GetDataTable("dbo.GetFacultyByID", SQLTextType.Stored_Proc, collection); } HOD hod = new HOD() { ID = int.Parse(table.Rows[0]["FacultyID"].ToString()), Name = table.Rows[0]["Name"].ToString(), EmailID = table.Rows[0]["EmailID"].ToString(), Designation = DesignationType.HOD, Department = (DepartmentType)(Enum.Parse(typeof(DepartmentType),table.Rows[0]["DepartmentID"].ToString())), ImageURL = table.Rows[0]["ImageURL"].ToString(), ContactNo = table.Rows[0]["ContactNo"].ToString() }; task.AssignedBy = hod; task.AssignedTo = GetAllFacultiesHavingTheTask(task.ID); tasks.Add(task,taskStatus); } return tasks; }
/// <summary> /// This method assigns the task to different persons. /// </summary> /// <param name="task">An object of type Task containing the details of the task.</param> /// <returns>It returns true if the task is successfully assigned to all the persons.</returns> public bool AssignTaskToFaculties(Task task) { DataTable table = new DataTable("data"); table.Columns.Add("TaskID"); table.Columns.Add("PersonID"); table.Columns.Add("TaskStatusID"); foreach (Faculty faculty in task.AssignedTo) { table.Rows.Add(new object[] { task.ID, faculty.ID, 1 }); } int result = 0; SqlParameter TaskFacultiesTVP = new SqlParameter("TaskFacultiesTVP", table); TaskFacultiesTVP.SqlDbType = SqlDbType.Structured; List<SqlParameter> parameterCollection = new List<SqlParameter>() { TaskFacultiesTVP }; using (DBDataHelper helper = new DBDataHelper()) { result = helper.GetRowsAffected("dbo.AssignTaskToFaculties", SQLTextType.Stored_Proc, parameterCollection); } if (result > 0) return true; else return false; }
/// <summary> /// Adds a new task to the database and assigns the task to different persons. /// </summary> /// <param name="task">An object of Task class containing the details about the task.</param> /// <returns>It returns true if the task is added and assigned successfully.</returns> public bool AddNewTask(Task task) { SqlParameter Name = new SqlParameter("name", task.Name); SqlParameter Description = new SqlParameter("description", task.Description); SqlParameter StartDate = new SqlParameter("startDate", task.StartDate); SqlParameter EndDate = new SqlParameter("endDate", task.EndDate); SqlParameter HODID = new SqlParameter("hodID", task.AssignedBy.ID); SqlParameter PriorityID = new SqlParameter("priorityID", (int)task.Priority); SqlParameter TaskTypeID = new SqlParameter("TaskTypeID", (int)task.Type); SqlParameter TaskID = new SqlParameter("id", SqlDbType.Int); TaskID.Direction = ParameterDirection.Output; TaskID.Size = 50; SqlParameter ReminderTime = new SqlParameter("reminderTime", task.ReminderTime); List<SqlParameter> parameterCollection = new List<SqlParameter>() { Name,Description,StartDate,EndDate,HODID,PriorityID,TaskTypeID,TaskID,ReminderTime }; using (DBDataHelper helper = new DBDataHelper()) { helper.ExecSQL("dbo.AddNewTask", SQLTextType.Stored_Proc, parameterCollection); } task.ID = int.Parse(TaskID.SqlValue.ToString()); return AssignTaskToFaculties(task); }
//public List<string> GetAllPriotities() //{ // DataTable priorityDataTable = new DataTable(); // List<string> priorities = new List<string>(); // using (DBDataHelper helper = new DBDataHelper()) // { // priorityDataTable = helper.GetDataTable("dbo.GetAllPriorities", SQLTextType.Stored_Proc); // } // foreach (DataRow row in priorityDataTable.Rows) // { // priorities.Add(row["Priority"].ToString()); // } //} public List<Task> GetSemesterTasks(int hodID) { SqlParameter HodID = new SqlParameter("hodID", hodID); List<SqlParameter> parameterCollection = new List<SqlParameter> { HodID }; DataTable table = new DataTable(); List<Task> tasks = new List<Task>(); using (DBDataHelper helper = new DBDataHelper()) { table = helper.GetDataTable("dbo.GetSemesterTasks", SQLTextType.Stored_Proc, parameterCollection); } foreach (DataRow row in table.Rows) { Task t = new Task { ID = int.Parse(row["TaskID"].ToString()), Name = row["Name"].ToString(), Description = row["Description"].ToString(), StartDate = DateTime.Parse(row["StartDate"].ToString()), EndDate = DateTime.Parse(row["EndDate"].ToString()), Priority = (PriorityType)(Enum.Parse(typeof(PriorityType), row["PriorityID"].ToString())), Type = (TaskType)(Enum.Parse(typeof(TaskType), row["TaskTypeID"].ToString())), ReminderTime = int.Parse(row["ReminderTime"].ToString()) }; t.AssignedTo = GetAllFacultiesHavingTheTask(t.ID); tasks.Add(t); } return tasks; }
/// <summary> /// This method gets all the tasks assigned by a HOD alongwith all the faculties who have been assigned that task and their task status. /// </summary> /// <param name="hodID">An integer parameter containing the id of the HOD.</param> /// <returns>It returns a list of tasks given by a hod.</returns> public List<Task> GetAllTasksAssignedByAHOD(int hodID) { SqlParameter HodID = new SqlParameter("hodID", hodID); List<SqlParameter> parameterCollection = new List<SqlParameter> { HodID }; DataTable table = new DataTable(); List<Task> tasks = new List<Task>(); using (DBDataHelper helper = new DBDataHelper()) { table = helper.GetDataTable("dbo.GetAllTasksAssignedByAHOD", SQLTextType.Stored_Proc, parameterCollection); } foreach (DataRow row in table.Rows) { Task t = new Task { ID = int.Parse(row["TaskID"].ToString()), Name = row["Name"].ToString(), Description = row["Description"].ToString(), StartDate = DateTime.Parse(row["StartDate"].ToString()), EndDate = DateTime.Parse(row["EndDate"].ToString()), Priority = (PriorityType)(Enum.Parse(typeof(PriorityType), row["PriorityID"].ToString())), Type = (TaskType)(Enum.Parse(typeof(TaskType), row["TaskTypeID"].ToString())), ReminderTime = int.Parse(row["ReminderTime"].ToString()) }; t.AssignedTo = GetAllFacultiesHavingTheTask(t.ID); for (int i = 0; i < t.AssignedTo.Count; i++) { TaskStatusType status = new TaskStatusType(); SqlParameter TaskID = new SqlParameter("taskID", t.ID); SqlParameter FacultyID = new SqlParameter("facultyID", t.AssignedTo[i].ID); List<SqlParameter> col = new List<SqlParameter> { TaskID, FacultyID }; using (DBDataHelper helper = new DBDataHelper()) { status = (TaskStatusType)(Enum.Parse(typeof(TaskStatusType), helper.GetDataTable("dbo.GetTaskStatus", SQLTextType.Stored_Proc, col).Rows[0]["TaskStatusID"].ToString())); } Dictionary<Task, TaskStatusType> abc = new Dictionary<Task, TaskStatusType>(); abc.Add(t, status); t.AssignedTo[i].Tasks = abc; } tasks.Add(t); } return tasks; }
public bool AssignTaskToFaculties(Task task) { return repository.AssignTaskToFaculties(task); }