public async Task <IActionResult> AddChannel( [FromBody] AddChannelRequest req) { Ulid userId; { var id = HttpContext.User.Claims.Where(claim => claim.Type == "sub") .Select(claim => claim.Value) .Single(); if (Ulid.TryParse(id, out var res)) { userId = res; } else { return(BadRequest(new ErrorResult( "Bad userId", "Malformed bearer token. Please authorize again!"))); } } if (req.channelName != null && await db.ChannelNameExists(req.channelName)) { return(BadRequest( new ErrorResult( "Channel already exists", "The name of this channel is already taken"))); } return(Ok( await this.db.NewMailingChannel( req.channelName, req.isPublic, req.channelTitle, userId))); }
public async Task <IActionResult> Add([FromBody] AddChannelRequest request) { try { string userClaims = _httpContextAccessor.HttpContext.User.FindFirst("User").Value; AuthenticateUserResponse userResponse = JsonConvert.DeserializeObject <AuthenticateUserResponse>(userClaims); var response = _serviceChannel.AddChannel(request, userResponse.Id); return(await ResponseAsync(response, _serviceChannel)); } catch (Exception ex) { return(await ResponseExceptionAsync(ex)); } }
public ChannelResponse AddChannel(AddChannelRequest request, Guid idUser) { User user = _repositoryUser.Get(idUser); Channel channel = new Channel(request.Name, request.UrlLogo, user); AddNotifications(channel); if (this.IsInvalid()) { return(null); } channel = _repositoryChanner.Add(channel); return((ChannelResponse)channel); }