Пример #1
0
        public async Task <int> AddAsync(string title, string author, int year)
        {
            var id = await repository.AddAsync(title, author, year);

            if (id > 0)
            {
                logger.LogDebug($"Clean cache: {GetAllCacheKey}");
                cache.Remove(GetAllCacheKey);
            }

            return(id);
        }
Пример #2
0
        public async Task <IActionResult> PostAsync(CreateOrUpdateBookModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var title  = model.Title;
            var author = model.Author;
            var year   = model.Year;
            var id     = await books.AddAsync(title, author, year);

            if (id <= 0)
            {
                return(StatusCode(500));
            }

            return(CreatedAtAction("Get", new { id, title }));
        }