public async Task <PartialViewResult> GetAllConversationThreads(int take = 50)
        {
            ConversationsVM vm = new ConversationsVM
            {
                Threads = await CommunityLogic.GetMessageThreads(take, new List <Types.ConvThreadCategory> {
                    Types.ConvThreadCategory.MainDashboard,
                    Types.ConvThreadCategory.OfficialCoins, Types.ConvThreadCategory.FeatureRequests
                }, CurrentUser),
                CurrentUser       = CurrentUser,
                HideCreateNewPost = true
            };

            List <OfficialCoin> officialCoins = CryptoLogic.GetAllOfficialCoins();

            foreach (var x in vm.Threads.Where(x => x.OfficialCoinId > 0))
            {
                OfficialCoin officialCoin = officialCoins.FirstOrDefault(o => o.OfficialCoinId == x.OfficialCoinId);
                if (officialCoin == null)
                {
                    continue;
                }

                x.OfficialCoin = officialCoin;
                x.ShowOfficialCoinNameOnThread = true;
            }

            return(PartialView("_Conversations", vm));
        }
Exemple #2
0
        public async Task <List <BBThread> > GetThreadsByCategory(int take, Types.ConvThreadCategory category, int officialCoinId = 0)
        {
            if (_memoryCache.TryGetValue(Constant.Session.GlobalThreadsByCategory, out List <ConversationFetchData> fetchData))
            {
                if (!fetchData.IsNullOrEmpty() && fetchData.Any(x => x.Take == take && x.Category == category && x.OfficialCoinId == officialCoinId))
                {
                    // This results already exist.
                    ConversationFetchData desiredResult = fetchData.First(x => x.Take == take && x.Category == category && x.OfficialCoinId == officialCoinId);
                    return(desiredResult.Results);
                }
            }

            // Results does not exist, or fetchData itself is non-existant.
            if (fetchData.IsNullOrEmpty())
            {
                fetchData = new List <ConversationFetchData>();
            }

            List <BBThread> results = await CommunityLogic.GetMessageThreads(50, Types.ConvThreadCategory.MainDashboard, CurrentUser, officialCoinId : officialCoinId);

            fetchData.Add(new ConversationFetchData
            {
                Take           = take,
                Category       = category,
                OfficialCoinId = officialCoinId,
                Results        = results
            });
            _memoryCache.Set(Constant.Session.GlobalThreadsByCategory, fetchData, TimeSpan.FromHours(24));

            return(results);
        }
        public async Task <ResultsItem> CreateBBThread(BBThread thread)
        {
            if (!ModelState.IsValid)
            {
                return(ResultsItem.Error(ModelState.GetAllErrorsString()));
            }

            OnThreadUpdatedCacheHandler(thread.CategoryCode, thread.OfficialCoinId.GetValueOrDefault());
            return(await CommunityLogic.CreateBBThread(thread, CurrentUser));
        }
        public async Task <ResultsItem> CreateBBComment(BBComment comment)
        {
            if (!ModelState.IsValid)
            {
                return(ResultsItem.Error(ModelState.GetAllErrorsString()));
            }

            OnThreadUpdatedCacheHandler(threadId: comment.ThreadId);
            OnCommentsUpdatedCacheHandler(comment.ThreadId);
            return(await CommunityLogic.CreateBBComment(comment, CurrentUser));
        }
Exemple #5
0
        public async Task <BBThread> GetThreadWithComments(int threadId)
        {
            if (_memoryCache.TryGetValue(Constant.Session.GlobalThreadsWithComments, out List <BBThread> fetchData))
            {
                if (!fetchData.IsNullOrEmpty() && fetchData.Any(x => x.ThreadId == threadId))
                {
                    return(fetchData.First(x => x.ThreadId == threadId));
                }
            }

            // Results does not exist, or fetchData itself is non-existant.
            if (fetchData.IsNullOrEmpty())
            {
                fetchData = new List <BBThread>();
            }

            BBThread result = await CommunityLogic.GetThreadWithComments(threadId, CurrentUser);

            fetchData.Add(result);
            _memoryCache.Set(Constant.Session.GlobalThreadsWithComments, fetchData, TimeSpan.FromHours(24));

            return(result);
        }
        public void ShouldGetCommunityId()
        {
            var communitySearch = new Community
                                  {
                                      Id = 1,
                                      LeaderUserId = 1,
                                      Leader = _members.FirstOrDefault(a => a.UserId == 1),
                                      Members = _members.ToList(),
                                      Posts = new List<Post> { new Post { PostId = 1 } }
                                  };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Get(It.IsAny<int>())).Returns(communitySearch);
            _communityRepository.Setup(a => a.GetMemberCountByCommunity(It.IsAny<int>())).Returns(5);

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Get(1);

            Assert.NotNull(result);
            Assert.NotNull(result.Posts);
            Assert.IsNull(result.Error);
            Assert.AreEqual(5, result.MemberCount);
        }
        public void ShouldThrowExceptionWhenGetCommunityByIdFails()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Get(It.IsAny<int>())).Throws(new Exception("Hooha!"));

            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.Get(1));
        }
 public async Task <ResultsItem> VoteBBComment(int commentId, bool isUpvote)
 {
     OnCommentsUpdatedCacheHandler(commentId: commentId);
     return(await CommunityLogic.VoteBBComment(commentId, isUpvote, CurrentUser));
 }
        public void ShouldDeleteCommunity()
        {
            var community = new Community { Id = 1, Name = "lorem", Description = "fudge brownies" };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Delete(It.IsAny<Community>()));
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), false))
                .Returns(new List<Community> { community });

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Delete(1);

            Assert.IsTrue(result);
        }
        public void ShouldThrowExceptionWhenCheckingCommunityNameFails()
        {
            var community = new Common.Contracts.Community
            {
                Name = "lorem",
                Description = "fudge brownies"
            };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), null, null))
                .Throws(new Exception("Hooha!"));

            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.Add(community));
        }
        public void ShouldErrorWhenCommunityNameExistsOnUpdate()
        {
            var search = _communities.Where(a => a.Id == 1).ToList();

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), null, null))
                .Returns(search);

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Update(new Common.Contracts.Community
            {
                Name = "lorem",
                Description = "fudge brownies"
            });

            Assert.NotNull(result.Error);
            Assert.AreEqual((int)Constants.Error.ValidationError, result.Error.Id);
            Assert.AreEqual("Community name lorem is already in use.", result.Error.Message);
        }
        public void ShouldUpdateCommunity()
        {
            var community = new Community { Id = 1, Name = "lorem", Description = "fudge brownies" };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Edit(It.IsAny<Community>())).Returns(community);
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), null, null))
                .Returns(new List<Community>());

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Update(new Common.Contracts.Community
            {
                Id = 1,
                Name = "lorem",
                Description = "fudge brownies"
            });

            Assert.NotNull(result);
            Assert.IsNull(result.Error);
        }
        public void ShouldThrowExceptionWhenGetMoreCreatedCommunityListFails()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.GetMoreCreatedCommunitiesByUser(It.IsAny<int>(),
                It.IsAny<int>(), It.IsAny<int>())).Throws(new Exception("Hooha!"));

            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.GetMoreCreatedByUser(1, 5));
        }
        public void ShouldGetMoreCreatedCommunityList()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.GetMoreCreatedCommunitiesByUser(It.IsAny<int>(),
                It.IsAny<int>(), It.IsAny<int>())).Returns(_communities);
            _communityRepository.Setup(a => a.GetMemberCountByCommunity(It.IsAny<int>())).Returns(5);

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.GetMoreCreatedByUser(1, 5);

            Assert.NotNull(result);
            CollectionAssert.AllItemsAreInstancesOfType(result, typeof(Common.Contracts.Community));
            result.Select(a => a.Posts).ToList().ForEach(Assert.IsNull);
        }
 public async Task <ResultsItem> DeleteBBComment(int commentId)
 {
     OnCommentsUpdatedCacheHandler(commentId: commentId);
     return(await CommunityLogic.DeleteBBComment(commentId, CurrentUser));
 }
 public async Task <ResultsItem> VoteBBThread(int threadId, bool isUpvote)
 {
     OnThreadUpdatedCacheHandler(threadId: threadId);
     return(await CommunityLogic.VoteBBThread(threadId, isUpvote, CurrentUser));
 }
        public void ShouldReturnFalseWhenNoRecordFoundOnDelete()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), false))
                .Returns(new List<Community>());

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Delete(1);

            Assert.IsFalse(result);
        }
        public void ShouldThrowExceptionWhenDeletingCommunityFailsOnGettingRecord()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Delete(It.IsAny<Community>()));
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), false))
                .Throws(new Exception("Hooha!"));


            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.Delete(1));
        }
        public void ShouldThrowExceptionWhenDeletingCommunityFails()
        {
            var community = new Community { Id = 1, Name = "lorem", Description = "fudge brownies" };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Delete(It.IsAny<Community>())).Throws(new Exception("Hooha!"));
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), false))
                .Returns(new List<Community> { community });

            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.Delete(1));
        }
 public async Task <ResultsItem> DeleteBBThread(int threadId)
 {
     OnThreadUpdatedCacheHandler(threadId: threadId);
     return(await CommunityLogic.DeleteBBThread(threadId, CurrentUser));
 }
        public void ShouldReturnErrorWhenGetCommunityIdFoundNoRecords()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Get(It.IsAny<int>())).Returns((Community)null);

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Get(1);

            Assert.NotNull(result.Error);
            Assert.AreEqual((int)Constants.Error.RecordNotFound, result.Error.Id);
            Assert.AreEqual("Cannot find community with Id 1", result.Error.Message);
        }