public ActionResult CreateReply(string content, int taskId, int userId)
        {
            TaskReply reply = new TaskReply()
            {
                Content         = content,
                TaskItemId      = taskId,
                ReadyTaskUserId = userId,
                DateCreated     = DateTime.Now
            };

            _context.TaskReplies.Add(reply);
            _context.SaveChanges();
            return(RedirectToAction("Details", new { id = taskId }));
        }
Ejemplo n.º 2
0
        public CreateReplyResponse CreateReplyAjax(string content, int taskId, int userId)
        {
            TaskReply reply = new TaskReply()
            {
                Content         = content,
                TaskItemId      = taskId,
                ReadyTaskUserId = userId,
                DateCreated     = DateTime.Now
            };

            _context.TaskReplies.Add(reply);
            _context.SaveChanges();

            ReadyTaskUser       user     = _context.Users.Find(reply.ReadyTaskUserId);
            CreateReplyResponse response = new CreateReplyResponse()
            {
                Content       = reply.Content,
                UserFirstName = user.FirstName,
                UserLastName  = user.LastName,
                DateCreated   = reply.DateCreated.Value.ToString("mm/dd/yy h:mm tt")
            };

            TaskItem task = _context.TaskItems.Find(taskId);

            if (task.AssignedUserId != null && task.AssignedUserId != 0)
            {
                Notification notification = new Notification()
                {
                    TaskId          = taskId,
                    Message         = $"<b>{user.FirstName} {user.LastName}</b> wrote a reply on one of your assigned tasks.",
                    ReadyTaskUserId = (int)task.AssignedUserId
                };
                _context.Notifications.Add(notification);
                _context.SaveChanges();
                _hub.Clients.All.SendAsync("ReceiveNotification", notification).Wait();
            }

            return(response);
        }
        public CreateReplyResponse CreateReplyAjax(string content, int taskId, int userId)
        {
            TaskReply reply = new TaskReply()
            {
                Content         = content,
                TaskItemId      = taskId,
                ReadyTaskUserId = userId,
                DateCreated     = DateTime.Now
            };

            _context.TaskReplies.Add(reply);
            _context.SaveChanges();

            ReadyTaskUser       user     = _context.Users.Find(reply.ReadyTaskUserId);
            CreateReplyResponse response = new CreateReplyResponse()
            {
                Content       = reply.Content,
                UserFirstName = user.FirstName,
                UserLastName  = user.LastName,
                DateCreated   = reply.DateCreated.Value.ToString("mm/dd/yy h:mm tt")
            };

            return(response);
        }