public void Setup()
 {
     _repository = new CommentRepository("comments",
                                         new ConnectionStringSettings("comments",
                                                                      "Server=teamlab;Database=Test;UserID=dev;Pwd=dev;pooling=True;Character Set=utf8",
                                                                      "MySql.Data.MySqlClient"));
 }
Example #2
0
        public JsonResult Borrar(int commentId)
        {
            bool result = false;

            int userId = ((CustomPrincipal)User).UserId;

            CommentRepository comment = new CommentRepository(SessionCustom);

            comment.Entity.CommentId = commentId;
            comment.LoadByKey();

            IdeaRepository idea = new IdeaRepository(SessionCustom);

            idea.Entity.IdeaId = comment.Entity.IdeaId;
            idea.LoadByKey();

            if (userId == comment.Entity.UserId /*|| userId == idea.Entity.UserId*/)
            {
                comment.Entity.Active = false;
                comment.Update();
                result = true;
            }

            return(this.Json(new { result = result }));
        }
Example #3
0
        public JsonResult Crear(int ideaId, string text)
        {
            bool result        = false;
            int  currentUserId = ((CustomPrincipal)User).UserId;
            CommentRepository commentRepository = new CommentRepository(SessionCustom);

            commentRepository.Entity.Text         = text;
            commentRepository.Entity.IdeaId       = ideaId;
            commentRepository.Entity.Active       = true;
            commentRepository.Entity.UserId       = currentUserId;
            commentRepository.Entity.Creationdate = DateTime.Now;
            int commentId = Convert.ToInt32(commentRepository.Insert());

            result = true;

            IdeaRepository idea = new IdeaRepository(SessionCustom);

            idea.Entity.IdeaId = ideaId;
            idea.LoadByKey();
            bool update = idea.Entity.UserId.Value == commentRepository.Entity.UserId.Value ? true : false;

            if (idea.Entity.UserId.Value != commentRepository.Entity.UserId.Value)
            {
                Utils.SetUserRewardAction(commentRepository.Entity.UserId.Value, RewardAction.UserActionType.CommentIdea, 21, 21, this.SessionCustom, ControllerContext.HttpContext, true, this.CurrentLanguage);
                Utils.SetUserRewardAction(idea.Entity.UserId.Value, RewardAction.UserActionType.ReciveComment, 21, int.MaxValue, this.SessionCustom, ControllerContext.HttpContext, update, this.CurrentLanguage);
                Business.Utilities.Notification.NewNotification(idea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.RECEIVE_IDEA_COMMENT, currentUserId, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, commentId, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage);
            }
            else
            {
                Utils.SetUserRewardAction(commentRepository.Entity.UserId.Value, RewardAction.UserActionType.CommentIdea, 21, 0, this.SessionCustom, ControllerContext.HttpContext, true, this.CurrentLanguage);
                Utils.SetUserRewardAction(idea.Entity.UserId.Value, RewardAction.UserActionType.ReciveComment, 21, 0, this.SessionCustom, ControllerContext.HttpContext, update, this.CurrentLanguage);
            }

            // hilo notificaciones de usuarios relacionados
            Business.Utilities.Notification.StartRelatedContentUser(commentRepository.Entity.UserId.Value, idea.Entity.IdeaId.Value, null, Domain.Entities.Basic.SystemNotificationType.RECEIVE_IDEA_RELATED_COMMENT, currentUserId, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, commentId, null, null, null, this.HttpContext, this.CurrentLanguage);

            if (idea.IsIdeaInTop10(idea.Entity.IdeaId.Value))
            {
                SystemNotificationRepository notification = new SystemNotificationRepository(SessionCustom);
                int count = notification.SystemNotificationCount(idea.Entity.UserId.Value, (int)Domain.Entities.Basic.SystemNotificationType.IDEA_TOP_10, idea.Entity.IdeaId.Value);
                if (count == 0)
                {
                    Business.Utilities.Notification.NewNotification(idea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.IDEA_TOP_10, null, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, idea.Entity.IdeaId.Value, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage);
                }
            }

            if (idea.IsIdeaInTop5Home(idea.Entity.IdeaId.Value))
            {
                SystemNotificationRepository notification = new SystemNotificationRepository(SessionCustom);
                int count = notification.SystemNotificationCount(idea.Entity.UserId.Value, (int)Domain.Entities.Basic.SystemNotificationType.POPULAR_IDEA_TOP_5, idea.Entity.IdeaId.Value);
                if (count == 0)
                {
                    Business.Utilities.Notification.NewNotification(idea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.POPULAR_IDEA_TOP_5, null, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, idea.Entity.IdeaId.Value, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage);
                }
            }

            Business.UserRelation.SaveRelationAction(((CustomPrincipal)User).UserId, idea.Entity.UserId.Value, commentId, "comment", this.SessionCustom);

            return(this.Json(new { result = result }));
        }
Example #4
0
        public JsonResult Editar(int commentId, string text)
        {
            bool result = false;

            int userId = ((CustomPrincipal)User).UserId;

            CommentRepository comment = new CommentRepository(SessionCustom);

            comment.Entity.CommentId = commentId;
            comment.LoadByKey();

            if (userId == comment.Entity.UserId || ((CustomPrincipal)User).IsFrontEndAdmin)
            {
                SessionCustom.Begin();

                comment.Entity.Text = text;
                comment.Update();

                result = true;

                SessionCustom.Commit();
            }

            return(this.Json(new { result = result }));
        }
Example #5
0
        public virtual async Task <CommentDto> CreateAsync(string entityType, string entityId, CreateCommentInput input)
        {
            var user = await CmsUserLookupService.GetByIdAsync(CurrentUser.GetId());

            var comment = await CommentRepository.InsertAsync(
                new Comment(
                    GuidGenerator.Create(),
                    entityType,
                    entityId,
                    input.Text,
                    input.RepliedCommentId,
                    user.Id,
                    CurrentTenant.Id
                    )
                );


            await UnitOfWorkManager.Current.SaveChangesAsync();

            await DistributedEventBus.PublishAsync(new CreatedCommentEvent
            {
                Id = comment.Id
            });

            return(ObjectMapper.Map <Comment, CommentDto>(comment));
        }
Example #6
0
        public ActionResult Comments(int pageIndex, int pageSize, int ideaId)
        {
            int total = 0;
            CommentRepository comment = new CommentRepository(SessionCustom);

            return(this.View("CommentsList", comment.CommentsPaging(pageIndex, pageSize, out total, ideaId)));
        }
Example #7
0
        public static Comment LoadSingle(long userId, long pin)
        {
            var repository = new CommentRepository();
            var toRet      = repository.LoadSingle(pin);

            return(toRet);
        }
 public UnitOfWork(ApplicationDbContext context)
 {
     Shops    = new ShopRepository(context);
     Comments = new CommentRepository(context);
     Images   = new ImageRepository(context);
     _context = context;
 }
Example #9
0
        public void ShouldGetTheRightPersonWhoMadeTheComment()
        {
            const int personId = 1;
            const int roleId = 1;
            var commentsToDelete = Context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach (var commentToDelete in commentsToDelete)
                Context.DeleteObject(commentToDelete);

            ICommentRepository commentsRepo = new CommentRepository(Context);
            var currentPerson = new Person { PersonId = personId, RoleId = roleId };

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);
            var sut       = commentsRepo.GetListOfComments(currentPerson, personId).ToList();

            Assert.That(sut[0].CreatedByPerson, Is.EqualTo("Peter Munnings"));
        }
Example #10
0
        public void InsertFalseInput()
        {
            commentRepository = new CommentRepository(context);
            Exception ex = Assert.Throws <NullReferenceException>(() => commentRepository.Insert(null));

            Assert.Equal("Het commentaar is leeg.", ex.Message);
        }
Example #11
0
        public void GetByTreatment()
        {
            EmptyLists();
            commentRepository = new CommentRepository(context);

            Assert.Equal(3, commentRepository.GetByTreatment(1).Count);
        }
Example #12
0
 public CommentController(ApplicationContext context, IHubContext <CommentHub> commentHub)
 {
     CommentRepository         = new CommentRepository(context);
     ApplicationUserRepository = new ApplicationUserRepository(context);
     LikeRepository            = new LikeRepository(context);
     _commentHubContext        = commentHub;
 }
Example #13
0
        public void CommentRepositoryConstructor()
        {
            EmptyLists();
            commentRepository = new CommentRepository(context);

            Assert.NotNull(commentRepository);
        }
Example #14
0
        public static CommentRepository GetCommentRepository()
        {
            var repository = new CommentRepository();

            repository.UnitOfWork = GetUnitOfWork();
            return(repository);
        }
Example #15
0
        public static CommentRepository GetCommentRepository(IUnitOfWork unitOfWork)
        {
            var repository = new CommentRepository();

            repository.UnitOfWork = unitOfWork;
            return(repository);
        }
Example #16
0
        async Task ExecuteLoadCommentsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Comments.Clear();
                CommentRepository commentRepository = new CommentRepository();
                var items = commentRepository.Get(c => c.PostId == _post.Id);
                foreach (var item in items)
                {
                    Comments.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #17
0
        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            if (ctx == null)
            {
                ctx = new DbOrganization();
            }
            if (commentrepository == null)
            {
                commentrepository = new CommentRepository(ctx);
            }
            if (Orgrep == null)
            {
                Orgrep = new OrganizationRepository(ctx);
            }
            if (userrep == null)
            {
                userrep = new UserRepository(ctx);
            }
            if (Orgmemrep == null)
            {
                Orgmemrep = new OrganizationMemberRepository(ctx);
            }

            if (controllerName == "Home")
            {
                return(new HomeController(Orgrep, userrep, Orgmemrep, commentrepository));
            }
            if (controllerName == "User")
            {
                return(new UserController(userrep));
            }


            return(base.CreateController(requestContext, controllerName));
        }
Example #18
0
 public UnitOfWork(BlogContext context)
 {
     _context       = context;
     Articles       = new ArticleRepository(_context);
     Comments       = new CommentRepository(_context);
     Questionnaires = new QuestionnaireRepository(_context);
 }
Example #19
0
        public JsonResult DeleteComment(int id)
        {
            bool result = false;
            int  userId = ((Business.Services.CustomPrincipal)User).UserId;
            CommentRepository comment = new CommentRepository(SessionCustom);

            comment.Entity.CommentId = id;
            comment.LoadByKey();
            if (comment.Entity.ContentId.HasValue)
            {
                ContentRepository content = new ContentRepository(SessionCustom);
                content.Entity.ContentId = comment.Entity.ContentId;
                content.LoadByKey();

                if ((Utils.IsBlogAdmin(userId) && content.Entity.UserId == userId) || comment.Entity.UserId == userId)
                {
                    comment.Entity.Active = false;
                    comment.Update();

                    result = true;
                }
            }

            return(this.Json(new { result = result }));
        }
Example #20
0
 public CommentRepositoryTests()
 {
     var options = new DbContextOptionsBuilder<EventProjectDbContext>()
         .UseInMemoryDatabase("TestDb").Options;
     db = new EventProjectDbContext(options);
     repository = new CommentRepository(db);
 }
Example #21
0
        public void PagesGetCorrectItems()
        {
            var comments = new Comment[12];

            for(int i = 0; i < 12; i++)
            {
                comments[i] = new Comment() {Text = "This is comment " + i.ToString("D2"), Author = "Chuck Finley"};
            }

            var postId = CreatePost("Comments Test", "Comments Test", DateTime.Now, comments);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            int pageSize = 5;
            var criteria = new CommentCriteria() { PostId = postId };
            var order = Order<Comment>.By(c => c.Text);

            var page0 = repo.Retrieve(pageSize, 0, out virtualItemCount, criteria, order).ToList();
            page0.Count().Should().Be(5);
            page0.First().Text.Should().EndWith("00");
            page0.Last().Text.Should().EndWith("04");

            var page1 = repo.Retrieve(pageSize, 1, out virtualItemCount, criteria, order).ToList();
            page1.Count().Should().Be(5);
            page1.First().Text.Should().EndWith("05");
            page1.Last().Text.Should().EndWith("09");

            var page2 = repo.Retrieve(pageSize, 2, out virtualItemCount, criteria, order).ToList();
            page2.Count().Should().Be(2);
            page2.First().Text.Should().EndWith("10");
            page2.Last().Text.Should().EndWith("11");
        }
 public static IRepositoryService<Comment> Create()
 {
     IDatabaseFactory databaseFactory = new DatabaseFactory();
     IUnitOfWork unitOfWork = new UnitOfWork(databaseFactory);
     IRepository<Comment> commentRepository = new CommentRepository(databaseFactory);
     return new CommentEntityService((ICommentRepository) commentRepository, unitOfWork);
 }
        public IHttpActionResult GetCommentWithId(int cid, int id)
        {
            CommentRepository cr = new CommentRepository();
            Comment           c  = cr.GetById(cid);

            if (c == null || c.PostId != id)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments/" + c.CommentId, HttpMethod = "GET", Relation = "Self"
            });
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments", HttpMethod = "Post", Relation = "Create a new Post"
            });
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments/" + c.CommentId, HttpMethod = "PUT", Relation = "Edit self"
            });
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments/" + c.CommentId, HttpMethod = "DELETE", Relation = "DELETE self"
            });
            return(Ok(c));
        }
 public PostManager()
 {
     _postRepo      = new UserPostRepository();
     _postModelRepo = new PostModelRepository();
     _imgM          = new ImageManager();
     _cRepo         = new CommentRepository();
 }
Example #25
0
        public ActionResult Index(FormCollection formData)
        {
            String strComment = formData["CommentText"];

            if (!String.IsNullOrEmpty(strComment))
            {
                Comment           c   = new Comment( );
                CommentRepository rep = new CommentRepository( );

                c.CommentText = strComment;
                String strUser = System.Security.Principal.WindowsIdentity.GetCurrent( ).Name;
                if (!String.IsNullOrEmpty(strUser))
                {
                    int slashPos = strUser.IndexOf("\\");
                    if (slashPos != -1)
                    {
                        strUser = strUser.Substring(slashPos + 1);
                    }
                    c.UserName = strUser;

                    rep.AddComment(c);
                }
                else
                {
                    c.UserName = "******";
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("CommentText", "Kjánaprik. Ætlarðu að setja inn tóma athugasemd?");
                return(Index( ));
            }
        }
Example #26
0
 public EventService(EventRepository eventRepo, AttractionRepository attractionRepo, UserRepository userRepo, CommentRepository commentRepo)
 {
     _eventRepo      = eventRepo;
     _attractionRepo = attractionRepo;
     _userRepo       = userRepo;
     _commentRepo    = commentRepo;
 }
Example #27
0
        public ActionResult Index( )
        {
            CommentRepository rep = new CommentRepository( );
            var model             = rep.GetComments( );

            return(View(model));
        }
        public void UpdateTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());
            var userRepository    = new UserRepository(new InMemoryDbContextFactory());
            var author            = new UserDetailModel();
            var dbAuthor          = userRepository.Insert(author);

            var commentOld = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Mamka mi zjedla rezen.",
            };

            var commentNew = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Content   = "Ocko mi zjedol rezen nakoniec.",
                Author    = dbAuthor
            };

            var commentDetail = commentRepository.Insert(commentNew);

            commentRepository.Update(commentNew);

            var commentDatabase = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentDatabase);
            Assert.Equal(commentNew.Timestamp, commentDatabase.Timestamp);
            Assert.Equal(commentNew.Content, commentDatabase.Content);

            commentRepository.Remove(commentDatabase.Id);
        }
        public void DoTheReadItemAndWriteItemFollowTheSamePattern()
        {
            //Arrange
            var    fakeComments = CommentRepositoryMocks.GetFakeComments();
            string filePath     = CommentRepositoryMocks.FakeCommentDataFileProvider(fakeComments);
            var    repository   = new CommentRepository(filePath);


            try
            {
                using (var fs = new FileStream(filePath, FileMode.OpenOrCreate))
                {
                    using (var sr = new StreamReader(fs))
                    {
                        foreach (var item in fakeComments)
                        {
                            //Act
                            var other = (Comment)typeof(CommentRepository)
                                        .GetMethod("readItem", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
                                        .Invoke(repository, new object[] { sr });

                            //Assert
                            Assert.AreEqual(item.Id, other.Id);
                            Assert.AreEqual(item.TaskId, other.TaskId);
                            Assert.AreEqual(item.AuthorId, other.AuthorId);
                            Assert.AreEqual(item.Body, other.Body);
                        }
                    }
                }
            }
            finally
            {
                File.Delete(filePath);
            }
        }
 // Konstruktor kontrolera użytkownika.
 public CompanyUserController()
 {
     // Inicjalizacja repozytoriów
     _providerRepo = new ServiceProviderRepository();
     _companyRepo  = new CompanyRepository();
     _commentRepo  = new CommentRepository();
 }
        public void GetByIdTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());
            var userRepository    = new UserRepository(new InMemoryDbContextFactory());

            var author = new UserDetailModel();

            var dbAuthor = userRepository.Insert(author);

            var comment = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Dneska som mala na obed kuraci steak",
            };

            var commentDetail = commentRepository.Insert(comment);

            var commentDatabase = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentDatabase);
            Assert.Equal(comment.Timestamp, commentDatabase.Timestamp);
            Assert.NotNull(commentDatabase.Author);
            Assert.Equal(comment.Content, commentDatabase.Content);
            commentRepository.Remove(commentDatabase.Id);
        }
Example #32
0
        /// <summary>
        /// obtains the idea detail
        /// </summary>
        /// <param name="mod">identifier of module</param>
        /// <param name="id">identifier of section</param>
        /// <returns>returns the result to action</returns>
        public ActionResult Detail(int mod, int id)
        {
            QuestionRepository   objquestion   = new QuestionRepository(SessionCustom);
            ContentManagement    objcontentman = new ContentManagement(SessionCustom, HttpContext);
            ContentRepository    objcontent    = new ContentRepository(SessionCustom);
            IdeaRepository       objidea       = new IdeaRepository(SessionCustom);
            FileattachRepository objfiles      = new FileattachRepository(SessionCustom);
            TagRepository        objtag        = new TagRepository(SessionCustom);
            SectionRepository    objsection    = new SectionRepository(SessionCustom);
            TemplateRepository   objtemplate   = new TemplateRepository(SessionCustom);
            CommentRepository    objcomment    = new CommentRepository(SessionCustom);

            objtemplate.Entity.Type = 0;

            objidea.Entity.IdeaId        =
                objcomment.Entity.IdeaId = id;
            objidea.LoadByKey();

            objquestion.Entity.ContentId    =
                objcontent.Entity.ContentId = objidea.Entity.ContentId;
            objcontent.LoadByKey();
            objquestion.LoadByKey();

            if (objquestion.Entity != null && objquestion.Entity.Type.Equals(Domain.Entities.Question.TypeQuestion.Ubicacion))
            {
                ViewBag.Location = true;
            }
            else
            {
                ViewBag.Location = false;
            }

            int totalComments = 0;
            List <CommentsPaging> comments = objcomment.CommentsPaging(0, 50, out totalComments, id);

            ViewBag.TotalComments = totalComments;

            IEnumerable <Tag> SelectedTags = objtag.GetTagbycontent(id);

            this.ViewBag.SelectedTags = string.Join("|", SelectedTags.Select(t => t.TagId));
            this.ViewBag.NewsTags     = string.Empty;

            return(this.View(
                       "Detail",
                       new IdeaModel()
            {
                UserPrincipal = this.CustomUser,
                ColModul = CustomMemberShipProvider.GetModuls(this.CustomUser.UserId, this.SessionCustom, HttpContext),
                Module = this.Module,
                ListFiles = objfiles.GetAllReadOnly(),
                Idea = objidea.Entity,
                IContent = objcontent.Entity,
                Templates = objtemplate.GetAll().Select(t => t.TemplateId),
                ListContent = objcontent.GetContentRelation(CurrentLanguage.LanguageId.Value),
                ListTags = SelectedTags,
                DeepFollower = Business.Utils.GetDeepFollower(objsection.GetAll(), objcontent.Entity.SectionId.Value),
                CurrentLanguage = this.CurrentLanguage,
                ListComments = comments
            }));
        }
Example #33
0
        public void ShouldGetTheRightNumberOfComments()
        {
            const int personId   = 1;
            const int roleId     = 4;
            var commentsToDelete = _context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach(var commentToDelete in commentsToDelete)
                _context.DeleteObject(commentToDelete);

            _context.SaveChanges();

            ICommentRepository commentsRepo = new CommentRepository();
            var currentPerson = new Person {PersonId = personId, RoleId = roleId};

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);

            var sut = commentsRepo.GetListOfComments(currentPerson, personId);

            Assert.That(sut.Count(), Is.EqualTo(1));
        }
Example #34
0
        /// <summary>
        /// Bind the context and the session with the content
        /// </summary>
        /// <param name="context">Context page</param>
        /// <param name="session">Session object</param>
        /// <param name="id">Content ID</param>
        /// <param name="userId">current user ID</param>
        public void Bind(HttpContextBase context, ISession session, int?id, int?userId, int?LanguageId)
        {
            int total = 0;
            BlogEntryRepository  blogEntryRepository = new BlogEntryRepository(session);
            FileattachRepository fileRepository      = new FileattachRepository(session);
            CommentRepository    comment             = new CommentRepository(session);

            this.CollBlogEntries = blogEntryRepository.BlogEntriesPaging(1, 6, out total, true, LanguageId);
            this.TotalCount      = total;
            int totalCount = 0;

            foreach (BlogEntriesPaging blogEntry in this.CollBlogEntries)
            {
                blogEntry.CollComment = comment.CommentsPagingContent(1, 3, out totalCount, blogEntry.ContentId.Value);
                if (blogEntry.CollComment.Count > 0)
                {
                    blogEntry.CollComment[0].CommentContentOwnerId = blogEntry.UserId.Value;
                }

                fileRepository.Entity.ContentId = blogEntry.ContentId;
                Fileattach file = fileRepository.GetAll().FirstOrDefault(t => t.Type == Domain.Entities.Fileattach.TypeFile.Video);
                if (file != null)
                {
                    blogEntry.Video = file.Filename;
                }

                this.CommentsCount = totalCount;
            }
        }
Example #35
0
 public static ISearch<Comment> GetCommentSearch()
 {
     if (CommentSearch == null)
     {
         CommentSearch = new CommentRepository();
     }
     return CommentSearch;
 }
Example #36
0
 public static ICRUDRepository<Comment> GetCommentRepository()
 {
     if (commentRepo == null)
     {
         commentRepo = new CommentRepository();
     }
     return commentRepo;
 }
        public void AddReturnsId()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.Add(new Comment());

            Assert.IsNotNull(response);
            Assert.AreEqual(response.Id, 1);
        }
        public void GetCommentOrganizerId_Call_GetResult_Test()
        {
            var context = new MyEventsContext();
            var comment = context.Comments.Include("Session.EventDefinition").FirstOrDefault();

            ICommentRepository target = new CommentRepository();

            int organizerId = target.GetOrganizerId(comment.CommentId);

            Assert.AreEqual(organizerId, comment.Session.EventDefinition.OrganizerId);
        }
Example #39
0
 public SqlDAL()
 {
     DBContext = new AlbumsDBModel();
     _albumRepository = new AlbumRepository(DBContext);
     _roleRepository = new RoleRepository(DBContext);
     _userRepository = new UserRepository(DBContext);
     _commentRepository = new CommentRepository(DBContext);
     _likeRepository = new LikeRepository(DBContext);
     _albumsPhotoRepository = new AlbumsPhotoRepository(DBContext);
     _photoRepository = new PhotoRepository(DBContext);
 }
        public void ExpectDataValidationException()
        {
            CommentRepository repo = new CommentRepository(new BlogContext());

            var comment = new Comment();
            comment.PostID = -1;
            comment.Text = "This shouldn't be saveable";

            Action save = () => repo.Save(comment);

            save.ShouldThrow<DataValidationException>();
        }
Example #41
0
 public static void Initialize()
 {
     UserRepository = new UserRepository();
     PostRepository = new PostRepository();
     HeaderImageRepository = new HeaderImageRepository();
     MessageRepository = new MessageRepository();
     CommentRepository = new CommentRepository();
     PostVotingRepository = new PostVotingRepository();
     CommentVotingRepository = new CommentVotingRepository();
     MessageSettingsRepository = new MessageSettingsRepository();
     TagRepository = new TagRepository();
     TagPostRepository = new TagPostRepository();
 }
        public void DeleteComment_NoExists_NotFail_Test()
        {
            var context = new MyEventsContext();
            var comment = context.Comments.FirstOrDefault();
            int expected = context.Comments.Count();

            ICommentRepository target = new CommentRepository();
            target.Delete(0);

            int actual = context.Comments.Count();

            Assert.AreEqual(expected, actual);
        }
        public void AddPersists()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            repository.Add(new Comment { Message = "Test Item" });

            dbFactory.Run(db =>
                              {
                                  var response = db.Select<Comment>();

                                  Assert.AreEqual(response.Count, 1);
                                  Assert.AreEqual(response[0].Message, "Test Item");
                              });
        }
        public void DeleteFails()
        {
            dbFactory.Run(db => db.Insert(new Comment { Id = 1, Message = "Test Item" }));

            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            repository.Delete(2);
            dbFactory.Run(db =>
                              {
                                  var response = db.Select<Comment>();

                                  Assert.AreEqual(response.Count, 1);
                                  Assert.AreEqual(response[0].Message, "Test Item");
                              });
        }
Example #45
0
 public ActionResult AddComment(string content, string userId, string ariticleId, string comment_temp)
 {
    
     CommentRepository cr = new CommentRepository();
     UserRepository ur = new UserRepository();
     string result = "";
     if (comment_temp != "null")
     {
         string[] array = comment_temp.Split('#');
         int id = Int32.Parse(array[0]);
         string firstUserId = array[1];
         Comment c = cr.FindByID(id);
         User u = ur.FindByID(userId);
         User firstUser = ur.FindByID(firstUserId);
         c.Isleaf = 1;
         cr.Update(c);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.AriticleId = ariticleId;
         comment.Content = content;
         comment.NickName = u.NickName;
         comment.FirstNickName = firstUser.NickName;
         comment.Pid = id;
         comment.Isleaf = 0;
         comment.CommentTime = DateTime.Now;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
     }
     else {
         User u = ur.FindByID(userId);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.Content = content;
         comment.CommentTime = DateTime.Now;
         comment.AriticleId = ariticleId;
         comment.Pid = 0;
         comment.Isleaf = 0;
         comment.Level = 1;
         comment.NickName = u.NickName;
         comment.FirstNickName = null;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
         ;
     }
     return Content(result);
 }
        public void AddComment_Added_NotFail_Test()
        {
            var context = new MyEventsContext();
            int sessionId = context.Sessions.FirstOrDefault().SessionId;
            int registeredUserId = context.RegisteredUsers.FirstOrDefault().RegisteredUserId;
            int expected = context.Comments.Count() + 1;

            ICommentRepository target = new CommentRepository();
            Comment comment = new Comment();
            comment.SessionId = sessionId;
            comment.AddedDateTime = DateTime.UtcNow;
            comment.RegisteredUserId = registeredUserId;
            comment.Text = "sample comment";
            target.Add(comment);

            int actual = context.Comments.Count();

            Assert.AreEqual(expected, actual);
        }
Example #47
0
        private static void CreatePost(string title)
        {
            var postRepository = new PostRepository();
            var categoryRepository = new CategoryRepository();
            var commentRepository = new CommentRepository();

            var post = new Post
                           {
                               Title = title,
                               PostedDate = DateTime.Now,
                               Contents = "This is just a simple test post..."
                           };

            for (int i = 0; i < 10; i++)
            {
                var category = new Category
                                   {
                                       Name = "Category " + i,
                                       CreatedDate = DateTime.Now,
                                       Description = "Just a test..."
                                   };

                post.AddCategory(category);
                categoryRepository.Create(category);
            }

            for (int i = 0; i < 20; i++)
            {
                var comment = new Comment
                                  {
                                      PostedDate = DateTime.Now,
                                      Author = "Author " + i,
                                      Text = "testing..."
                                  };

                post.AddComment(comment);
                commentRepository.Create(comment);
            }

            postRepository.Create(post);
        }
Example #48
0
        public void CommentsCanBeFilteredByPost()
        {
            var comment1 = new Comment() { Text = "This is a comment for the first post", Author = "Chuck Finley" };
            var comment2 = new Comment() { Text = "This is a comment for the first post", Author = "Chuck Finley" };
            var comment3 = new Comment() { Text = "This is a comment for the second post", Author = "Santos L. Helper" };
            var comment4 = new Comment() { Text = "This is a comment for the second post", Author = "Santos L. Helper" };

            var post1Id = CreatePost("Comments Test 1", "Comments Test 1", DateTime.Now, comment1, comment2);
            var post2Id = CreatePost("Comments Test 2", "Comments Test 2", DateTime.Now, comment3, comment4);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            var comments = repo.Retrieve(10, 0, out virtualItemCount, new CommentCriteria() { PostId = post2Id }).ToList();

            comment3.PostID = post2Id;
            comment4.PostID = post2Id;
            var comparisonComments = new Collection<Comment>() { comment3, comment4 };

            comments.Count().Should().Be(2);
            comments.ShouldAllBeEquivalentTo(comparisonComments,
                options => options.Excluding(o => o.ID));
        }
Example #49
0
        public void CommentsShouldSavedWithPost()
        {
            var title = "Comments Test";
            var text = "Comments Test";
            var publishDate = DateTime.Now;

            var comment1 = new Comment() {Text = "This is a comment", Author = "Chuck Finley"};
            var comment2 = new Comment() { Text = "This is a comment", Author = "Chuck Finley" };

            var postId = CreatePost(title, text, publishDate, comment1, comment2);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            var comments = repo.Retrieve(10, 0, out virtualItemCount, new CommentCriteria() {PostId = postId}).ToList();

            comment1.PostID = postId;
            comment2.PostID = postId;
            var comparisonComments = new Collection<Comment>() {comment1, comment2};

            comments.Count().Should().Be(2);
            comments.ShouldAllBeEquivalentTo(comparisonComments,
                options => options.Excluding(o => o.ID));
        }
 private void initializeTest()
 {
     _connectionString = "server=wt-220.ruc.dk;database=raw4;uid=raw4;pwd=raw4";
     _commentMapper = new CommentMapper(_connectionString);
     _commentRepository = new CommentRepository(_commentMapper);
 }
Example #51
0
 protected void Page_Load(object sender, EventArgs e)
 {
     LogUtil.Logger.Writeln(String.Format(".  -<font color = 'cyan'><u> Comment OnInit:  RecID {0}</u></font>",idst));
     _presenter = new CommentsPresenter();
        // _presenter.Init(this, IsPostBack);
        // _presenter.LoadComments();
     _com = new CommentRepository();
     _ac = new AccountRepository();
     tb_comment.Text = "";
     Image1.ImageUrl ="~/Image/ProfileAvatar.aspx?AccountID=" + _usersession.CurrentUser.AccountID;
     Label1.Text ="Bình luận cho "+ _ac.GetAccountByID(idac).UserName.ToUpper()+" ";
 }
Example #52
0
 public List<Comment> GetCommentChidren(int id) {
     CommentRepository cr = new CommentRepository();
     return cr.GetCommentChidren(id).ToList();
 }
        public void UpdateIsSingular()
        {
            dbFactory.Run(db =>
                              {
                                  db.Insert(new Comment { Id = 1, Message = "Test Item" });
                                  db.Insert(new Comment { Id = 2, Message = "Test Item 2" });
                              });

            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            repository.Update(new Comment { Id = 1, Message = "Test Edit" });

            dbFactory.Run(db =>
                              {
                                  var response = db.Select<Comment>();

                                  Assert.AreEqual(response.Count, 2);
                                  Assert.AreEqual(response.Single(x => x.Id == 1).Message, "Test Edit");
                                  Assert.AreEqual(response.Single(x => x.Id == 2).Message, "Test Item 2");
                              });
        }
        public void GetByIdReturnsNull()
        {
            dbFactory.Run(db => db.Insert(new Comment { Id = 1, Message = "Test Item" }));

            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.GetById(2);

            Assert.IsNull(response);
        }
        public void GetAllReturnsItems()
        {
            dbFactory.Run(db =>
                              {
                                  db.Insert(new Comment { Id = 1, Message = "Test Item" });
                                  db.Insert(new Comment { Id = 2, Message = "Test Item 2" });
                              });

            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.GetAll();

            Assert.IsNotNull(response);
            Assert.AreEqual(response.Count, 2);
            Assert.AreEqual(response.Single(x => x.Id == 1).Message, "Test Item");
            Assert.AreEqual(response.Single(x => x.Id == 2).Message, "Test Item 2");
        }
        public void GetAllReturnsEmpty()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.GetAll();

            Assert.IsNotNull(response);
            Assert.AreEqual(response.Count, 0);
        }
 public CommentsController(CommentRepository commentRepository)
 {
     this.commentRepository = commentRepository;
 }
        public void GetComment_Call_GetResults_Test()
        {
            var context = new MyEventsContext();
            int sessionId = context.Comments.FirstOrDefault().SessionId;
            int expectedCount = context.Comments.Count(q => q.SessionId == sessionId);

            ICommentRepository target = new CommentRepository();

            IEnumerable<Comment> results = target.GetAll(sessionId);

            Assert.IsNotNull(results);
            Assert.AreEqual(expectedCount, results.Count());
        }
 public JsonResult Reply(int commentId, int replyId, string content)
 {
     CommentRepository commentRepository = new CommentRepository();
     Comment comment = new Comment();
     Comment replyComment = new Comment();
     if (replyId == 0)
     {
         comment = commentRepository.GetById(commentId);
         replyComment.Article = comment.Article;
         replyComment.ArticleID = comment.ArticleID;
         replyComment.DateCreated = DateTime.Now;
         replyComment.UserID = AuthenticationManager.LoggedUser.Id;
         replyComment.Content = content;
         replyComment.ParentComment = comment;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         replyComment.UserType = type;
         commentRepository.Save(replyComment);
     }
     if (commentId == 0)
     {
         comment = commentRepository.GetById(replyId);
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
         commentRepository.Save(comment);
     }
     SelectListItem item = new SelectListItem() { Text = commentId.ToString(), Value = comment.Article.Id.ToString() };
     return Json(item, JsonRequestBehavior.AllowGet);
 }
Example #60
0
        public void VirtualCountEqualsTotalItems()
        {
            var comments = new Comment[12];

            for (int i = 0; i < 12; i++)
            {
                comments[i] = new Comment() { Text = "This is comment " + i.ToString("D2"), Author = "Chuck Finley" };
            }

            var postId = CreatePost("Comments Test", "Comments Test", DateTime.Now, comments);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            int pageSize = 5;

            var criteria = new CommentCriteria() {PostId = postId};
            var order =  Order<Comment>.By(c => c.Text);

            var page0 = repo.Retrieve(pageSize, 0, out virtualItemCount, criteria, order).ToList();
            virtualItemCount.Should().Be(12);

            var page1 = repo.Retrieve(pageSize, 1, out virtualItemCount, criteria, order).ToList();
            virtualItemCount.Should().Be(12);

            var page2 = repo.Retrieve(pageSize, 2, out virtualItemCount, criteria, order).ToList();
            virtualItemCount.Should().Be(12);
        }