Example #1
0
        public async Task <GroupViewModel> Handle(CreateGroupCommand request, CancellationToken cancellationToken)
        {
            var myId  = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var group = new Domain.AggregatesModel.GroupAggregate.Group(request.Name, request.Avatar, myId, request.MemberIds);

            _groupRepository.Add(group);

            if (await _groupRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken))
            {
                // BackwardCompatibility: 为了兼容以前的聊天服务,需要向redis写入相关数据
                await UpdateRedisAsync(group);

                return(await _groupQueries.GetGroupAsync(group.Id, null));
            }

            throw new ApplicationException("操作失败");
        }
        public async Task <ActionResult <ResponseWrapper> > GetGroupAsync([FromQuery(Name = "groupId")] Guid?groupId, [FromQuery(Name = "oldGroupId")] int?oldGroupId)
        {
            var result = await _groupQueries.GetGroupAsync(groupId, oldGroupId);

            return(Ok(ResponseWrapper.CreateOkResponseWrapper(result)));
        }