Exemplo n.º 1
0
        public async Task <DeviceModel> GetById(string token, Guid id)
        {
            var device = await _deviceRepository.GetByAsync(x => x.Id == id);

            var companyId = await _validationHelper.GetCompanyIdByPermission(token, new [] { Const.Permissions.Device.AdminRead });

            if (companyId != null && device.CompanyId != companyId)
            {
                throw new AccessException();
            }
            var result = device.Adapt <DeviceModel>();

            result.Branch = await _httpService.GetBranchById(device.BranchId, token);

            result.Company = await _httpService.GetCompanyById(device.CompanyId, token);

            return(result);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public async Task ValidateCompanyAndBranch(int companyId, Guid branchId, string token)
        {
            var company = await _httpService.GetCompanyById(companyId, token);

            if (company == null)
            {
                throw new ApplicationException($"Company with id: {companyId.ToString()} does not exist");
            }
            var branch = await _httpService.GetBranchById(branchId, token);

            if (branch == null)
            {
                throw new ApplicationException($"Branch with id: {branchId.ToString()} does not exist");
            }
            if (branch.CompanyId != company.Id)
            {
                throw new ApplicationException($"Branch with id: {branchId.ToString()} has not company with id: {companyId.ToString()}");
            }
        }