Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("CommentId,Title,EmployeeNumber,Date,Post,Category")] CommentCreateViewModel commentCreateViewModel)
        {
            try
            {
                var employeeNumber = await _commentRepository.GetEmployeeNums(commentCreateViewModel.EmployeeNumber);

                if (employeeNumber.Contains(commentCreateViewModel.EmployeeNumber))
                {
                    commentCreateViewModel.SubmittedBy = User.FindFirstValue(ClaimTypes.Name);

                    if (ModelState.IsValid)
                    {
                        var comment = _mapper.Map <Comment>(commentCreateViewModel);
                        await _commentRepository.CreateComment(comment);

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Enter a valid Employee Number ");
                }
            }
            catch (DbUpdateException)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(View(commentCreateViewModel));
        }
Ejemplo n.º 2
0
        public async Task PostFromAnAuthenticatedUserWithValidViewModel_CreatesACommentWithCorrectlyData()
        {
            TestableCommentController controller = TestableCommentController.Create();
            const int currentUserAccountId       = 345;
            DateTime  systemTime = new DateTime(2017, 9, 22, 16, 43, 7);

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(currentUserAccountId);
            controller.MockSystemClock.Setup(x => x.UtcNow).Returns(systemTime);

            var model = new CommentCreateViewModel {
                CountdownId = 123,
                Text        = "Testing"
            };

            EmptyResult result = await controller.Create(model) as EmptyResult;

            Comment comment = controller.CommentRepository.Comments.FirstOrDefault();

            Assert.IsNotNull(result);
            Assert.IsNotNull(comment);
            Assert.AreEqual(model.Text, comment.Text);
            Assert.AreEqual(model.CountdownId, comment.CountdownId);
            Assert.AreEqual(systemTime, comment.CreatedOn);
            Assert.AreEqual(currentUserAccountId, comment.CreatedByAccountId);
        }
Ejemplo n.º 3
0
        public ActionResult Create(CommentCreateViewModel commentData)
        {
            if (!ModelState.IsValid || (commentData.AnonymousAuthorEmail == null && commentData.AuthorId == null))
            {
                return(BadRequest());
            }

            var post = db.Posts.Find(commentData.PostId);

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

            var comment = mapper.Map <CommentCreateViewModel, Comment>(commentData);

            if (commentData.AnonymousAuthorEmail != null)
            {
                comment.AnonAuthorEmail = comment.AnonAuthorEmail.ToLower();
            }

            db.Comments.Add(comment);
            db.SaveChanges();

            comment = db.Comments
                      .Include(c => c.Author)
                      .SingleOrDefault(c => c.CommentId == comment.CommentId);

            var commentVM = mapper.Map <Comment, CommentViewModel>(comment);

            return(Ok(commentVM));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create(CommentCreateViewModel model)
        {
            _logger.Info("Creating comment! Params: " + model.ToJson());

            if (!ModelState.IsValid)
            {
                _logger.Info("Invalid comment Form! Errors: " + ModelState.ToJson());
                return(Json(ModelState.ToDictionary()));
            }
            if (!await postsManager.Exists(model.PostId))
            {
                ModelState.AddModelError("PostId", "Постът, който искате да коментирате не съществува.");
                return(Json(ModelState.ToDictionary()));
            }
            try
            {
                var createdComment = await commentsManager.Create(model, User.Identity.GetUserId());

                _logger.Info("Comment created successfully!");

                return(Json(new
                {
                    CreationDate = createdComment.CreationDate.ToString("MMMM dd, yyyy"),
                    UserImageUrl = createdComment.UserImageUrl,
                    Author = createdComment.Author,
                    Body = createdComment.Body,
                    CommentId = createdComment.CommentId
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Creating comment failed!");
                throw;
            }
        }
Ejemplo n.º 5
0
        // GET: Comments/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var comment = await _bll.Comments.FindAsync(id);

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

            var vm = new CommentCreateViewModel
            {
                Comment           = comment,
                ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()),
                                                   nameof(Product.Id), nameof(Product.ProductName), comment.ProductId),
                ShopSelectList = new SelectList(await _bll.Shops.GetShopByUserShopIdForDropDown(User.GetShopId()),
                                                nameof(Shop.Id), nameof(Shop.ShopName), comment.ShopId)
            };

            return(View(vm));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Create(CommentCreateViewModel model)
        {
//            await Task.Delay(3000);
            if (ModelState.IsValid)
            {
                var comment = new Comment {
                    CountdownId        = model.CountdownId,
                    Text               = model.Text,
                    CreatedOn          = _systemClock.UtcNow,
                    CreatedByAccountId = (int)_contextService.CurrentUserAccountId
                };
                await _commentRepository.CreateAsync(comment);

                _notificationService.UpdateClientsAfterCreate(comment);

                var notificationChange = new NotificationChange {
                    CreatedByAccountId     = (int)_contextService.CurrentUserAccountId,
                    CreatedOn              = _systemClock.UtcNow,
                    NotificationActionType = NotificationActionType.Commented
                };
                await _notificationService.NotifyCountdownOwnerAsync(comment.CountdownId, notificationChange);

                return(new EmptyResult());
            }
            return(new HttpStatusCodeResult(400, "Bad Request"));
        }
Ejemplo n.º 7
0
        public IActionResult Thread(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var comments = _db.GameComment.Where(c => c.ThreadId == id);

            foreach (var comment in comments)
            {
                comment.Author = _db.ApplicationUser.Find(comment.AuthorID);
            }

            CommentCreateViewModel obj = new CommentCreateViewModel
            {
                Comments = comments,
                Thread   = _db.GameCommentThread.Find(id),
            };

            obj.Thread.Game = _db.Game.Find(obj.Thread.GameId);
            obj.NewComment  = new GameComment();

            ViewData["Title"] = comments.FirstOrDefault().Thread.Name + " - " + comments.FirstOrDefault().Thread.Game.Name;

            return(View(obj));
        }
Ejemplo n.º 8
0
        public async void Post([FromBody] CommentCreateViewModel model)
        {
            model.User = await _manager.GetUserAsync(User);

            //model.User = await _manager.FindByEmailAsync("*****@*****.**");
            _commentService.Create(model);
        }
Ejemplo n.º 9
0
        public ActionResult Index(int id)
        {
            var            currentUser = GetCurrentUser();
            List <Comment> comments    = _commentRepository.GetCommentsByPostId(id);

            foreach (Comment comment in comments)
            {
                if (comment.UserProfileId == currentUser)
                {
                    comment.CurrentUser = true;
                }
                else
                {
                    comment.CurrentUser = false;
                }
            }
            Post post = _postRepository.GetPublishedPostById(id);

            CommentCreateViewModel vm = new CommentCreateViewModel
            {
                Comments   = comments,
                ParentPost = post
            };

            return(View(vm));
        }
Ejemplo n.º 10
0
        public async Task EditAsync(int id, CommentCreateViewModel model)
        {
            var comment = await _context.Comments.FindAsync(id);

            comment.Text = model.Text;
            _context.Update(comment);
            await _context.SaveChangesAsync();
        }
Ejemplo n.º 11
0
        public IActionResult CreateComment(CommentCreateViewModel comment)
        {
            var currentUser = db.Users.Where(user => user.UserName == User.Identity.Name).Single();

            db.Comments.Add(new CommentModel(comment.Body, currentUser, comment.ArticleId));
            db.SaveChanges();
            return(ShowArticle(comment.ArticleId));
        }
Ejemplo n.º 12
0
        public ActionResult Create(string articleId)
        {
            CommentCreateViewModel model = new CommentCreateViewModel {
                ArticleId = articleId
            };

            return(View(model));
        }
Ejemplo n.º 13
0
        // GET: Comments/Create
        public IActionResult Create()
        {
            var model = new CommentCreateViewModel
            {
                EmployeeList = _commentRepository.EmployeeList()
            };

            return(View(model));
        }
Ejemplo n.º 14
0
        public ActionResult CreateForm(int postId)
        {
            var Model = new CommentCreateViewModel()
            {
                PostId = postId
            };

            return(PartialView("Create", Model));
        }
Ejemplo n.º 15
0
        public IViewComponentResult Invoke(int id, string commentOn)
        {
            CommentCreateViewModel details = new CommentCreateViewModel
            {
                ID        = id,
                CommentOn = commentOn
            };

            return(View("Default", details));
        }
Ejemplo n.º 16
0
        public ActionResult Add(int tutorialId, int page, CommentCreateViewModel model)
        {
            this.comments.Add(model.Content, User.Identity.GetUserId(), tutorialId);

            var result = new CommentsViewModel();

            result.Comments = this.comments.GetByPage(tutorialId, page).To<CommentViewModel>().ToList();
            result.Pages = this.comments.GetPagesCount(tutorialId);

            return this.PartialView("_CommentsPartial", result);
        }
Ejemplo n.º 17
0
        // GET: Comments/Create
        public IActionResult Create(int id)
        {
            var model = new CommentCreateViewModel();
            var post  = _context.Post
                        .Where(c => c.PostId == id).FirstOrDefault();

            model.Post        = post;
            model.Post.PostId = post.PostId;

            return(View(model));
        }
Ejemplo n.º 18
0
        // GET: Comments/Create
        public async Task <IActionResult> Create()
        {
            var vm = new CommentCreateViewModel
            {
                ProductSelectList = new SelectList(await _bll.Products.AllAsyncByShopForDropDown(User.GetShopId()),
                                                   nameof(Product.Id), nameof(Product.ProductName)),
                ShopSelectList = new SelectList(await _bll.Shops.GetShopByUserShopIdForDropDown(User.GetShopId()),
                                                nameof(Shop.Id), nameof(Shop.ShopName))
            };

            return(View(vm));
        }
Ejemplo n.º 19
0
        // GET: Comments/Create
        public async Task <IActionResult> Create()
        {
            var vm = new CommentCreateViewModel
            {
                ProductSelectList = new SelectList(await _bll.Products.AllAsync(),
                                                   nameof(Product.Id), nameof(Product.ProductName)),
                ShopSelectList = new SelectList(await _bll.Shops.AllAsync(),
                                                nameof(Shop.Id), nameof(Shop.ShopName))
            };

            return(View(vm));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Create(int postId, CommentCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                await _commentsService.CreateAsync(userId, postId, model);

                return(RedirectToAction("Index", "Post"));
            }

            return(View(model));
        }
Ejemplo n.º 21
0
        public long Create(CommentCreateViewModel model)
        {
            var comment = _dbContext.Comments.Add(new Comment()
            {
                PostId      = model.PostId,
                CommentText = model.CommentText,
                CommentDate = DateTime.Now,
                User        = model.User,
            });

            _dbContext.SaveChanges();
            return(comment.Entity.CommentId);
        }
Ejemplo n.º 22
0
 public ActionResult Create(CommentCreateViewModel vm)
 {
     try
     {
         vm.Comment.CreateDataTime = DateTime.Now;
         _commentRepo.AddComment(vm.Comment);
         return(RedirectToAction("Index", new { id = vm.Comment.PostId }));
     }
     catch
     {
         return(View(vm));
     }
 }
Ejemplo n.º 23
0
        public async Task <Comment> CreateComment(CommentCreateViewModel comment)
        {
            var user = _userManager.Users.FirstOrDefault(u => u.Email == HttpContext.User.Identity.Name);

            comment.CommentAuthor = user?.Name;

            var newComment = _map.Map <Comment>(comment);
            await _uow.CommentRepository.CreateAsync(newComment);

            await _uow.Save();

            return(newComment);
        }
Ejemplo n.º 24
0
 public ActionResult Create(CommentCreateViewModel comment)
 {
     if (ModelState.IsValid)
     {
         var newComment = new Comment();
         newComment.User    = uRepo.Get(Session["CurrentUser-Username"].ToString());
         newComment.Content = comment.Content;
         newComment.Post    = pRepo.Get(comment.PostId);
         cRepo.Add(newComment);
         return(new EmptyResult());
     }
     return(View(comment));
 }
Ejemplo n.º 25
0
        // GET: HomeController1/Create
        public ActionResult Create(int id)
        {
            var                    currentUser = GetCurrentUser();
            List <Comment>         comments    = _commentRepository.GetCommentsByPostId(id);
            Post                   post        = _postRepository.GetPublishedPostById(id);
            CommentCreateViewModel vm          = new CommentCreateViewModel
            {
                UserId     = currentUser,
                Comments   = comments,
                ParentPost = post
            };

            return(View(vm));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Create(CommentCreateViewModel model)
        {
            var userId = this.userManager.GetUserId(User);

            await this.comments.CreateAsync(userId, model.Content, model.NewsId, model.ParentCommentId);

            if (model.NewsId == null)
            {
                model.NewsId = await this.comments.NewsId(model.ParentCommentId.Value);
            }

            TempData.AddSuccessMessage($"Comment created successfully!");

            return(RedirectToAction("Details", "News", new { id = model.NewsId, area = "News" }));
        }
Ejemplo n.º 27
0
        public IActionResult Create([FromQuery] int?newsId, [FromQuery] int?parentCommentId)
        {
            if ((newsId == null && parentCommentId == null) || (newsId != null && parentCommentId != null))
            {
                return(BadRequest());
            }

            var model = new CommentCreateViewModel
            {
                NewsId          = newsId,
                ParentCommentId = parentCommentId
            };

            return(View(model));
        }
Ejemplo n.º 28
0
        // GET: CommentController/Create
        public ActionResult Create(int id)
        {
            Post post = _postRepo.GetPublishedPostById(id);
            CommentCreateViewModel vm = new CommentCreateViewModel()
            {
                Post    = post,
                Comment = new Comment()
                {
                    PostId        = post.Id,
                    UserProfileId = GetCurrentUserId()
                }
            };

            return(View(vm));
        }
Ejemplo n.º 29
0
        public ActionResult Create([Bind(Include = "Content,PostId")] CommentCreateViewModel commentVM)
        {
            Comment comment = new Comment();

            if (ModelState.IsValid)
            {
                comment.Content      = commentVM.Content;
                comment.AuthorId     = User.Identity.GetUserId();
                comment.CreationDate = DateTime.Now;
                comment.Post         = db.Posts.FirstOrDefault(x => x.Id == commentVM.PostId);
                db.Comments.Add(comment);
                db.SaveChanges();
            }
            return(Json(new { date = comment.CreationDate.ToString(), content = comment.Content, username = db.Users.Find(comment.AuthorId).UserName }));
        }
Ejemplo n.º 30
0
        public async Task PostFromAnAuthenticatedUserWithValidViewModel_ReturnsEmptyResult()
        {
            TestableCommentController controller = TestableCommentController.Create();

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(123);

            var model = new CommentCreateViewModel {
                CountdownId = 123,
                Text        = "Testing"
            };

            EmptyResult result = await controller.Create(model) as EmptyResult;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 31
0
        public ActionResult Add(CommentCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Comment commentToAdd = new Comment();
                commentToAdd.Id         = Guid.NewGuid().ToString();
                commentToAdd.AuthorName = model.AuthorName;
                commentToAdd.PostDate   = DateTime.Now;
                commentToAdd.ArticleId  = model.ArticleId;
                commentToAdd.ReviewText = model.Text;
                commentsService.Add(commentToAdd);

                return(RedirectToAction("Details", "Article", new { id = Convert.ToInt32(model.ArticleId) }));
            }
            return(View());
        }