Пример #1
0
        public async Task <IActionResult> Search(SearchViewModel search)
        {
            VerseSearch result = null;

            if (ModelState.IsValid)
            {
                result = await _service.GetVerses(search.StartDate, search.TotalVerses);
            }

            return(View(result));
        }
        public async Task <bool> Add(SearchViewModel search)
        {
            if (!ModelState.IsValid)
            {
                return(false);
            }

            VerseSearch result = await _service.GetVerses(search.StartDate, search.TotalVerses);

            if (result == null)
            {
                throw new Exception("No verses found.");
            }

            if (_context.FavoriteVerses.Where(i => i.Id == search.Id).FirstOrDefault() == null)
            {
                var favorite = _service.GetVerseById(result.Verses, search.Id);
                await _context.AddAsync(favorite);

                await _context.SaveChangesAsync();
            }
            return(true);
        }