コード例 #1
0
        public async Task <IActionResult> Delete(BookKeyModel key)
        {
            var book = await GetBookAsync(key);

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

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(View(book));
        }
コード例 #2
0
        public async Task <IActionResult> Index(BookKeyModel key)
        {
            var book = await GetBookAsync(key);

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

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var viewModel = await _dataService.GetBookViewAsync(book.BookId);

            return(View(viewModel));
        }
コード例 #3
0
        private async Task <BookModel> GetBookAsync(BookKeyModel key)
        {
            if (key == null || key.BookId == null || key.Token == null)
            {
                return(null);
            }
            var book = await _dataService.GetBookAsync(key.BookId.Value);

            if (book == null)
            {
                return(null);
            }
            if (!book.Token.TimingSafeEquals(key.Token))
            {
                return(null);
            }
            return(book);
        }
コード例 #4
0
        public async Task <IActionResult> Delete(BookKeyModel key, DeleteBookModel model)
        {
            var book = await GetBookAsync(key);

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

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

            await _dataService.DeleteBookAsync(book.BookId);

            return(RedirectToAction("Index", "Home"));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(BookKeyModel key)
        {
            var book = await GetBookAsync(key);

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

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(View(new EditBookModel
            {
                Name = book.Name
            }));
        }
コード例 #6
0
        public async Task <IActionResult> AddRecipe(BookKeyModel bookKey, AddRecipeModel model)
        {
            var book = await GetBookAsync(bookKey);

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

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

            var recipeKey = await _dataService.CreateRecipeAsync(book.BookId, model);

            recipeKey.Token = bookKey.Token;
            return(RedirectToAction("Index", "Recipe", recipeKey));
        }
コード例 #7
0
        public async Task <IActionResult> AddRecipe(BookKeyModel key)
        {
            var book = await GetBookAsync(key);

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

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(View(new AddRecipeModel
            {
                Servings = 4
            }));
        }
コード例 #8
0
        public async Task <IActionResult> Edit(BookKeyModel key, EditBookModel model)
        {
            var book = await GetBookAsync(key);

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

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

            if (book.Name != model.Name)
            {
                await _dataService.RenameBookAsync(book.BookId, model.Name);
            }

            return(RedirectToAction("Index"));
        }