public void setLimit(int limit) //sets the limit field { if ((limit < 0 & limit != -1) | limit < tasks.Count) //Limit check { log.Warn("invalid limit"); throw new Exception("invalid limit"); } this.limit = limit; //Updating database DataAccessLayer.dataColumnController DCC = new DataAccessLayer.dataColumnController(); DCC.Update(boardId, key, "limited", limit); }
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 } }
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"); } }