示例#1
0
        public ActionResult <RetroCard> DeleteRetroCard(int id)
        {
            RetroCard retroCard = _context.RetroCards.FirstOrDefault(r => r.Id == id);

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

            _context.RemoveRetroCard(retroCard);

            RetroColumn retroColumn = _context.RetroColumns.Single(x => x.Id == retroCard.RetroColumnId);

            if (_hubContext != null)
            {
                try
                {
                    _hubContext.Clients.All.BroadcastMessage(true, retroColumn.RetrospectiveId);
                }
                catch
                {
                    _hubContext.Clients.All.BroadcastMessage(false, retroColumn.RetrospectiveId);
                }
            }

            return(retroCard);
        }
        public IQueryable <Retrospective> GetAll()
        {
            IList <Retrospective>   retrospectives    = _context.Retrospectives.Include(c => c.RetroColumns).ThenInclude(s => s.RetroCards).Include(x => x.RetroColumns).ThenInclude(x => x.RetroFamilies).ThenInclude(x => x.RetroCards).ToList();
            ICollection <RetroCard> removedRetroCards = new List <RetroCard>();

            foreach (Retrospective retrospective in retrospectives)
            {
                foreach (RetroColumn r in retrospective.RetroColumns)
                {
                    foreach (RetroCard i in r.RetroCards)
                    {
                        RetroCard c = (RetroCard)i;
                        if (c.RetroFamily != null)
                        {
                            removedRetroCards.Add(i);
                        }
                    }

                    foreach (RetroCard i in removedRetroCards)
                    {
                        r.RetroCards.Remove(i);
                    }
                }
            }

            return(retrospectives.AsQueryable());
        }
示例#3
0
        public ActionResult <RetroCard> PostRetroCard(RetroCard retroCard)
        {
            _context.SaveRetroCard(retroCard);

            RetroColumn retroColumn = _context.RetroColumns.Single(x => x.Id == retroCard.RetroColumnId);

            if (_hubContext.Clients != null)
            {
                try
                {
                    _hubContext.Clients.All.BroadcastMessage(true, retroColumn.RetrospectiveId);
                }
                catch
                {
                    _hubContext.Clients.All.BroadcastMessage(false, retroColumn.RetrospectiveId);
                }
            }

            return(CreatedAtAction("GetRetroCard", new { id = retroCard.Id }, retroCard));
        }
示例#4
0
        public ActionResult <RetroCard> UpdateRetroCard(RetroCard retroCard)
        {
            _context.SaveRetroCard(retroCard);

            RetroColumn retroColumn = _context.RetroColumns.Single(x => x.Id == retroCard.RetroColumnId);

            if (_hubContext != null)
            {
                try
                {
                    _hubContext.Clients.All.BroadcastMessage(true, retroColumn.RetrospectiveId);
                }
                catch
                {
                    _hubContext.Clients.All.BroadcastMessage(false, retroColumn.RetrospectiveId);
                }
            }

            return(retroCard);
        }
        public ActionResult <Retrospective> GetRetrospective(int id)
        {
            var retrospective = _context.Retrospectives.Include(c => c.RetroColumns).ThenInclude(s => s.RetroCards)
                                .Include(c => c.RetroColumns).ThenInclude(s => s.RetroFamilies).ThenInclude(c => c.RetroCards)
                                .FirstOrDefault(r => r.Id == id);

            ICollection <RetroCard> removedRetroCards = new List <RetroCard>();

            if (retrospective != null)
            {
                foreach (RetroColumn r in retrospective.RetroColumns)
                {
                    foreach (RetroCard i in r.RetroCards)
                    {
                        RetroCard c = (RetroCard)i;
                        if (c.RetroFamily != null)
                        {
                            removedRetroCards.Add(i);
                        }
                    }

                    foreach (RetroCard i in removedRetroCards)
                    {
                        r.RetroCards.Remove(i);
                    }
                }
            }


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

            return(retrospective);
        }
示例#6
0
        public void AdditionOfARetroCard()
        {
            //Arrange
            IRetroRespectiveRepository repo = _mockRetrospectiveRepo.Object;
            var controller = new RetroCardsController(repo, _hubContext.Object);

            IList <RetroColumn> retroColumns = new List <RetroColumn>();

            retroColumns.Add(new RetroColumn {
                Id = 0
            });

            this._mockRetrospectiveRepo.Setup(r => r.RetroColumns).Returns(retroColumns.AsQueryable);

            IList <RetroCard> retroCards = new List <RetroCard>();

            void Action(RetroCard retroCard)
            {
                retroCards.Add(retroCard);
            }

            _mockRetrospectiveRepo.Setup(m => m.SaveRetroCard(It.IsAny <RetroCard>())).Callback((Action <RetroCard>)Action);

            //Act
            controller.PostRetroCard(new RetroCard
            {
                Id      = 5,
                Content = "RetroCard 1"
            });

            //Assert
            Assert.True(retroCards.Any());
            RetroCard createdRetroCard = retroCards.FirstOrDefault(r => r.Content.Equals("RetroCard 1"));

            Assert.NotNull(createdRetroCard);
        }
        public void SaveRetroCard(RetroCard retroCard)
        {
            if (retroCard.Id == 0)
            {
                _context.RetroCards.Add(retroCard);
            }
            else
            {
                RetroCard dbEntry = _context.RetroCards
                                    .FirstOrDefault(c => c.Id == retroCard.Id);

                if (dbEntry != null)
                {
                    dbEntry.Content       = retroCard.Content;
                    dbEntry.Position      = retroCard.Position;
                    dbEntry.RetroColumnId = retroCard.RetroColumnId;
                    dbEntry.RetroFamilyId = retroCard.RetroFamilyId;
                    dbEntry.DownVotes     = retroCard.DownVotes;
                    dbEntry.UpVotes       = retroCard.UpVotes;
                }
            }

            _context.SaveChanges();
        }
 public void RemoveRetroCard(RetroCard baseItem)
 {
     _context.RetroCards.Remove(baseItem);
     _context.SaveChanges();
 }