Beispiel #1
0
        public int Add(Category category)
        {
            _context.Categories.Add(category);
            _context.SaveChanges();

            //0109 - activity
            _activityRepository.CategoryActivities(category, "added");
            return(category.Id);
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var category = await _context.Categories.FindAsync(id);

            if (category == null)
            {
                return(NotFound());
            }
            try
            {
                //if (!_categoryRepository.HasArticleInCategory(id))
                if (!_categoryRepository.HasArticleInCategoryOrParentCategoryOrChildren(id))
                {
                    _context.Categories.Remove(category);
                    await _context.SaveChangesAsync();

                    //0109
                    _activityRepository.CategoryActivities(category, "deleted");

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    log.Info("Category Has Articles!");
                    //vrati se
                    return(BadRequest("Category Has Articles!"));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ModelState.AddModelError("Exception", ex.Message);
                return(View(category));
            }
        }