public T AddCategory <T>(T entity) where T : ProductCategoryModel { var categoryCriteria = new CategoryCriteria() { Name = entity.Name }; if (AnyCategory(categoryCriteria)) { return(null); } var newEntity = _mapper.Map <Category>(entity); newEntity.CreationDate = DateTime.Now; _context.Categories.Add(newEntity); _context.SaveChanges(); return(_mapper.Map <T>(newEntity)); }
private bool AnyCategory(CategoryCriteria categoryCriteria) { return(_context.Categories.Any(categoryCriteria.Match())); }