コード例 #1
0
        public async Task <IOutput> Handle(AddCommentInput request, CancellationToken cancellationToken)
        {
            var currentUser = await _currentUserProvider.GetCurrentUser();

            if (currentUser is null)
            {
                return(ActionOutput.Error("Пользователь не найден"));
            }

            var lesson = await _context.Lessons.FirstOrDefaultAsync(
                x => x.Id == request.LessonId,
                cancellationToken : cancellationToken);

            if (lesson is null)
            {
                return(ActionOutput.Error("Урок не найден"));
            }

            var comment = new Entity.Comment(request.Text, currentUser, lesson);

            await _context.Comments.AddAsync(comment, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(ActionOutput.SuccessData(comment.Id));
        }
コード例 #2
0
 public async Task CreateOrEditAsync(Entity.Comment model)
 {
     model.TenantId = _AbpSession.TenantId ?? 0;
     if (model.Id <= 0)
     {
         await _Repository.InsertAsync(model);
     }
     else
     {
         await _Repository.UpdateAsync(model);
     }
 }