/// <summary> /// Method for getting stat. units by Id and type /// </summary> /// <param name = "id"> Id stat. units </param> /// <param name = "type"> Type of stat. units </param> /// <param name = "userId"> User Id </param> /// <param name = "showDeleted"> Distance flag </param> /// <returns> </returns> public async Task <object> GetUnitByIdAndType(int id, StatUnitTypes type, string userId, bool showDeleted) { var item = await _commonSvc.GetStatisticalUnitByIdAndType(id, type, showDeleted); if (item == null) { throw new BadRequestException(nameof(Resource.NotFoundMessage)); } async Task FillRegionParents(Address address) { if (address?.Region?.ParentId == null) { return; } address.Region.Parent = await _regionService.GetRegionParents(address.Region.ParentId.Value); } await FillRegionParents(item.Address); await FillRegionParents(item.ActualAddress); await FillRegionParents(item.PostalAddress); var dataAttributes = await _userService.GetDataAccessAttributes(userId, item.UnitType); foreach (var person in item.PersonsUnits) { if (person.PersonTypeId != null) { person.Person.Role = (int)person.PersonTypeId; } } return(SearchItemVm.Create(item, item.UnitType, dataAttributes.GetReadablePropNames())); }