public async Task<OperationResult<Category>> EditCategory(Category category) { var dbcategory = await _categoryRepository.GetSingleByName(category.CategoryName); if (dbcategory == null || dbcategory.CategoryID != category.CategoryID) return new OperationResult<Category>(false); await _categoryRepository.Edit(category); return new OperationResult<Category>(true) { Entity = category }; }
public static Category ToCategory(this CategoryRequestModel requestModel) { var category = new Category() { CategoryName = requestModel.CategoryName, Description = requestModel.Description }; if(requestModel.CategoryID.HasValue) category.CategoryID = requestModel.CategoryID.Value; return category; }
public async Task<OperationResult<Category>> AddCategory(Category category) { //buscar categoria por nome //se retornar algo, retornar false //se nao retornar nada, registrar if (await _categoryRepository.GetSingleByName(category.CategoryName) != null) return new OperationResult<Category>(false); await _categoryRepository.Add(category); return new OperationResult<Category>(true) { Entity = category }; }