public async Task <IActionResult> GetByIdAsync(int id) { var category = await _categoryDal.GetAsync(p => p.Id == id); if (category == null) { return(BadRequest()); } return(Ok(category)); }
public async Task <IDataResult <Category> > GetByIdAsync(int id) { try { return(new SuccessDataResult <Category>(await _categoryDal.GetAsync(p => p.CategoryId == id))); } catch (Exception ex) { return(new ErrorDataResult <Category>(await _categoryDal.GetAsync(p => p.CategoryId == id), ex.Message)); } }
public async Task <Category> GetCategoryByName(string name) { var category = await _categoryDal.GetAsync(c => c.Name == name); if (category == null) { throw new Exception(name + "category did not find"); } return(category); }
public IDataResult <Category> GetAsync(Expression <Func <Category, bool> > filter) { var _getAsync = _categoryDal.GetAsync(filter).Result; if (_getAsync == null) { return(new ErrorDataResult <Category>(CategoryMessages.RecordNotFound)); } return(new SuccessDataResult <Category>(_getAsync, CategoryMessages.CategoryListed)); }
public async Task <IResult> Handle(UpdateCategoryCommand request, CancellationToken cancellationToken) { var categoryToUpdate = await _categoryDal.GetAsync(u => u.CategoryId == request.CategoryId); categoryToUpdate.CategoryName = request.CategoryName; categoryToUpdate.CategoryId = request.CategoryId; await _categoryDal.UpdateAsync(categoryToUpdate); return(new SuccessResult(Messages.Updated)); }
public async Task <IResult> Handle(CreateCategoryCommand request, CancellationToken cancellationToken) { var categoryExits = await _categoryDal.GetAsync(u => u.CategoryName == request.CategoryName); if (categoryExits != null) { return(new ErrorResult(Messages.NameAlreadyExist)); } var category = new Category { CategoryName = request.CategoryName }; await _categoryDal.AddAsync(category); return(new SuccessResult(Messages.Added)); }
public async Task <IDataResult <Category> > GetByIdAsync(int id) { var result = await _categoryDal.GetAsync(c => c.Id == id); return(new SuccessDataResult <Category>(result, Messages.Category.GetByIdSuccess)); }
public async Task <Category> GetAsync(Expression <Func <Category, bool> > filter) { var cancelToken = new CancellationTokenSource(); return(await _categoryDal.GetAsync(filter, cancelToken.Token)); }