Esempio n. 1
0
            public async Task <Result <CompanyResponse> > Handle(GetCurrentCompanyQuery query, CancellationToken cancellationToken)
            {
                var id = _authenticatedUser.Username;

                var item = await _repository.GetByUserNameAsync(id);

                Throw.Exception.IfNull(item, "Company", "No Company Found");
                var mappedCategory = _mapper.Map <CompanyResponse>(item);


                Expression <Func <CompanyIndustry, int> > expression = e => (int)e.IndustryId;
                var listIdIndustry = _companyIndustryRepository.CompanyIndustries.Where(x => x.CompanyId == item.Id).Select(expression).ToList();

                ICollection <Industry> list = new List <Industry>();

                foreach (var tmp in listIdIndustry)
                {
                    var item_industry = await _industryRepository.GetByIdAsync(tmp);

                    if (item_industry != null)
                    {
                        list.Add(item_industry);
                    }
                }

                mappedCategory.Industries = list;

                return(Result <CompanyResponse> .Success(mappedCategory));
            }
            public async Task <Result <IndustriesResponse> > Handle(GetIndustryByIdQuery query, CancellationToken cancellationToken)
            {
                var item = await _repository.GetByIdAsync(query.Id);

                var mappedCategory = _mapper.Map <IndustriesResponse>(item);

                return(Result <IndustriesResponse> .Success(mappedCategory));
            }
            public async Task <Result <int> > Handle(DeleteIndustryCommand 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(UpdateIndustryCommand command, CancellationToken cancellationToken)
        {
            var item = await _repository.GetByIdAsync(command.Id);

            if (item == null)
            {
                return(Result <int> .Fail($"JobAge Not Found."));
            }
            else
            {
                item.Name        = command.Name ?? item.Name;
                item.Code        = command.Code ?? item.Code;
                item.Description = command.Description ?? item.Description;
                await _repository.UpdateAsync(item);

                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(item.Id));
            }
        }