Example #1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var model = await _context.Channels.FirstOrDefaultAsync(m => m.Id == id);

            if (model == null)
            {
                return(NotFound());
            }

            Channel = model.ToChannelEditModel();

            Countries = TZNames.GetCountryNames(CultureInfo.CurrentUICulture.Name)
                        .Select(x =>
                                new SelectListItem(x.Value, x.Key, x.Key == model.CountryCode));

            TimeZones = TimeZonesData.GetForCountry(model.CountryCode, null)
                        .Select(x =>
                                new SelectListItem(x.Value, x.Key, x.Key == model.TimeZoneId));

            return(Page());
        }
Example #2
0
        /// <summary>
        /// Modifies the current channel.
        /// </summary>
        /// <param name="action">Action to perform on this channel</param>
        /// <returns></returns>
        public Task ModifyAsync(Action <ChannelEditModel> action)
        {
            var mdl = new ChannelEditModel();

            action(mdl);
            return(this.Discord.ApiClient.ModifyChannelAsync(this.Id, mdl.Name, mdl.Position, mdl.Topic,
                                                             mdl.Parent.HasValue ? mdl.Parent.Value?.Id : default(Optional <ulong?>), mdl.Bitrate, mdl.Userlimit, mdl.AuditLogReason));
        }
        public Task ModifyChannelAsync(ulong channel_id, Action <ChannelEditModel> action)
        {
            var mdl = new ChannelEditModel();

            action(mdl);

            return(ApiClient.ModifyChannelAsync(channel_id, mdl.Name, mdl.Position, mdl.Topic, mdl.Nsfw,
                                                mdl.Parent.HasValue ? mdl.Parent.Value?.Id : default(Optional <ulong?>), mdl.Bitrate, mdl.Userlimit, mdl.PerUserRateLimit, mdl.AuditLogReason));
        }
Example #4
0
        public async Task <IActionResult> Post([FromBody] ChannelEditModel channel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Channel model;

            if (IsNewChannel(channel))
            {
                model = new Channel();
                _context.Channels.Add(model);
            }
            else
            {
                model = await _context.Channels
                        .Include(c => c.Tags)
                        .FirstOrDefaultAsync(c => c.Id == channel.Id);
            }

            model.ApplyEditChanges(channel);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChannelExists(channel.Id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(Ok());

            bool ChannelExists(int id)
            {
                return(_context.Channels.Any(e => e.Id == id));
            }

            bool IsNewChannel(ChannelEditModel c) => c.Id <= 0;
        }
        public async Task <IActionResult> Post([FromBody] ChannelEditModel channel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                if (IsNewChannel(channel))
                {
                    Channel model = new Channel();
                    model.ApplyEditChanges(channel);

                    var userId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;

                    await _channelService.Create(model, userId);
                }
                else
                {
                    Channel model = _channelService.GetAggregate(channel.Id);
                    model.ApplyEditChanges(channel);
                    await _channelService.Update(model);
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await ChannelExists(channel.Id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(Ok());

            bool IsNewChannel(ChannelEditModel c) => c.Id <= 0;
        }
Example #6
0
        public async Task <IActionResult> Post([FromBody] ChannelEditModel channel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                if (IsNewChannel(channel))
                {
                    Channel model = new Channel();
                    model.ApplyEditChanges(channel);
                    await _channelService.Create(model);
                }
                else
                {
                    Channel model = _channelService.GetAggregate(channel.Id);
                    model.ApplyEditChanges(channel);
                    await _channelService.Update(model);
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await ChannelExists(channel.Id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(Ok());

            bool IsNewChannel(ChannelEditModel c) => c.Id <= 0;
        }