Exemplo n.º 1
0
        }//empty constructor

        public Board(string emailCreator, int boardId) //Default constructor
        {
            this.boardId       = boardId;
            this.assignedUsers = new List <string>();
            this.assignedUsers.Add(emailCreator);
            columnCounterKey  = 0;
            columns           = new Dictionary <int, Column>();
            this.isLoggedIn   = false;                                               //Board is not logged in until user logged in
            this.emailCreator = emailCreator;
            Column columnBackLog = new Column("backlog", columnCounterKey, boardId); //Default first column

            columnCounterKey++;
            Column columnInProgress = new Column("in progress", columnCounterKey, boardId); //Default second column

            columnCounterKey++;
            Column columnDone = new Column("done", columnCounterKey, boardId);//Default third column

            columnCounterKey++;
            columns.Add(0, columnBackLog);
            columns.Add(1, columnInProgress);
            columns.Add(2, columnDone);
            taskCounterKey = 0; //Initialize taskCounterKey with 0 because no tasks were added yet


            //Inserting to database------------------------------------------------------------------------
            DataAccessLayer.dataBoardController DBC = new DataAccessLayer.dataBoardController();
            DBC.Insert(this.toDalObject());
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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");
     }
 }
Exemplo n.º 4
0
        public void loadata()
        {
            if (users.Count == 0) //Cant load data before deleting it
            {
                DataAccessLayer.dataBoardController  boardController  = new DataAccessLayer.dataBoardController();
                DataAccessLayer.dataTaskController   taskController   = new DataAccessLayer.dataTaskController();
                DataAccessLayer.dataColumnController columnController = new DataAccessLayer.dataColumnController();
                DataAccessLayer.dataUserController   UserController   = new DataAccessLayer.dataUserController();
                //Loading from database to dal objects
                List <DataAccessLayer.dataBoard>  allBoards  = boardController.SelectAllBoards();
                List <DataAccessLayer.dataTask>   allTasks   = taskController.SelectAllTasks();
                List <DataAccessLayer.dataColumn> allColumns = columnController.SelectAllColumns();
                List <DataAccessLayer.dataUser>   allUsers   = UserController.SelectAllUsers();
                List <Board> boards = new List <Board>();

                foreach (var dataUser in allUsers)
                {
                    Board busBoard = null;
                    foreach (var dataBoard in allBoards)
                    {
                        if (dataUser.email.Equals(dataBoard.emailCreator)) //Only add the board created by the user
                        {
                            Dictionary <int, Column> busColumns = new Dictionary <int, Column>();
                            foreach (var dataColumn in allColumns)
                            {
                                if (dataColumn.boardId == dataBoard.boardId)
                                {
                                    List <Task> busTasks = new List <Task>();
                                    foreach (var dataTask in allTasks)
                                    {
                                        if (dataTask.column == dataColumn.ordinal & dataColumn.boardId == dataTask.boardId) //Only add the tasks that match the correct column
                                        {
                                            busTasks.Add(new Task(dataTask));                                               //adding to task list business task which is the copy of the data task
                                        }
                                    }
                                    Column busColumn = new Column(dataColumn, busTasks);
                                    busColumns.Add(busColumn.getKey(), busColumn);
                                }
                            }
                            busBoard = new Board(dataBoard, busColumns);
                            boards.Add(busBoard);
                        }
                    }
                    User busUser = new User(dataUser, busBoard);
                    users.Add(busUser.getEmail(), busUser);
                }

                foreach (var user in users)
                {
                    if (user.Value.getBoard() == null) //A user that is not a board creator
                    {
                        foreach (var board in boards)
                        {
                            if (board.getBoardId() == user.Value.getBoardId())
                            {
                                user.Value.setBoard(board); //board is not null
                                board.addAssignedUser(user.Value.getEmail());
                            }
                        }
                    }
                }
                bc.loadData(users); //Loading all Boards to BoardController
            }
        }
Exemplo n.º 5
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");
            }
        }