public async Task <JoinChannelResultModel> JoinToGroupChannel(JoinChannelRequestModel model) { var user = await _authService.GetAuthorizedUser(); var channel = await DbContext.ChatChannels.FindAsync(model.ChannelId); if (channel == null) { channel = new ChatChannel(); await DbContext.AddAsync(channel); await DbContext.SaveChangesAsync(); } var channelUser = new ChatChannelUser { UserId = user.Id, ChannelId = channel.Id }; await DbContext.AddAsync(channelUser); await DbContext.SaveChangesAsync(); await _chatProvider.UserJoinedToChannel(user, channel.Id); return(new JoinChannelResultModel { ChannelId = channel.Id }); }