Esempio n. 1
0
        public async Task <ActionResult <Book> > PostBook(Book book)
        {
            if (String.IsNullOrEmpty(book.Author) || String.IsNullOrEmpty(book.FileName) || String.IsNullOrEmpty(book.Name))
            {
                return(BadRequest());
            }
            _context.Books.Add(book);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBook", new { id = book.Id }, book));
        }
        public async Task AddRecipe(Recipe recipe)
        {
            _context.Recipes.Add(recipe);
            int n = await _context.SaveChangesAsync(); //n-число новых записей в таблице

            if (n > 0)
            {
                cache.Set(recipe.Id, recipe, new MemoryCacheEntryOptions
                {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
                });
            }
        }