Пример #1
0
        public async Task ModifierAsync([Remainder] string parameters)
        {
            await Context.Channel.TriggerTypingAsync();

            string[] args   = parameters.Split(" ");
            ulong    userId = Context.Message.Author.Id;

            var textChannel = Context.Channel as ITextChannel;
            await textChannel.TriggerTypingAsync();

            var embed = new EmbedBuilder();

            switch (args[0])
            {
            case "create":
                if (args.Length == 2)
                {
                    embed.WithDescription($"Created playlist: {args[1]}");
                    embed.AddField("Begin adding songs with command:", ".list add <playlist name> <song name>", false);
                    await ReplyAsync(null, false, PlaylistService.CreatePlaylist(userId, args[1]));

                    return;
                }
                embed.WithDescription(".list create <playlist name>");
                await ReplyAsync(null, false, embed.Build());

                return;

            case "del":
                await ReplyAsync(null, false, PlaylistService.DeletePlaylist(userId, args[1]));

                return;

            case "add":
                if (args.Length > 2)
                {
                    var array = args.Where((item, index) => index >= 2).ToArray();
                    var name  = string.Join(" ", array);
                    await ReplyAsync(null, false, await PlaylistService.AddSongAsync(userId, args[1], name));

                    return;
                }
                embed.WithDescription(".list add <playlist name> <song name>");
                await ReplyAsync(null, false, embed.Build());

                return;

            case "rem":
                return;

            default:
                await ReplyAsync("unknown sub-command");

                return;
            }
        }
Пример #2
0
        public async Task <IActionResult> NewPlaylist(NewPlaylistModel model)
        {
            if (ModelState.IsValid)
            {
                var playlist = await _playlistService.CreatePlaylist(model.Title, model.Description);

                return(RedirectToAction("Playlist", new { Id = playlist.Id }));
            }

            return(View(model));
        }
        public async Task <IActionResult> CreatePlaylist([FromBody] PlaylistDto playlistDto)
        {
            int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims);

            var playlist = _mapper.Map <PlaylistDto, Playlist>(playlistDto);

            var response = await _playlistService.CreatePlaylist(userId, playlist);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            playlistDto = _mapper.Map <Playlist, PlaylistDto>(response.Resource);

            return(Ok(playlistDto));
        }
        public ActionResult Create(PlaylistCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new PlaylistService();

            if (service.CreatePlaylist(model))
            {
                TempData["SaveResult"] = "Playlist has been added";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Playlist was not added");
            return(View(model));
        }
Пример #5
0
        public async Task <IActionResult> CreatePlaylist(CreatePlaylistModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var playlist = await _service.CreatePlaylist(model);

                    SavePlaylistId(playlist.Id);

                    return(RedirectToAction(nameof(Playlist), new { playlist.Id }));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            return(View(model));
        }