Beispiel #1
0
        private void MainWindow_FormClosing(Object sender, FormClosingEventArgs e)
        {
            //DataBaseWriter dataBaseWrite = new DataBaseWriter();
            this.mapper         = new BoardDataMapper();
            this.savedGameState = new SavedGameState
            {
                BoardSize        = this.matrixAlgorithm.BoardSize,
                CurrentTurn      = this.matrixAlgorithm.CurrentTurn,
                CurrentTurnCount = this.matrixAlgorithm.CurrentTurnCount,
                BoardData        = this.mapper.WriteCurrentBoardToString(this.matrixAlgorithm),
            };
            Data data = new Data
            {
                CurrentGame = this.savedGameState,
                Round       = this.settings.RoundCount,
                HistoryList = this.settings.HistoryList,
                Difficulty  = this.ChooseDifficulty()
            };
            HistoryData historyData = new HistoryData
            {
                HistoryList = this.settings.HistoryList,
            };

            dataBaseWriter.WriteDatabaseFile(historyData);
            this.serialize = (ISerializeData)SerDesFactory.Create(typeof(ISerializeData));
            this.serialize.SerializeJson(Application.StartupPath + "/settings/autosave.json", data);
            this.serialize.SerializeXml(Application.StartupPath + "/settings/autosave.xml", data);
        }
        public JsonResult ExistingLists(int id)
        {
            var user = AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name);

            return(user.CanReadBoard(id) ? Json(
                       ListDataMapper.GetListDataMapper().GetAllByBoard(BoardDataMapper.GetBoardDataMapper().GetById(id)), JsonRequestBehavior.AllowGet) : null);
        }
        public bool BoardExists(String id)
        {
            var user  = AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name);
            var board = BoardDataMapper.GetBoardDataMapper().GetBoardByUserAndName(user, id);

            return(board != null);
        }
        public ActionResult Index()
        {
            var bm     = BoardDataMapper.GetBoardDataMapper();
            var boards =
                bm.GetBoardsFrom(AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name));

            return(View(boards));
        }
        public ActionResult CreateList(int id)
        {
            var board = BoardDataMapper.GetBoardDataMapper().GetById(id);

            if (board == null)
            {
                return(Redirect("~/Errors/Http404"));
            }
            return(View(new ListsModel {
                Board = board
            }));
        }
        public ActionResult CreateList(ListsModel listsModel, int id)
        {
            var board = BoardDataMapper.GetBoardDataMapper().GetById(id);

            if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id))
            {
                return(RedirectToAction("Index"));
            }
            listsModel.Board = board;
            var ldm = ListDataMapper.GetListDataMapper();

            ldm.Add(listsModel);
            return(Redirect(String.Format("~/Boards/GetLists/{0}", id)));
        }
        public ActionResult Create(BoardsModel boardsModel)
        {
            var bm = BoardDataMapper.GetBoardDataMapper();

            if (bm.GetByName(boardsModel.Name) == null)
            {
                bm.Add(boardsModel);
                var acc = AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name);
                acc.AddBoard(boardsModel);
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("Name", "Já existe um Quadro com esse nome");
            return(View(boardsModel));
        }
        public ActionResult Edit(int id)
        {
            var board = BoardDataMapper.GetBoardDataMapper().GetById(id);

            if (board == null)
            {
                return(RedirectToAction("Http404", "Errors"));
            }
            if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id))
            {
                return(RedirectToAction("Index"));
            }
            return(View(board));
        }
        public ActionResult RemoveWriteRights(int id)
        {
            var board = BoardDataMapper.GetBoardDataMapper().GetById(id);

            if (board == null)
            {
                return(RedirectToAction("Http404", "Errors"));
            }
            if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id))
            {
                return(RedirectToAction("Index"));
            }
            return(View(new RightsModel {
                BoardId = id
            }));
        }
        public ActionResult Edit(BoardsModel boardsModel)
        {
            var board = BoardDataMapper.GetBoardDataMapper().GetById(boardsModel.Id);

            if (board == null)
            {
                return(RedirectToAction("Http404", "Errors"));
            }
            if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id))
            {
                return(RedirectToAction("Index"));
            }
            board.Name        = boardsModel.Name;
            board.Description = boardsModel.Description;
            return(RedirectToAction("Index"));
        }
        //
        // GET: /Home/
        public ActionResult Search(String id)
        {
            int counter = 5;
            var result  = new List <KeyValuePair <String, String> >();

            BoardDataMapper b = BoardDataMapper.GetBoardDataMapper();

            //Guarda os boards do user e procura boards cujo nome contenha id
            IEnumerable <BoardsModel> boards = b.GetBoardsFrom(AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name));

            GetResultsByName(boards, "/Boards/GetLists/", "[Board]", result, counter, id);

            //No caso de ainda poderem ser adicionados resultados adiciona lists
            if (counter > 0)
            {
                //Procura listas
                var            allLists = new List <ListsModel>();
                ListDataMapper l        = ListDataMapper.GetListDataMapper();
                foreach (BoardsModel bm in boards)
                {
                    IEnumerable <ListsModel> lists = l.GetAllByBoard(bm);
                    allLists.AddRange(lists);
                    GetResultsByName(lists, "/Lists/GetCards/", "[List]", result, counter, id);
                }

                //Se ainda poderem ser adicionados resultados adiciona cards
                if (counter > 0)
                {
                    var            allCards = new List <CardsModel>();
                    CardDataMapper c        = CardDataMapper.GetCardDataMapper();
                    foreach (ListsModel lm in allLists)
                    {
                        IEnumerable <CardsModel> cards = c.GetAllByList(lm);
                        allCards.AddRange(cards);
                        GetResultsByName(cards, "/Cards/GetCard/", "[Card]", result, counter, id);
                    }

                    //Se ainda poderem ser adicionados resultados adiciona cards pela descrição
                    if (counter > 0)
                    {
                        GetResultsByDescription(allCards, "/Cards/GetCard/", "[Card]", result, counter, id);
                    }
                }
            }
            return(PartialView("Search", result));
        }
        public ActionResult GetLists(int id)
        {
            var board = BoardDataMapper.GetBoardDataMapper().GetById(id);

            if (board == null)
            {
                return(Redirect("~/Errors/Http404"));
            }
            if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanReadBoard(board.Id))
            {
                return(RedirectToAction("Index"));
            }
            var ie = ListDataMapper.GetListDataMapper().GetAllByBoard(board);

            if (ie.Count() != 0)
            {
                return(View(ie));
            }
            return(View("Empty", board));
        }
        public ActionResult RemoveWriteRights(RightsModel gr)
        {
            var acc = AccountDataMapper.GetAccountDataMapper().GetById(gr.Name);

            if (acc == null)
            {
                ModelState.AddModelError("Name", "Não existe nenhum utilizador com esse username");
                return(View(gr));
            }
            var board = BoardDataMapper.GetBoardDataMapper().GetById(gr.BoardId);

            if (board == null)
            {
                ModelState.AddModelError("Name", "BoardId " + gr.BoardId);
                return(View(gr));
            }
            if (!AccountDataMapper.GetAccountDataMapper().GetById(User.Identity.Name).CanWriteBoard(board.Id))
            {
                ModelState.AddModelError("BoardId", "Não possui permissões para efectuar essa acção");
                return(View(gr));
            }
            acc.RemoveWriteBoard(board.Id);
            return(RedirectToAction("GetLists", new { id = board.Id }));
        }