public RedirectToRouteResult AddComment(AddCommentViewModel comment)
        {
            if (ModelState.IsValid)
            {
                var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var user        = _userService.Get(User.Identity.GetUserId());

                var _newComment = new CommentModel()
                {
                    PublishDate = DateTime.Now,
                    Body        = comment.Body,
                    IsBlocked   = false,
                    AuthorId    = User.Identity.GetUserId(),
                    PostId      = comment.PostId
                };

                _userService.UserAddComment(user.Id);
                _userService.CheckUserStatus(userManager, user.Id);
                _userService.CheckUserAwards(user.Id);

                _commentManager.Add(_newComment);
            }

            return(RedirectToAction("Details", "Post", new { id = comment.PostId }));
        }
Beispiel #2
0
        public ActionResult AddComment(ServicePageViewModel model)
        {
            if (model.NewComment == null)
            {
                return(RedirectToRoute("ServicePage", new { id = model.Id }));
            }
            var entity = Mapper.Map <ServicePageViewModel, Comments>(model);

            _commentManager.Add(entity);
            return(RedirectToRoute("ServicePage", new { id = model.Id }));
        }
Beispiel #3
0
        public ActionResult CreateComment(CommentViewModel commentViewModel)
        {
            //var userId = User.Identity.GetUserId();
            var userName = User.Identity.Name;


            Comment comment = new Comment
            {
                RequsitionId     = commentViewModel.RequsitionId,
                Comments         = commentViewModel.Comments,
                EmployeeId       = commentViewModel.EmployeeId,
                SenderEmployeeId = commentViewModel.SenderEmployeeId,
                // SenderEmployee = _employeeManager.GetById(commentViewModel.SenderEmployeeId),
                ReceiverEmployeeId = commentViewModel.ReceiverEmployeeId,
                ReceiverSeenTime   = DateTime.Now,
                //ReceiverEmployee = _employeeManager.GetById(commentViewModel.SenderEmployeeId),
                UserName    = userName,
                CommentTime = DateTime.Now
            };
            bool isSaved = commentManager.Add(comment);

            List <CommentViewModel> commentListViewModel = new List <CommentViewModel>();

            if (isSaved)
            {
                var userEmployeeId = GetEmployeeId();
                ViewBag.UserEmployeeId = userEmployeeId;
                //Collect the list of comment to display the list under comment
                var commentListView = commentManager.GetCommentsByRequisition(commentViewModel.RequsitionId);

                foreach (var item in commentListView.ToList())
                {
                    var cmnt = new CommentViewModel
                    {
                        Id                 = item.Id,
                        RequsitionId       = item.RequsitionId,
                        EmployeeId         = item.EmployeeId,
                        Comments           = item.Comments,
                        UserName           = item.UserName,
                        CommentTime        = item.CommentTime,
                        IsReceiverSeen     = item.IsReceiverSeen,
                        ReceiverSeenTime   = item.ReceiverSeenTime,
                        SenderEmployee     = item.SenderEmployee,
                        SenderEmployeeId   = (int)item.SenderEmployeeId,
                        ReceiverEmployee   = item.ReceiverEmployee,
                        ReceiverEmployeeId = (int)item.ReceiverEmployeeId,
                    };
                    commentListViewModel.Add(cmnt);
                }
                return(PartialView("_CommentList", commentListViewModel));
            }
            return(PartialView("_CommentList", commentListViewModel));
        }
Beispiel #4
0
        public async Task <CommentDTO> Add(CommentDTO newComment)
        {
            var comment = mapper.Map <Comment>(newComment);
            var added   = await commentManager.Add(comment);

            if (added != null)
            {
                newComment = mapper.Map <CommentDTO>(comment);
                return(newComment);
            }
            return(null);
        }
        public IActionResult Comment(IFormCollection comment)
        {
            try
            {
                var text = comment["reply"];
                //creamos el nuevo comentario
                CORE.Comment com = new CORE.Comment
                {
                    Malware_Id  = malId,
                    User_Id     = _userManager.GetUserId(User),
                    TextComment = text
                };
                //añadiumo y guardamos
                commentManager.Add(com);
                commentManager.Context.SaveChanges();
                TempData["creado"] = "El comentario se ha añadido correctamente";
                _log.LogInformation("Comentario creado correctamente: Id " + com.Id.ToString());
                var md5 = malwareManager.GetById(malId).MD5;

                //preparamos el mensaje de email
                var from = new List <EmailAddress>();
                from.Add(new EmailAddress
                {
                    Address = "*****@*****.**",
                    Name    = "PoyectoFinal"
                });
                var to = new List <EmailAddress>();
                to.Add(new EmailAddress
                {
                    Address = User.FindFirstValue(ClaimTypes.Name),
                    Name    = User.FindFirstValue(ClaimTypes.Name),
                });

                EmailMessage message = new EmailMessage
                {
                    FromAddresses = from,
                    ToAddresses   = to,
                    Subject       = "Comentario publicado",
                    Content       = "El comentario ha sido publicado correctamente"
                };
                //enviamos el email
                email.Send(message);

                return(RedirectToAction("Index", "Analysis", new { id = md5 }));
            }
            catch (Exception ex)
            {
                //guardamso log si se produce una excepcion
                _log.LogError(ex.Message, ex);
                return(View(comment));
            }
        }
Beispiel #6
0
        public ActionResult CreateComment(CommentViewModel commentViewModel)
        {
            var userId   = User.Identity.GetUserId();
            var userName = User.Identity.Name;


            Comment comment = new Comment();

            comment.RequsitionId = commentViewModel.RequsitionId;
            comment.Comments     = commentViewModel.Comments;
            comment.EmployeeId   = commentViewModel.EmployeeId;
            comment.UserName     = userName;
            comment.CommentTime  = DateTime.Now;
            bool isSaved = commentManager.Add(comment);

            List <CommentViewModel> commentListViewModel = new List <CommentViewModel>();

            if (isSaved)
            {
                //Collect the list of comment to display the list under comment
                var commentListView = commentManager.GetCommentsByRequisition(commentViewModel.RequsitionId);

                foreach (var item in commentListView.ToList())
                {
                    var cmnt = new CommentViewModel();
                    cmnt.RequsitionId = item.RequsitionId;
                    cmnt.EmployeeId   = item.EmployeeId;
                    cmnt.Comments     = item.Comments;
                    cmnt.Employee     = item.Employee;
                    cmnt.Employee     = item.Employee;
                    cmnt.UserName     = item.UserName;
                    cmnt.CommentTime  = item.CommentTime;
                    cmnt.EmployeName  = commentViewModel.EmployeName;
                    commentListViewModel.Add(cmnt);
                }
                return(PartialView("_CommentList", commentListViewModel));
            }
            return(PartialView("_CommentList", commentListViewModel));
        }
        public ActionResult CreateComment(RequsitionViewModel requsitionViewModel)
        {
            Comment comment = new Comment();

            comment.RequsitionId = requsitionViewModel.Id;
            comment.Comments     = requsitionViewModel.CommentViewModel.Comments;
            bool isSaved = commentManager.Add(comment);

            if (isSaved)
            {
                return(RedirectToAction("Details"));
            }
            return(View());
        }
        public ActionResult Create(RequsitionViewModel RequsitionViewModel)
        {
            try
            {
                Comment comment = new Comment();
                comment.RequsitionId = RequsitionViewModel.Id;
                comment.Comments     = RequsitionViewModel.CommentViewModel.Comments;

                commentManager.Add(comment);
                return(RedirectToAction("Details", "Requsition"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Add(FormCommentModel model)
        {
            commentManager.Add(model);

            switch (model.ParentType)
            {
            case CommentParentType.ALERT:
                return(RedirectToAction("AlertComments", new { alertId = model.ParentId }));

            case CommentParentType.COMMENT:
                return(RedirectToAction("CommentComments", new { commentId = model.ParentId }));

            default:
                return(Json(false));
            }
        }
        public ActionResult Create(Comment comment)
        {
            try
            {
                //var userId = User.Identity.GetUserId();
                //Comment comment = new Comment();
                //comment.RequsitionId = RequsitionViewModel.Id;
                //comment.Comments = RequsitionViewModel.CommentViewModel.Comments;

                commentManager.Add(comment);
                return(RedirectToAction("Details", "Requsition"));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <JsonResult> AddComment(int?ticketId, string text)
        {
            if (text != null && ticketId != null && ticketId > 0)
            {
                string unescapedText = htmlValidator.ValidateHtml(HttpUtility.UrlDecode(text));
                text = unescapedText;
                User curUser = await userManager.GetCurrentUser();

                Ticket curTicket = await db.Tickets.Include(y => y.Comments).SingleOrDefaultAsync(x => x.Id == ticketId);

                TeamPermissions userPerms = await GetCurrentTeamPermissions(curTicket.TeamId, curUser.Id);

                if (userPerms.CanCommentTicket || curUser.AppRole.Permissions.IsAdmin)
                {
                    Comment newComment = await commentManager.Add(curUser, curTicket, text);

                    CommentDTO commentToJs = dtoConverter.ConvertComment(newComment, curUser, userPerms);
                    return(Json(commentToJs));
                }
            }
            return(Json(null));
        }