Example #1
0
        public async Task <IActionResult> Edit(string id, Book book)
        {
            if (int.Parse(id) != book.BookId)
            {
                return(NotFound());
            }
            bool isAdmin = await _cs.IsItAdminAsync(User.Identity.Name);

            if (!isAdmin)
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _bc.UpdateAsync(book);

                    await _bc.CommitAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }