public async Task <IActionResult> Add(ChannelCreateDto model) { if (User.FindFirst(ClaimTypes.NameIdentifier) == null) { return(BadRequest()); } var channel = new Channel(); channel.CreateChannel(model); channel.CreatorId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; _context.Channels.Add(channel); var result = await _context.SaveChangesAsync(); if (result > 0) { var response = new ResponseDto <ChannelDto>(); response.Status = true; response.Message = "Channel successfully created"; response.Data = _mapper.Map <ChannelDto>(channel); return(Ok(response)); } return(BadRequest()); }
public async Task <ActionResult <int> > CreateChannelAsync(ChannelCreateDto channelCreateDto) { var id = await _channelCommandService.CreateChannelAsync(channelCreateDto.Name, User.GetUserId(), User.GetWorkspaceId(), channelCreateDto.Topic); await _channelCommandService.AddUserToChannelAsync(id, User.GetUserId(), User.GetWorkspaceId()); return(Ok(id)); }
public static Channel CreateChannel(this Channel u, ChannelCreateDto model) { u.Id = Guid.NewGuid().ToString(); u.Name = model.Name; return(u); }