public IResult AddCategory(Category category, int mainCategoryId = -1) { if (mainCategoryId == -1) { try { _categoryDal.Add(category); return(new SuccessResult()); } catch (Exception) { return(new ErrorResult(Messages.ErrorWhileAddingEntity)); } } try { _categoryDal.Add(category); var addedCategory = _categoryDal.Get(c => c.CategoryName == category.CategoryName); var subCategory = new SubCategory { CategoryId = mainCategoryId, SubCategoryId = addedCategory.CategoryId }; _subCategoryDal.Add(subCategory); return(new SuccessResult()); } catch (Exception e) { return(new ErrorResult(Messages.ErrorWhileAddingEntity)); } }
public IResult Create(SubCategory entity) { _subCategoryDal.Add(entity); return(new SuccessResult(Messages.SubCategoryCreated)); }