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 }); }
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 }); }
public CompanyDTO GetCompany(int id) { Company company = companiesRepository.GetById(id); if (company != null) { return(company.getDTO()); } else { return(null); } }
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()); }
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")); } }
public Company GetById(int id) { return(_repository.GetById(id)); }