コード例 #1
0
        public async Task <Response <CompanyDTO> > Update(Guid companyId, Guid userId, CompanyUpdateDTO dto)
        {
            var companyUser = await _companiesUsersRepository.GetCompanyUser(companyId, userId);

            if (companyUser == null)
            {
                return(new BusinessConflictErrorResponse <CompanyDTO>(new []
                {
                    new Error
                    {
                        Code = ErrorCodes.Common.NotFound,
                        Message = ErrorMessages.Common.NotFound,
                        Field = "userId"
                    }
                }));
            }

            if (companyUser.Status != MembershipStatus.SuperAdmin)
            {
                return(new ForbiddenErrorResponse <CompanyDTO>(new []
                {
                    new Error
                    {
                        Code = ErrorCodes.Security.Forbidden,
                        Message = ErrorMessages.Security.Forbidden
                    }
                }));
            }

            var companyEntity = await _repository.GetById(companyId);

            if (companyEntity == null)
            {
                return(new BusinessConflictErrorResponse <CompanyDTO>(new []
                {
                    new Error
                    {
                        Code = ErrorCodes.Common.NotFound,
                        Message = ErrorMessages.Common.NotFound,
                        Field = "companyId"
                    }
                }));
            }

            companyEntity.Name    = dto.Name;
            companyEntity.Address = dto.Address;

            companyEntity = await _repository.Update(companyEntity);

            var result = _mapper.Map <CompanyModel, CompanyDTO>(companyEntity);

            return(new Response <CompanyDTO>
            {
                Data = result
            });
        }
コード例 #2
0
        public async Task <Response <CompanyDTO> > GetById(Guid id)
        {
            var entity = await _repository.GetById(id);

            var result = _mapper.Map <CompanyModel, CompanyDTO>(entity);

            return(new Response <CompanyDTO>
            {
                Data = result
            });
        }
コード例 #3
0
ファイル: CompanyService.cs プロジェクト: pekoe09/tapir
        public CompanyDTO GetCompany(int id)
        {
            Company company = companiesRepository.GetById(id);

            if (company != null)
            {
                return(company.getDTO());
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public async Task <Response> SetCompanyStatus(Guid companyId, CompanyStatus status)
        {
            var companyEntity = await _companiesRepository.GetById(companyId);

            if (companyEntity == null)
            {
                return(new NotFoundErrorResponse());
            }

            if (companyEntity.Status == status)
            {
                return(new Response());
            }

            companyEntity.Status = status;
            await _companiesRepository.Update(companyEntity);

            return(new Response());
        }
コード例 #5
0
        public async Task <IActionResult> Update(long id, CompanyDTO companyDTO)
        {
            try
            {
                // get company by id
                Company company = await _companiesRepository.GetById(id);

                // change data with with dto
                company.UpdateByDTO(companyDTO);
                // update model
                await _companiesRepository.Update(company);

                return(Ok());
            }
            catch (InvalidOperationException)
            {
                return(NotFound("None existing company"));
            }
        }
コード例 #6
0
 public Company GetById(int id)
 {
     return(_repository.GetById(id));
 }