public ActionResult <BoardListResult> GetAll([FromQuery] bool isPopular = false,
                                                     [FromQuery] string title   = "",
                                                     [FromQuery] int limit      = 1000)
        {
            var list = (from b in _boardRepository.Get()
                        where b.IsPopular == isPopular &&
                        (string.IsNullOrWhiteSpace(title) || b.Title.Contains(title, StringComparison.CurrentCulture))
                        select b)
                       .Take(limit)
                       .ToDTO();

            if (!list.Any())
            {
                return(NoContent());
            }

            var next = _boardRepository.Get()
                       .Skip(limit)
                       .Take(1)
                       .SingleOrDefault()
                       .ToDTO();

            return(new BoardListResult
            {
                List = list,
                Next = next
            });
        }
Exemplo n.º 2
0
        public HttpResponseMessage Put(string id, Sticky sticky)
        {
            using (var session = RavenDatabase.GetSession())
            {
                var boardRepo      = new BoardRepository(session);
                var board          = boardRepo.Get();
                var existingSticky = board.Stickies.Where(s => s.Id == id).FirstOrDefault();

                if (existingSticky == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Sticky with that id not found."));
                }
                else
                {
                    existingSticky.Content = sticky.Content;
                    existingSticky.X       = sticky.X;
                    existingSticky.Y       = sticky.Y;
                    existingSticky.Height  = sticky.Height;
                    existingSticky.Width   = sticky.Width;

                    boardRepo.Save(board);

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult <BoardResponse> > GetBoard(long id)
        {
            var board = await _boardRepository.Get(id);

            var boardResponse = MapModelToResponse(board);

            return(boardResponse);
        }
Exemplo n.º 4
0
 private Board GetBoardFromDatabase()
 {
     using (var session = RavenDatabase.GetSession())
     {
         var repo = new BoardRepository(session);
         return(repo.Get());
     }
 }
Exemplo n.º 5
0
        public void GivenBoard_WhenSetSavesBoard_GetReturnsTheSameBoard()
        {
            var board           = new Board();
            var boardRepository = new BoardRepository();

            boardRepository.Set(board);
            var result = boardRepository.Get();

            Assert.That(result.GetHashCode(), Is.EqualTo(board.GetHashCode()));
        }
Exemplo n.º 6
0
        public HttpResponseMessage Post(Sticky sticky)
        {
            using (var session = RavenDatabase.GetSession())
            {
                var boardRepo = new BoardRepository(session);
                var board     = boardRepo.Get();
                board.AddSticky(sticky);
                boardRepo.Save(board);
            }

            return(Request.CreateResponse <string>(HttpStatusCode.OK, sticky.Id));
        }
Exemplo n.º 7
0
        public IActionResult Board(int id)
        {
            var board = _boardRepository.Get(id);

            if (board == null)
            {
                return(NotFound());
            }

            var vm = Mapper.Map <BoardViewModel>(board);

            return(Board(vm));
        }
Exemplo n.º 8
0
        public HttpResponseMessage Get(string id)
        {
            using (var session = RavenDatabase.GetSession())
            {
                var boardRepo = new BoardRepository(session);
                var board     = boardRepo.Get();
                var sticky    = board.Stickies.Where(s => s.Id == id).FirstOrDefault();

                if (sticky == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Sticky with that id not found."));
                }
                else
                {
                    return(Request.CreateResponse <Sticky>(HttpStatusCode.OK, sticky));
                }
            }
        }