Beispiel #1
0
        public async Task CreateAsync(CreateDeckInputModel input, string userId)
        {
            var channelId = this.channelService.GetChannelIdByName(input.ChannelName);

            if (channelId == null)
            {
                return;
            }

            if (this.context.Decks
                .Any(x => x.UserId == userId && x.ChannelId == channelId && x.Name == input.Name))
            {
                return;
            }

            var deck = new Deck()
            {
                Name      = input.Name,
                ChannelId = channelId,
                UserId    = userId
            };

            await this.context.Decks.AddAsync(deck);

            await this.context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <ActionResult> Create([FromBody] CreateDeckInputModel input)
        {
            var userId = this.userManager.GetUserId(this.User);

            await this.decksService.CreateAsync(userId, input.Name, input.Description);

            return(this.Ok());
        }
        public async Task <IActionResult> Create(CreateDeckInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", new { input.ChannelName }));
            }

            var user = await this.userManager.GetUserAsync(User);

            await this.deckService.CreateAsync(input, user.Id);

            return(RedirectToAction("Index", new { input.ChannelName }));
        }