Example #1
0
 /// <summary>
 /// Removing an exists column from the board!
 /// WE musts have minimum 2 columns on the board! so if the NumberOfColumns equals to 2 throws an error!
 /// All the tasks are moved to the neighbor column but only if the neighbor coloum has limit > NumOfHisTasks + NumOfOtherTasks
 /// </summary>
 /// <param name="columnID"> unique id for the column to be moved! </param>
 public void removeColumn(int columnID) // 0 (1) 2
 {
     taskDalController   = new DataAccess_Layer.TaskDalController();
     columnDalController = new DataAccess_Layer.ColumnDalController();
     if (columnID < 0 || columnID >= boardColumns.Count || boardColumns.Count == 2)
     {
         throw new Exception("Board must have minmum of 2 columns!");
     }
     if (columnID == 0)
     {
         if (!(getColumnById(1).getLimit() == -1) && getColumnById(1).getNumberOfTasks() + getColumnById(0).getNumberOfTasks() > getColumnById(1).getLimit())
         {
             throw new Exception("Couldnt remove the column!");
         }
         foreach (Task t in getColumnById(columnID).getTasks())
         {
             taskDalController.Delete(t.ToDalObject());
             boardColumns[1].addTask(t, t.getId());
         }
     }
     else
     {
         if (!(getColumnById(columnID - 1).getLimit() == -1) && getColumnById(columnID - 1).getNumberOfTasks() + getColumnById(columnID).getNumberOfTasks() > getColumnById(columnID - 1).getLimit())
         {
             throw new Exception("Couldnt remove the column!");
         }
         foreach (Task t in getColumnById(columnID).getTasks())
         {
             taskDalController.Delete(t.ToDalObject());
             boardColumns[columnID - 1].addTask(t, t.getId());
         }
     }
     columnDalController.Delete(getColumnById(columnID).ToDalObject());
     //Shifting columns back.
     for (int i = columnID + 1; i < boardColumns.Count; i++)
     {
         boardColumns.ElementAt(i).columnID--; // done id = 1
         boardColumns.ElementAt(i).Save();
     }
     boardColumns.RemoveAt(columnID);
     Save();//Saving board due to columns decrement.
 }
Example #2
0
        /// <summary>
        /// Helper function to achive an important requirement!
        /// Removing an existing task from the column!
        /// </summary>
        /// <param name="taskId"> Task unique Id to be removed! </param>
        public void RemoveTask(int taskId)
        {
            int  index = 0;
            bool temp  = false;

            for (int i = 0; i < Tasks.Count && !temp; i++)
            {
                if (Tasks[i].getId() == taskId)
                {
                    temp  = true;
                    index = i;
                }
            }
            if (!temp)
            {
                log.Warn("No such task with the given Id!");
                throw new Exception("No such task with the given Id!");
            }
            taskDalController.Delete(Tasks.ElementAt(index).ToDalObject());//Deleting task.
            Tasks.RemoveAt(index);
            NumberOfTasks--;
            Save();//Saving column.
        }