public ActionResult CreateChannel(Guid token, [FromBody] CreateChannelDTO channel)
        {
            Session session = _loginService.ValidateUserContext(token);

            _logger.LogCritical("Session validated.");
            _logger.LogCritical($"Create Channel(Name={channel.Name}, Type={channel.Type}).");
            Guid channelId = _dataService.CreateChannel(session.User, channel);

            if (channelId == Guid.Empty)
            {
                return(BadRequest());
            }
            return(Created("https://localhost:5001/api/channel", channelId));
        }
Example #2
0
        public static Channel FromCreateChannelDTO(CreateChannelDTO model, User owner)
        {
            // Get the current time as we need this for created and modified to ensure
            // both contain the same value.
            var currentTime = DateTime.Now;

            // Create a channel object based on the model and current time.
            return(new Channel {
                Name = model.Name, Created = currentTime, Modified = currentTime, Members = new [] { new Member()
                                                                                                     {
                                                                                                         Role = MemberRole.OWNER, User = owner
                                                                                                     } }
            });
        }
Example #3
0
        public bool AddChannel(Guid sessionId, CreateChannelDTO channel, out string fixHint)
        {
            var request = new RestRequest("api/channel?token={session}", Method.POST);

            request.AddUrlSegment("session", sessionId);
            request.AddHeader("content-type", "application/json");
            request.AddBody(channel);
            var response2 = _client.Execute(request);

            if (ProcessResponse(response2, out fixHint))
            {
                return(true);
            }
            return(false);
        }
Example #4
0
        public async Task <ActionResult <ChannelDTO> > Create([FromBody] CreateChannelDTO model)
        {
            var channel = uMessageAPI.Models.Channel.FromCreateChannelDTO(model, await GetCurrentUserAsync());

            //var member = new Member() { ChannelId = channel.Id, Role = MemberRole.OWNER,User = GetCurrentUserAsync };
            // Create channel and assign a name.
            channelRepository.Add(channel);
            channelRepository.SaveChanges();
            // Check whether thechannel was successfully created.
            if (channel != null)
            {
                // Generate the channel response for given channel.
                return(Ok(ChannelDTO.FromChannel(channel)));
            }

            return(NotFound());
        }
Example #5
0
        public async Task <ActualResult <string> > CreateMainChannelAsync(CreateChannelDTO dto)
        {
            try
            {
                var channel = _mapper.Map <DimChannel>(dto);
                await _context.DimChannel.AddAsync(channel);

                await _context.SaveChangesAsync();

                return(new ActualResult <string> {
                    Result = channel.ChannelKey.ToString()
                });
            }
            catch (Exception exception)
            {
                return(new ActualResult <string>(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }
 public Guid CreateChannel(Guid user, CreateChannelDTO channel)
 {
     return(_repo.CreateChannel(user, channel.Name, channel.Type));
 }