コード例 #1
0
        public async Task <IHttpActionResult> AddComment(TaskCommentViewModel model)
        {
            try
            {
                //add task owner to model
                if (string.IsNullOrWhiteSpace(model.CommentBody))
                {
                    return(Json(JsonResponse.Error("Please input a comment.")));
                }
                UserTaskCommentBO userTaskComment = new UserTaskCommentBO
                {
                    UserTaskId  = model.UserTaskId,
                    Comment     = model.CommentBody,
                    CommenterId = CurrentUserId,
                    CommentDate = DateTime.UtcNow,
                    Audit       = new Entity.Entities.Audit(CurrentUserId)
                };
                zeus.evaluationManager.Add(userTaskComment);
                await AddNotificationAsync(NotificationType.NewTaskComment, CurrentUserId, model.UserId, "task/" + model.UserTaskId);

                return(Ok(new UserTaskCommentDTO {
                    UserTaskCommentId = userTaskComment.Id, CommenterId = CurrentUserId, Comment = model.CommentBody, CommenterName = "You", Date = DateTime.UtcNow
                }));
            }
            catch (Exception ex)
            {
                LogError(ex, CurrentUserId);
                return(BadRequest());
            }
        }
コード例 #2
0
        public static List <TaskCommentsViewModel> GetAllCompletedTasksOfUserAndGroup(Int64 recipientUserId, Int64 groupId, ILogger _logger, Helper.Cache _redisCache, Helper.AppSettings _appSettings, Model.DatabaseRepository _dbr)
        {
            try
            {
                List <TaskCommentsViewModel> lstTaskCommentsViewModel = new List <TaskCommentsViewModel>();
                MongoRepository taskmongorepo        = new MongoRepository("Tasks", _appSettings);
                MongoRepository taskcommentmongorepo = new MongoRepository("TaskComments", _appSettings);
                var             ret  = taskmongorepo.Find <Tasks>(t => t.groupId == groupId && t.recipientUserId == recipientUserId && t.taskStatus == Domain.Socioboard.Enum.TaskStatus.Completed);
                var             task = Task.Run(async() =>
                {
                    return(await ret);
                });
                IList <Tasks> lstTask = task.Result.ToList();
                foreach (Tasks item in lstTask)
                {
                    TaskCommentsViewModel taskCommentsViewModel = new TaskCommentsViewModel();
                    var ret1  = taskcommentmongorepo.Find <TaskComments>(t => t.taskId == item.strId);
                    var task1 = Task.Run(async() =>
                    {
                        return(await ret1);
                    });
                    taskCommentsViewModel.tasks = item;
                    taskCommentsViewModel.user  = _dbr.FindSingle <User>(t => t.Id == item.senderUserId);
                    IList <TaskComments>        lstTaskComment      = task1.Result.ToList();
                    List <TaskCommentViewModel> lstCommentViewModel = new List <TaskCommentViewModel>();
                    foreach (TaskComments item1 in lstTaskComment)
                    {
                        TaskCommentViewModel commentViewModel = new TaskCommentViewModel();
                        commentViewModel.taskComments = item1;
                        commentViewModel.user         = _dbr.FindSingle <User>(t => t.Id == item1.userId);
                        lstCommentViewModel.Add(commentViewModel);
                    }

                    taskCommentsViewModel.lstTaskComments = lstCommentViewModel;
                    lstTaskCommentsViewModel.Add(taskCommentsViewModel);
                }
                return(lstTaskCommentsViewModel);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new List <TaskCommentsViewModel>());
            }
        }