Пример #1
0
        public async Task <IActionResult> AddItem(Repertorie newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            var successful = await _repertoryService.AddItemAsync(newItem);

            if (!successful)
            {
                return(BadRequest("Could not add item."));
            }
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <bool> AddItemAsync(Repertorie newItem)
        {
            if (newItem.SongId == null && string.IsNullOrEmpty(newItem.Comments))
            {
                return(true);
            }

            newItem.Index = _context.Repertorie.Count() + 1;

            _context.Repertorie.Add(newItem);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }