Exemplo n.º 1
0
        public async Task <OffchainClosingResponse> CreateChannelAsync(CreateChannelData data)
        {
            var request = new CreateChannelModel(data.ClientPubKey, data.HubAmount, data.AssetId, data.Required, !string.IsNullOrWhiteSpace(data.ExternalTransferId) ? Guid.Parse(data.ExternalTransferId) : (Guid?)null, data.ClientAmount);

            var response = await _apiClient.ApiOffchainCreatechannelPostAsync(request);

            return(PrepareOffchainClosingResult(response));
        }
Exemplo n.º 2
0
        public async Task <CashoutOffchainApiResponse> CreateUnsignedChannel([FromBody] CreateChannelModel model)
        {
            var asset = await GetAsset(model.Asset);

            var tr = await _offchain.CreateUnsignedChannel(model.ClientPubKey, model.HubAmount, asset
                                                           , model.RequiredOperation, model.TransferId, model.ClientAmount);

            return(new CashoutOffchainApiResponse(tr));
        }
Exemplo n.º 3
0
        public IHttpActionResult Post([FromBody] CreateChannelModel command)
        {
            if (command == null || !ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }
            ValidateChannel(command.Name, command.ShortName);
            var channel = _mapper.Map <Channel>(command);

            _channelsRepository.Add(channel);
            return(Ok());
        }
Exemplo n.º 4
0
        public IHttpActionResult Put(int id, [FromBody] CreateChannelModel command)
        {
            if (command == null || !ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }
            var channel = _channelsRepository.GetById(id);

            channel = UpdateChannel(channel, command);
            _channelsRepository.Add(channel);
            return(Ok());
        }
Exemplo n.º 5
0
        public IActionResult Create(Guid groupId)
        {
            var groupFromDb = _chatService.GetAllGroups().FirstOrDefault(g => g.Id.GetHashCode().ToString() == groupId.ToString());

            CreateChannelModel model = new CreateChannelModel()
            {
                groupId = groupId
            };


            return(View("Views/Channel/Create.cshtml", model));
        }
Exemplo n.º 6
0
        public IActionResult CreatePost(CreateChannelModel model)
        {
            if (ModelState.IsValid)
            {
                var group   = _chatService.GetAllGroups().FirstOrDefault(g => g.Id == model.groupId);
                var channel = _chatService.GetAllChannels().FirstOrDefault(c => c.GroupId == group.Id);

                var newChat = new Chat()
                {
                    Id       = Guid.NewGuid(),
                    ChatType = ChatType.Group,
                    Messages = new List <Message>(),
                    Group    = group,
                    GroupId  = group.Id
                };

                _chatService.InsertChat(newChat);
                _chatService.SaveChanges();

                var chatFromDb = _chatService.GetAllChats().FirstOrDefault(c => c.Id == newChat.Id);


                var newChannel = new Channel()
                {
                    //Id = Guid.NewGuid(),
                    Name    = model.Name,
                    GroupId = group.Id,
                    Group   = group,
                    Chat    = chatFromDb,
                    ChatId  = chatFromDb.Id
                };

                _chatService.InsertChannel(newChannel);

                _chatService.SaveChanges();

                group.Channels.Add(newChannel);
                _chatService.SaveChanges();

                var groupFromDbWithChannel = _chatService.GetAllGroups().FirstOrDefault(g => g.Id == model.groupId);

                var channelFromDb = _chatService.GetAllChannels().FirstOrDefault(c => c.Id == newChannel.Id && c.GroupId == groupFromDbWithChannel.Id);

                return(RedirectToAction("Join", "Channel", new { channelId = channelFromDb.Id }));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 7
0
        public void CreateChannel(CreateChannelModel model)
        {
            var tagNames = model.Tags.Split(new[] { ", ", "," }, StringSplitOptions.RemoveEmptyEntries);


            var type    = Enum.Parse <ChannelType>(model.Type, true);
            var channel = new Channel
            {
                Name        = model.Name,
                Description = model.Description,
                Type        = type
            };

            context.Channels.Add(channel);
            context.SaveChanges();

            var tags = new List <Tag>();

            foreach (var name in tagNames)
            {
                var tag = this.context.Tags.FirstOrDefault(p => p.Name == name);
                if (tag == null)
                {
                    tag = new Tag
                    {
                        Name = name
                    };
                }
                tags.Add(tag);
            }

            context.AddRange(tags);
            context.SaveChanges();

            var channelTags = new List <ChannelTag>();

            foreach (var tag in tags)
            {
                var channelTag = new ChannelTag
                {
                    Channel = channel,
                    Tag     = tag
                };

                channelTags.Add(channelTag);
            }
            context.ChannelTags.AddRange(channelTags);
            context.SaveChanges();
        }
Exemplo n.º 8
0
        public IHttpResponse Create(CreateChannelModel model)
        {
            if (!this.Request.Cookies.ContainsCookie("auth"))
            {
                return(this.Redirect("/"));
            }

            if (!this.User.IsAdmin)
            {
                return(this.Redirect("/"));
            }

            this.channelService.CreateChannel(model);
            return(this.Redirect("/"));
        }
Exemplo n.º 9
0
        public IHttpResponse Create(CreateChannelModel model)
        {
            var user = this.userService.GetUser(this.User.Username);

            if (user == null)
            {
                return(this.Redirect("/"));
            }

            if (!this.channelService.AddChannel(
                    model.Name,
                    model.Description,
                    model.Tags,
                    model.Type,
                    user))
            {
                return(this.BadRequestErrorWithView("Invalid channel data."));
            }

            return(this.Redirect("/"));
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='model'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task <object> ApiOffchainCreatechannelPostAsync(this IBitcoinApi operations, CreateChannelModel model = default(CreateChannelModel), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.ApiOffchainCreatechannelPostWithHttpMessagesAsync(model, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='model'>
 /// </param>
 public static object ApiOffchainCreatechannelPost(this IBitcoinApi operations, CreateChannelModel model = default(CreateChannelModel))
 {
     return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IBitcoinApi)s).ApiOffchainCreatechannelPostAsync(model), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemplo n.º 12
0
 /// <summary>
 /// update Channel values
 /// </summary>
 /// <param name="channel">existing channel value</param>
 /// <param name="command">input parameter</param>
 /// <returns>channel value</returns>
 private Channel UpdateChannel(Channel channel, CreateChannelModel command)
 {
     channel.Name      = command.Name;
     channel.ShortName = command.ShortName;
     return(channel);
 }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='model'>
 /// </param>
 public static object ApiOffchainCreatechannelPost(this IBitcoinApi operations, CreateChannelModel model = default(CreateChannelModel))
 {
     return(operations.ApiOffchainCreatechannelPostAsync(model).GetAwaiter().GetResult());
 }