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));
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
            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));
            }
예제 #7
0
        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));
        }