Example #1
0
        public async Task <IActionResult> CreateChannel([FromForm] CreateChannelAddressModel model)
        {
            var token = await _dbContext.AccessTokens.Include(t => t.ApplyApp).SingleOrDefaultAsync(t => t.Value == model.AccessToken);

            if (token == null || token.ApplyApp == null)
            {
                return(Protocal(ErrorType.Unauthorized, "Invalid accesstoken!"));
            }
            //Create and save to database
            var newChannel = new Channel
            {
                Description = model.Description,
                ConnectKey  = StringOperation.RandomString(20),
                AppId       = token.ApplyAppId
            };

            _dbContext.Channels.Add(newChannel);
            await _dbContext.SaveChangesAsync();

            //return model
            var viewModel = new CreateChannelViewModel
            {
                ChannelId  = newChannel.Id,
                ConnectKey = newChannel.ConnectKey,
                code       = ErrorType.Success,
                message    = "Successfully created your channel!"
            };

            return(Json(viewModel));
        }
Example #2
0
        public async Task <IActionResult> CreateChannel(CreateChannelViewModel model)
        {
            //check if the channel name is already taken
            var workspace = await _context.Workspace
                            .Where(ws => ws.Name == model.WorkspaceName).SingleOrDefaultAsync();

            List <Channel> workspaceChannels = await _context.Channel
                                               .Where(ch => ch.Workspace.ID == workspace.ID).ToListAsync();

            foreach (Channel ch in workspaceChannels)
            {
                if (ch.Name.Equals(model.Name))
                {
                    return(Json(new { result = "That name is already taken." }));
                }
            }

            //create channel, add current user to it and redirect to the new channel
            var channel = new Channel {
                Name = model.Name, General = false, OwnerID = model.OwnerID, Type = model.Type, Workspace = workspace
            };

            _context.Add(channel);
            var channelMembership = new ChannelMembership {
                JoinDate = DateTime.Now, Channel = channel, ChannelID = channel.ID, ApplicationUserID = model.OwnerID
            };

            _context.Add(channelMembership);
            await _context.SaveChangesAsync();

            return(Json(new { result = "Redirect", url = Url.Action("Messages/" + model.WorkspaceName + "/" + channel.Name, "Workspaces") }));
        }
        public async Task <IActionResult> CreateChannel(CreateChannelAddressModel model)
        {
            //Update app info
            var appid    = _tokenManager.ValidateAccessToken(model.AccessToken);
            var appLocal = await _dbContext.Apps.SingleOrDefaultAsync(t => t.Id == appid);

            if (appLocal == null)
            {
                appLocal = new StargateApp
                {
                    Id = appid
                };
                await _dbContext.Apps.AddAsync(appLocal);
            }
            var channelId = _counter.GetUniqueNo();
            var key       = Guid.NewGuid().ToString("N");

            _stargateMemory.CreateChannel(channelId, appid, model.Description, key);
            //return model
            var viewModel = new CreateChannelViewModel
            {
                ChannelId  = channelId,
                ConnectKey = key,
                Code       = ErrorType.Success,
                Message    = "Successfully created your channel!"
            };

            return(Ok(viewModel));
        }
        public ChatGenericDialogBoxVue(string pannelInformation, bool showInput, string confirmBtnContent, string cancelBtnContent)
        {
            SizeToContent = SizeToContent.WidthAndHeight;
            DataContext   = new CreateChannelViewModel(showInput);
            InitializeComponent();
            dialogInformationTxt.Text = pannelInformation;
            dialogInputTxt.Visibility = showInput ? Visibility.Visible : Visibility.Collapsed;

            cancelBtn.Content  = cancelBtnContent;
            confirmBtn.Content = confirmBtnContent;
            Owner = App.Current.MainWindow;
        }
Example #5
0
        public async Task <IActionResult> CreateChannel([FromForm] CreateChannelViewModel model)
        {
            var channel = new Channel()
            {
                Caption = model.Caption, Name = model.Name, AdminId = model.AdminId
            };
            var result = await _ChannelService.CreateChannel(channel);

            if (result)
            {
                return(Ok(successfull));
            }
            return(BadRequest(failed));
        }
        public IActionResult Create(CreateChannelViewModel model)
        {
            if (!this.IsAuthenticated())
            {
                return(this.View());
            }

            if (!this.IsAdmin())
            {
                return(this.View());
            }

            bool enumParsed = Enum.TryParse(model.Type, true, out Type type);


            var channel = new Channel
            {
                Name        = this.DecodeString(model.Name),
                Description = model.Description,
                Type        = type
            };

            var tags = model.Tags.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var tag in tags)
            {
                var tagEntity = db.Tags.FirstOrDefault(t => t.Content == tag.Trim());

                if (tagEntity == null)
                {
                    var tagObject = new Tag
                    {
                        Content = tag.Trim()
                    };
                    this.db.Tags.Add(tagObject);
                    channel.Tags.Add(tagObject);
                }
                else
                {
                    channel.Tags.Add(tagEntity);
                }
            }
            this.db.Channels.Add(channel);
            db.SaveChanges();

            return(this.RedirectToAction($"/channels/details/?id={channel.Id}"));
        }
        public IActionResult Create(CreateChannelViewModel model)
        {
            if (this.Identity == null)
            {
                return(this.RedirectToAction("/users/login"));
            }

            var channel = new Channel()
            {
                Name        = WebUtility.UrlDecode(model.Name),
                Description = WebUtility.UrlDecode(model.Description),
                ChannelType = (ChannelType)Enum.Parse(typeof(ChannelType), model.ChannelType, true)
            };

            var tags = WebUtility.UrlDecode(model.Tags).Split(", ", StringSplitOptions.RemoveEmptyEntries)
                       .Select(t => new ChannelTag()
            {
                Tag = new Tag()
                {
                    Name = t
                },
                Channel = channel
            }).ToList();

            channel.Tags = tags;

            var channels = this.DbContext.Channels.ToList();

            if (channels.Any(ch => ch.Name == channel.Name))
            {
                return(this.View());
            }

            try
            {
                this.DbContext.Channels.Add(channel);
                this.DbContext.SaveChanges();
            }
            catch (Exception e)
            {
                throw new InternalServerException(e.Message);
            }

            return(this.RedirectToAction("/home/index"));
        }
        public IHttpResponse Create(CreateChannelViewModel model)
        {
            if (!Enum.TryParse(model.Type, true, out ChannelType channelType))
            {
                return(this.BadRequestErrorWithView("Invalid channel type!"));
            }

            var channel = new Channel
            {
                Name        = model.Name,
                Description = model.Description,
                Type        = channelType
            };

            if (!string.IsNullOrWhiteSpace(model.Tags))
            {
                var tags = model.Tags.Split(',', ';', StringSplitOptions.RemoveEmptyEntries);
                foreach (var tag in tags)
                {
                    var dbTag = this.db.Tags.FirstOrDefault(t => t.Name == tag.Trim());
                    if (dbTag == null)
                    {
                        dbTag = new Tag
                        {
                            Name = tag.Trim()
                        };

                        this.db.Tags.Add(dbTag);
                        this.db.SaveChanges();
                    }

                    channel.Tags.Add(new ChannelTag
                    {
                        TagId = dbTag.Id
                    });
                }
            }

            this.db.Channels.Add(channel);
            this.db.SaveChanges();

            return(this.Redirect($"/Channels/Details?id={channel.Id}"));
        }
Example #9
0
        public async Task <IActionResult> CreateChannel([FromForm] CreateChannelAddressModel model)
        {
            //Update app info
            var app = await ApiService.ValidateAccessTokenAsync(model.AccessToken);

            var appLocal = await _dbContext.Apps.Include(t => t.Channels).SingleOrDefaultAsync(t => t.Id == app.AppId);

            if (appLocal == null)
            {
                appLocal = new StargateApp
                {
                    Id       = app.AppId,
                    Channels = new List <Channel>()
                };
                _dbContext.Apps.Add(appLocal);
            }
            //Create and save to database
            var newChannel = new Channel
            {
                Description = model.Description,
                ConnectKey  = StringOperation.RandomString(20)
            };

            appLocal.Channels.Add(newChannel);
            await _dbContext.SaveChangesAsync();

            //return model
            var viewModel = new CreateChannelViewModel
            {
                ChannelId  = newChannel.Id,
                ConnectKey = newChannel.ConnectKey,
                code       = ErrorType.Success,
                message    = "Successfully created your channel!"
            };

            return(Json(viewModel));
        }
Example #10
0
        public async Task <IActionResult> CreateChannel(CreateChannelAddressModel model)
        {
            //Update app info
            var appid = await _tokenManager.ValidateAccessToken(model.AccessToken);

            var appLocal = await _dbContext.Apps.Include(t => t.Channels).SingleOrDefaultAsync(t => t.Id == appid);

            if (appLocal == null)
            {
                appLocal = new StargateApp
                {
                    Id       = appid,
                    Channels = new List <Channel>()
                };
                _dbContext.Apps.Add(appLocal);
            }
            //Create and save to database
            var newChannel = new Channel
            {
                Description = model.Description,
                ConnectKey  = Guid.NewGuid().ToString("N")
            };

            appLocal.Channels.Add(newChannel);
            await _dbContext.SaveChangesAsync();

            //return model
            var viewModel = new CreateChannelViewModel
            {
                ChannelId  = newChannel.Id,
                ConnectKey = newChannel.ConnectKey,
                Code       = ErrorType.Success,
                Message    = "Successfully created your channel!"
            };

            return(Json(viewModel));
        }
Example #11
0
        public IHttpResponse Create(CreateChannelViewModel model)
        {
            if (model.Name == null)
            {
                return(this.BadRequestErrorWithView("A channel must have name."));
            }

            if (!Enum.TryParse(model.Type, out ChannelType type))
            {
                return(this.BadRequestErrorWithView("Please select channel type."));
            }

            var channel = new Channel()
            {
                Name        = model.Name,
                Type        = type,
                Description = model.Description,
            };

            if (!string.IsNullOrWhiteSpace(model.Tags))
            {
                var tags = model.Tags
                           .Split(new[] { ';', ',', ' ', }, StringSplitOptions.RemoveEmptyEntries)
                           .ToArray();

                foreach (var tagName in tags)
                {
                    var tag = this.DbContext.Tags.FirstOrDefault(t => t.Name == tagName);
                    if (tag == null)
                    {
                        tag = new Tag()
                        {
                            Name = tagName.Trim()
                        };
                        this.DbContext.Tags.Add(tag);
                        try
                        {
                            this.DbContext.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            return(this.ServerError(e.Message));
                        }
                    }

                    channel.Tags.Add(new ChannelTag()
                    {
                        TagId = tag.Id
                    });
                }
            }

            this.DbContext.Channels.Add(channel);

            try
            {
                this.DbContext.SaveChanges();
            }
            catch (Exception e)
            {
                return(this.ServerError(e.Message));
            }

            return(this.Redirect("/channels/details?id=" + channel.Id));
        }