Пример #1
0
        public void addTask(DateTime dueDate, string title, string description, string email)
        {
            if (!isLoggedIn) //User is not logged in
            {
                log.Warn("user is not logged in");
                throw new Exception("user is not logged in");
            }
            Task temp;

            if (description != null)                                                                  //Description isnt null
            {
                temp = new Task(dueDate, title, description, this.taskCounterKey, email, 0, boardId); //Using the construcor with description
            }
            else //Description is null
            {
                temp = new Task(dueDate, title, this.taskCounterKey, email, 0, boardId); //Using the construcor without description
            }
            if (!this.columns[0].addTask(temp))                                          //Task limit reached
            {
                log.Warn("Tasks limit reached");
                throw new Exception("Tasks limit reached");  //Exception is thrown in this class in order to tell if counterKey should be incremented or not
            }
            else //If a task was added
            {
                taskCounterKey++; //Increment because a task was added
                //Updating the database-------------------------------------------------------------------------------
                DataAccessLayer.dataBoardController DBC = new DataAccessLayer.dataBoardController();
                DBC.Update(boardId, "taskCounterKey", taskCounterKey);
            }
        }
Пример #2
0
 public void addColumn(int columnOrdinal, string Name, string email)
 {
     email = email.ToLower();
     if (!isLoggedIn) //User is not logged in
     {
         log.Warn("user is not logged in");
         throw new Exception("user is not logged in");
     }
     if (!this.emailCreator.Equals(email))//only board creator can add column
     {
         log.Warn("only board creator can add column");
         throw new Exception("only board creator can add column");
     }
     foreach (var item in columns) //Checking unique column name
     {
         if (item.Value.getName().Equals(Name))
         {
             log.Warn("Column name already exists");
             throw new Exception("Column name already exists");
         }
     }
     if (columnOrdinal == columnCounterKey) //Adding a column as the last column
     {
         Column toAdd = new Column(Name, columnCounterKey, boardId);
         columns.Add(columnOrdinal, toAdd);
         columnCounterKey++;//Increment because a column was added
         //Updating the database-----------------------------------------------------------------------------------------------
         DataAccessLayer.dataBoardController DBC = new DataAccessLayer.dataBoardController();
         DBC.Update(boardId, "columnCounterKey", columnCounterKey);
     }
     else if (columnOrdinal < columnCounterKey & columnOrdinal >= 0) //Adding a column to the "middle" of the columns
     {
         for (int i = columns.Count - 1; i >= columnOrdinal; i--)    //Moving all columns (that are bigger than coulmnOrdinal) to the right to make room for the new column
         {
             Column temp = columns[i];
             columns.Remove(i);
             temp.setKey(i + 1);
             columns.Add(i + 1, temp);
         }
         Column toAdd = new Column(Name, columnOrdinal, boardId); //Building the new column
         columns.Add(columnOrdinal, toAdd);                       //Adding the new column in the columnOrdinal place
         columnCounterKey++;                                      //Increment because a column was added
         //Updating the database-----------------------------------------------------------------------------------------------
         DataAccessLayer.dataBoardController DBC = new DataAccessLayer.dataBoardController();
         DBC.Update(boardId, "columnCounterKey", columnCounterKey);
     }
     else //Column ordinal is invalid
     {
         log.Warn("invalid column ordinal");
         throw new Exception("invalid column ordinal");
     }
 }
Пример #3
0
        public void removeColumn(int columnOrdinal, string email)
        {
            email = email.ToLower();
            if (!isLoggedIn) //User is not logged in
            {
                log.Warn("user is not logged in");
                throw new Exception("user is not logged in");
            }
            if (!this.emailCreator.Equals(email))
            {
                log.Warn("only board creator can remove column");
                throw new Exception("only board creator can remove column");
            }
            if (columns.Count <= MinNumberOfColumns) //Board has 2 columns left - Cant remove column
            {
                log.Warn("Cant remove this column - Board must have at least 2 columns");
                throw new Exception("Cant remove this column - Board must have at least 2 columns");
            }
            if (columnOrdinal > 0 & columnOrdinal < columnCounterKey)//Removing column from the "middle"
            {
                Column toRemove = columns[columnOrdinal];
                Column backup   = columns[columnOrdinal - 1];

                if (backup.getLimit() != -1 && toRemove.getTasksForColumns().Count + backup.getTasksForColumns().Count > backup.getLimit()) //The column to the left will exceed the limit after removing current column
                {
                    log.Warn("the limit is smaller then the tasks number");
                    throw new Exception("the limit is smaller then the tasks number");
                }
                List <int> listOfKeysToRemove = new List <int>();   //A list to hold all the keys of tasks we want to remove
                foreach (var item in toRemove.getTasksForColumns()) //Adding all tasks keys to the listOfKeysToRemove
                {
                    listOfKeysToRemove.Add(item.getKey());
                }
                foreach (var item in listOfKeysToRemove) //Moving all tasks from the current column to the column to the left
                {
                    Task removedTask = toRemove.removeTask(item);
                    removedTask.setColumnId(backup.getKey());
                    backup.addTask(removedTask);
                }
                columns.Remove(columnOrdinal);
                //deleting the column row from database-----------------------------------------------------------------------
                DataAccessLayer.dataColumnController DCC = new DataAccessLayer.dataColumnController();
                DCC.Delete(boardId, columnOrdinal);
                //------------------------------------------------------------------------------------------------------------
                for (int i = columnOrdinal + 1; i < columnCounterKey; i++)//Moving column to the left to cover the gap
                {
                    Column temp = columns[i];
                    foreach (var item in temp.getTasksForColumns())
                    {
                        item.setColumnId(i - 1);
                    }
                    columns.Remove(i);
                    temp.setKey(i - 1);
                    columns.Add(i - 1, temp);
                }
                columnCounterKey--; //Decrease because a column was removed
                //Updating the database---------------------------------------------------------------------------------------
                DataAccessLayer.dataBoardController DBC = new DataAccessLayer.dataBoardController();
                DBC.Update(this.boardId, "columnCounterKey", columnCounterKey);
            }


            else if (columnOrdinal == 0) //Removing the leftmost column
            {
                Column toRemove = columns[0];
                Column backup   = columns[1];
                if (backup.getLimit() != -1 && toRemove.getTasksForColumns().Count + backup.getTasksForColumns().Count > backup.getLimit())//The column to the right will exceed the limit after removing current column
                {
                    log.Warn("the limit is smaller then the tasks number");
                    throw new Exception("the limit is smaller then the tasks number");
                }
                foreach (var item in toRemove.getTasksForColumns())
                {
                    item.setColumnId(columnOrdinal); //Always set to 0
                    backup.addTask(item);
                }
                columns.Remove(columnOrdinal);
                //deleting the column row from database-----------------------------------------------------------------------
                DataAccessLayer.dataColumnController DCC = new DataAccessLayer.dataColumnController();
                DCC.Delete(boardId, columnOrdinal);
                //------------------------------------------------------------------------------------------------------------
                for (int i = columnOrdinal + 1; i < columnCounterKey; i++) //i always starts from 1
                {
                    Column temp = columns[i];
                    foreach (var item in temp.getTasksForColumns())
                    {
                        item.setColumnId(i - 1);
                    }
                    columns.Remove(i);
                    temp.setKey(i - 1);
                    columns.Add(i - 1, temp);
                }
                columnCounterKey--;//Decrease because a column was removed
                //Updating the database---------------------------------------------------------------------------------------
                DataAccessLayer.dataBoardController DBC = new DataAccessLayer.dataBoardController();
                DBC.Update(this.boardId, "columnCounterKey", columnCounterKey);
            }

            else //Invalid column ordinal
            {
                log.Warn("invalid column ordinal");
                throw new Exception("invalid column ordinal");
            }
        }