public async Task <Result <EcommerceCategoryResponse> > Handle(GetEcommerceCategoryByIdQuery query, CancellationToken cancellationToken) { var item = await _repository.GetByIdAsync(query.Id); var mapped = _mapper.Map <EcommerceCategoryResponse>(item); return(Result <EcommerceCategoryResponse> .Success(mapped)); }
public async Task <Result <int> > Handle(DeleteEcommerceCategoryCommand command, CancellationToken cancellationToken) { var item = await _repository.GetByIdAsync(command.Id); await _repository.DeleteAsync(item); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(item.Id)); }
public async Task <Result <int> > Handle(UpdateEcommerceCategoryCommand command, CancellationToken cancellationToken) { var item = await _repository.GetByIdAsync(command.Id); if (item == null) { return(Result <int> .Fail($"EcommerceCategory Not Found.")); } else { if (command.ParentId == null) { item.Level = 1; } else { var category = await _repository.GetByIdAsync((int)command.ParentId); Throw.Exception.IfNull(category, "EcommerceCategory", "No EcommerceCategory ParentId Found"); item.Level = category.Level + 1; } item.Name = command.Name ?? item.Name; item.ParentId = command.ParentId ?? item.ParentId; item.Slug = command.Slug ?? item.Slug; item.Description = command.Description ?? item.Description; item.MetaTitle = command.MetaTitle ?? item.MetaTitle; item.MetaDescription = command.MetaDescription ?? item.MetaDescription; item.Position = command.Position ?? item.Position; item.IncludeInMenu = command.IncludeInMenu ?? item.IncludeInMenu; item.Position = command.Position ?? item.Position; item.Icon = command.Icon ?? item.Icon; item.Image = command.Image ?? item.Image; item.Tags = command.Tags ?? item.Tags; await _repository.UpdateAsync(item); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(item.Id)); } }
public async Task <Result <int> > Handle(CreateEcommerceCategoryCommand request, CancellationToken cancellationToken) { var item = _mapper.Map <EcommerceCategory>(request); if (request.ParentId == null) { item.Level = 1; } else { var category = await _repository.GetByIdAsync((int)request.ParentId); Throw.Exception.IfNull(category, "EcommerceCategory", "No EcommerceCategory ParentId Found"); item.Level = category.Level + 1; } await _repository.InsertAsync(item); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(item.Id)); }