Esempio n. 1
0
        public async Task <IActionResult> AddChannel(
            Guid?id, string token, AddChannelModel model)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            if (token == null)
            {
                return(BadRequest());
            }

            var list = await _listService.GetListAsync(id.Value);

            if (list == null)
            {
                return(BadRequest());
            }
            if (TokenUtils.NotEqual(token, list.TokenString))
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var channel = await _channelService.GetOrCreateChannelAsync(model.Url);

            if (channel == null)
            {
                ModelState.AddModelError("Url", "Cannot find channel on YouTube.");
                return(View(model));
            }

            await _listService.AddChannelAsync(list.Id, channel.Id);

            return(RedirectToAction("Index"));
        }