public InconsistentRecord(int regId, StatUnitTypes type, string name, string inconsistents) { RegId = regId; Type = type; Name = name; Inconsistents = inconsistents.Split(';').ToList(); }
public bool CheckWritePermissions(string userId, StatUnitTypes unitType) { var roleId = _userService.GetUserById(userId).UserRoles.Single().RoleId; var role = _roleService.GetRoleById(roleId); return(role.IsNotAllowedToWrite(unitType)); }
public InconsistentRecord(int regId, StatUnitTypes type, string name, List <string> inconsistents) { RegId = regId; Type = type; Name = name; Inconsistents = inconsistents; }
/// <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())); }
/// <summary> /// Delete / Restore stat. units /// </summary> /// <param name="unitType">Type of stat. units</param> /// <param name="id">Id stat. units</param> /// <param name="toDelete">Remoteness flag</param> /// <param name="userId">User ID</param> public void DeleteUndelete(StatUnitTypes unitType, int id, bool toDelete, string userId) { if (_dataAccessService.CheckWritePermissions(userId, unitType)) { throw new UnauthorizedAccessException(); } var item = _commonSvc.GetStatisticalUnitByIdAndType(id, unitType, true).Result; bool isEmployee = _userService.IsInRoleAsync(userId, DefaultRoleNames.Employee).Result; var mappedItem = Mapper.Map <IStatisticalUnit, ElasticStatUnit>(item); if (isEmployee) { var helper = new StatUnitCheckPermissionsHelper(_dbContext); helper.CheckRegionOrActivityContains(userId, mappedItem.RegionIds, mappedItem.ActivityCategoryIds); } if (item.IsDeleted == toDelete) { _elasticService.EditDocument(Mapper.Map <IStatisticalUnit, ElasticStatUnit>(item)).Wait(); } else { CheckBeforeDelete(item, toDelete); var deletedUnit = _deleteUndeleteActions[unitType](id, toDelete, userId); _postDeleteActions[unitType](deletedUnit, toDelete, userId); _elasticService.EditDocument(Mapper.Map <IStatisticalUnit, ElasticStatUnit>(deletedUnit)).Wait(); } }
public bool IsNotAllowedToWrite(StatUnitTypes unitType) { var permissions = StandardDataAccessArray.Permissions.Where(x => x.PropertyName.Split('.')[0] == unitType.ToString()); return(permissions.All(x => x.CanWrite == false)); }
/// <summary> /// Validates provided statId uniqueness /// </summary> /// <param name = "unitType"> </param> /// <param name = "statId"> </param> /// <param name = "unitId"> </param> /// <returns> </returns> public async Task <bool> ValidateStatIdUniquenessAsync(int?unitId, StatUnitTypes unitType, string statId) { if (unitType == StatUnitTypes.EnterpriseGroup) { return(!await _dbContext.EnterpriseGroups .AnyAsync(x => x.StatId == statId && x.RegId != unitId)); } return(!await _dbContext.StatisticalUnits .AnyAsync(x => x.StatId == statId && x.RegId != unitId && x.UnitType == unitType)); }
/// <summary> /// Method for obtaining the history of stat. units /// </summary> /// <param name = "type"> Type of stat. Edinet </param> /// <param name = "id"> Id stat. Edinet </param> /// <returns> </returns> public async Task <object> ShowHistoryAsync(StatUnitTypes type, int id) { var history = type == StatUnitTypes.EnterpriseGroup ? await FetchUnitHistoryAsync <EnterpriseGroup, EnterpriseGroupHistory>(id) : await FetchUnitHistoryAsync <StatisticalUnit, StatisticalUnitHistory>(id); var result = history.ToArray(); return(SearchVm.Create(result, result.Length)); }
/// <summary> /// Method for obtaining a detailed history of stat. units /// </summary> /// <param name = "type"> Type of stat. units </param> /// <param name = "id"> Id stat. units </param> /// <param name = "userId"> User Id </param> /// <param name = "isHistory"> Is the stat. historical unit </param> /// <returns> </returns> public async Task <object> ShowHistoryDetailsAsync(StatUnitTypes type, int id, string userId, bool isHistory) { var history = type == StatUnitTypes.EnterpriseGroup ? await FetchDetailedUnitHistoryAsync <EnterpriseGroup, EnterpriseGroupHistory>(id, userId, isHistory) : await FetchDetailedUnitHistoryAsync <StatisticalUnit, StatisticalUnitHistory>(id, userId, isHistory); var result = history.ToArray(); return(SearchVm.Create(result, result.Length)); }
public IActionResult Delete(StatUnitTypes type, int id) { try { _deleteService.DeleteUndelete(type, id, true, User.GetUserId()); return(NoContent()); } catch (UnauthorizedAccessException) { return(Forbid()); } }
public static object Create <T>(T statUnit, StatUnitTypes type, ISet <string> propNames, bool?isReadonly = null) where T : class { var unitType = StatisticalUnitsTypeHelper.GetStatUnitMappingType(type); if (unitType != typeof(T)) { var currentType = statUnit.GetType(); propNames = new HashSet <string>( currentType.GetProperties() .Where(v => propNames.Contains(DataAccessAttributesHelper.GetName(unitType, v.Name))) .Select(v => DataAccessAttributesHelper.GetName(currentType, v.Name)) .ToList() ); } return(DataAccessResolver.Execute(statUnit, propNames, jo => { jo.Add("type", (int)type); jo.Add("readonly", isReadonly); })); }
private List <StatUnitTypes> GetUnitTypes(string statId, StatUnitTypes statUnitType) { var statUnitTypes = new List <StatUnitTypes>(); var isContainDataSource = _dbContext.StatisticalUnits.AsNoTracking().First(x => x.StatId == statId && x.UnitType == statUnitType).DataSource != null; if (!isContainDataSource) { statUnitTypes.Add(statUnitType); } else { statUnitTypes.AddRange(_dbContext.StatisticalUnits.AsNoTracking().Where(x => x.StatId == statId && x.DataSource != null).Select(x => x.UnitType).ToList()); } return(statUnitTypes); }
private LogItemDetailsVm( int id, int unitId, StatUnitTypes unitType, DateTime issuedAt, DateTime?resolvedAt, string errors, string summary, IEnumerable <PropertyMetadataBase> properties, IEnumerable <Permission> permisisons) { Id = id; UnitId = unitId; UnitType = unitType; IssuedAt = issuedAt; ResolvedAt = resolvedAt; Errors = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(errors); Summary = summary.Split(';'); Properties = properties; Permissions = permisisons; }
/// <summary> /// Method for getting stat. units by Id and type /// </summary> /// <param name="id">Stat Id</param> /// <param name="type">Typeparam> /// <param name="showDeleted">Remoteness flag</param> /// <returns></returns> public async Task <IStatisticalUnit> GetStatisticalUnitByIdAndType(int id, StatUnitTypes type, bool showDeleted) { switch (type) { case StatUnitTypes.LocalUnit: return(await GetUnitById <StatisticalUnit>(id, showDeleted, query => query.IncludeAdvancedFields())); case StatUnitTypes.LegalUnit: return(await GetUnitById <LegalUnit>(id, showDeleted, query => query.IncludeAdvancedFields().Include(x => x.LocalUnits))); case StatUnitTypes.EnterpriseUnit: return(await GetUnitById <EnterpriseUnit>(id, showDeleted, query => query.IncludeAdvancedFields().Include(x => x.LegalUnits))); case StatUnitTypes.EnterpriseGroup: return(await GetUnitById <EnterpriseGroup>(id, showDeleted, query => query.IncludeCommonFields().Include(x => x.EnterpriseUnits))); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
private QueueLogDetailsVm( DataUploadingLog item, StatUnitTypes statUnitType, IEnumerable <PropertyMetadataBase> properties, IEnumerable <Permission> permissions) { Id = item.Id; Started = item.StartImportDate; Ended = item.EndImportDate; StatId = item.TargetStatId; Name = item.StatUnitName; Unit = item.SerializedUnit ?? "{}"; RawUnit = item.SerializedRawUnit ?? "{}"; Status = item.Status; Note = item.Note; Errors = item.ErrorMessages; Summary = item.SummaryMessages; StatUnitType = statUnitType; Properties = properties; Permissions = permissions; }
public async Task <IActionResult> HistoryDetails(StatUnitTypes type, int id, bool isHistory) => Ok(await _historyService.ShowHistoryDetailsAsync(type, id, User.GetUserId(), isHistory));
private async Task GetStatUnitFromRawEntityTest(Type type, StatUnitTypes unitType) { var raw = new Dictionary <string, object> { ["source"] = "name42", ["sourceId"] = "qwe" }; var mapping = new[]
/// <summary> /// Method to get view model /// </summary> /// <param name = "id"> Id stat. units </param> /// <param name = "type"> Type of stat. units </param> /// <param name = "userId"> User Id </param> /// <param name = "ignoredActions"> </param> /// <returns> </returns> public async Task <StatUnitViewModel> GetViewModel(int?id, StatUnitTypes type, string userId, ActionsEnum ignoredActions) { bool isEmployee = await _userService.IsInRoleAsync(userId, DefaultRoleNames.Employee); var item = id.HasValue ? await _commonSvc.GetStatisticalUnitByIdAndType(id.Value, type, false) : GetDefaultDomainForType(type); if (item == null) { throw new BadRequestException(nameof(Resource.NotFoundMessage)); } if ((ignoredActions == ActionsEnum.Edit) && isEmployee) { var helper = new StatUnitCheckPermissionsHelper(_context); var mappedItem = new ElasticStatUnit(); Mapper.Map(item, mappedItem); helper.CheckRegionOrActivityContains(userId, mappedItem.RegionIds, mappedItem.ActivityCategoryIds); } var dataAccess = await _userService.GetDataAccessAttributes(userId, item.UnitType); var config = type == StatUnitTypes.EnterpriseGroup ? _mandatoryFields.EnterpriseGroup : (object)_mandatoryFields.StatUnit; var mandatoryDict = config.GetType().GetProperties().ToDictionary(x => x.Name, GetValueFrom(config)); if (type != StatUnitTypes.EnterpriseGroup) { object subConfig; switch (type) { case StatUnitTypes.LocalUnit: subConfig = _mandatoryFields.LocalUnit; break; case StatUnitTypes.LegalUnit: subConfig = _mandatoryFields.LegalUnit; break; case StatUnitTypes.EnterpriseUnit: subConfig = _mandatoryFields.Enterprise; break; default: throw new Exception("bad statunit type"); } var getValue = GetValueFrom(subConfig); subConfig.GetType().GetProperties().ForEach(x => mandatoryDict[x.Name] = getValue(x)); } //The LegalUnits field of the EnterpriseUnit type is required by business logic if (type == StatUnitTypes.EnterpriseUnit && mandatoryDict.ContainsKey("LegalUnits")) { mandatoryDict["LegalUnits"] = true; } return(StatUnitViewModelCreator.Create(item, dataAccess, mandatoryDict, ignoredActions)); Func <PropertyInfo, bool> GetValueFrom(object source) => prop => { var value = prop.GetValue(source); return(value is bool b && b); }; }
public async Task <IActionResult> GetUnitById(StatUnitTypes type, string id) { int.TryParse(id, out int result); return(Ok(await _viewService.GetViewModel(result, type, User.GetUserId(), ActionsEnum.Edit))); }
/// <summary> /// The method of obtaining the domain for the default type /// </summary> /// <param name = "type"> Type of stat. units </param> /// <returns> </returns> private static IStatisticalUnit GetDefaultDomainForType(StatUnitTypes type) => (IStatisticalUnit)Activator.CreateInstance(StatisticalUnitsTypeHelper.GetStatUnitMappingType(type));
/// <summary> /// Method for getting type by enumeration /// </summary> /// <param name="type">Type of stat. units</param> /// <returns></returns> public static Type GetStatUnitMappingType(StatUnitTypes type) => EnumToType[type];
public async Task <IActionResult> GetEntityById(StatUnitTypes type, string id) { int.TryParse(id, out int result); return(Ok(await _viewService.GetUnitByIdAndType(result, type, User.GetUserId(), true))); }
public async Task <IActionResult> ValidateStatId(int?unitId, StatUnitTypes unitType, string value) => Ok(await _searchService.ValidateStatIdUniquenessAsync(unitId, unitType, value));
/// <summary> ///Method for creating a view model for a detailed log queue /// </summary> /// <param name="item">item/param> /// <param name="statUnitType">stat unit type</param> /// <param name="properties">propertiesа</param> /// <param name="permissions">permissions</param> /// <returns></returns> public static QueueLogDetailsVm Create( DataUploadingLog item, StatUnitTypes statUnitType, IEnumerable <PropertyMetadataBase> properties, IEnumerable <Permission> permissions) => new QueueLogDetailsVm(item, statUnitType, properties, permissions);
public async Task <IActionResult> SearchByStatId(StatUnitTypes type, string code, int regId, bool isDeleted = false) => Ok(await _searchService.Search(type, code, User.GetUserId(), regId, isDeleted));
public async Task <StatisticalUnit> GetStatUnitFromRawEntity( IReadOnlyDictionary <string, object> raw, StatUnitTypes unitType, IEnumerable <(string source, string target)> propMapping,
/// <summary> /// Stat search method. units by code /// </summary> /// <param name = "type"> Type of static unit </param> /// <param name = "code"> Code </param> /// <param name = "isDeleted"> Delete flag </param> /// <param name = "limit"> Display limitation </param> /// <param name = "userId"> User Id </param> /// <param name = "regId"> Registration Id </param> /// <param name = "page"> Current page </param> /// <returns> </returns> public async Task <List <UnitLookupVm> > Search(StatUnitTypes type, string code, string userId, int regId, bool isDeleted, int limit = 5, int page = 1) { if (isDeleted) { var list = new List <UnitLookupVm>(); var root = new UnitSubmitM() { Id = regId, Type = type }; switch (type) { case StatUnitTypes.EnterpriseGroup: list.AddRange(Common.ToUnitLookupVm( await _commonSvc.GetUnitsList <EnterpriseUnit>(false) .Where(v => v.EntGroupId == regId) .Select(Common.UnitMapping) .ToListAsync() )); break; case StatUnitTypes.EnterpriseUnit: list.AddRange(Common.ToUnitLookupVm( await _commonSvc.GetUnitsList <EnterpriseUnit>(false) .Where(v => v.RegId == regId) .Include(v => v.EnterpriseGroup) .Select(v => v.EnterpriseGroup) .Select(Common.UnitMapping) .ToListAsync() )); list.AddRange(Common.ToUnitLookupVm( await _commonSvc.GetUnitsList <LegalUnit>(false) .Where(v => v.EnterpriseUnitRegId == regId) .Select(Common.UnitMapping) .ToListAsync() )); break; case StatUnitTypes.LegalUnit: list.AddRange(Common.ToUnitLookupVm( await _commonSvc.GetUnitsList <LegalUnit>(false) .Where(v => v.RegId == regId) .Include(v => v.EnterpriseUnit) .Select(v => v.EnterpriseUnit) .Select(Common.UnitMapping) .ToListAsync() )); list.AddRange(Common.ToUnitLookupVm( await _commonSvc.GetUnitsList <LocalUnit>(false) .Where(v => v.LegalUnitId == regId) .Select(Common.UnitMapping) .ToListAsync() )); break; case StatUnitTypes.LocalUnit: var linkedList = await _service.LinksList(root); if (linkedList.Count > 0) { list.Add(new UnitLookupVm { Id = linkedList[0].Source1.Id, Type = linkedList[0].Source1.Type, Code = linkedList[0].Source1.Code, Name = linkedList[0].Source1.Name }); } break; } return(list); } var statUnitTypes = new List <StatUnitTypes>(); switch (type) { case StatUnitTypes.LocalUnit: statUnitTypes.Add(StatUnitTypes.LegalUnit); break; case StatUnitTypes.LegalUnit: statUnitTypes.Add(StatUnitTypes.LocalUnit); statUnitTypes.Add(StatUnitTypes.EnterpriseUnit); break; case StatUnitTypes.EnterpriseUnit: statUnitTypes.Add(StatUnitTypes.LegalUnit); statUnitTypes.Add(StatUnitTypes.EnterpriseGroup); break; case StatUnitTypes.EnterpriseGroup: statUnitTypes.Add(StatUnitTypes.EnterpriseUnit); break; } var filter = new SearchQueryM { Type = statUnitTypes, StatId = code, Page = page, PageSize = limit }; var searchResponse = await _elasticService.Search(filter, userId, isDeleted); return(searchResponse.Result.Select(u => new UnitLookupVm { Id = u.RegId, Code = u.StatId, Name = u.Name, Type = u.UnitType }).ToList()); }
public IActionResult Restore(StatUnitTypes type, int regId) { _deleteService.DeleteUndelete(type, regId, false, User.GetUserId()); return(NoContent()); }
public async Task <IActionResult> GetNewEntity(StatUnitTypes type) => Ok(await _viewService.GetViewModel(null, type, User.GetUserId(), ActionsEnum.Create));
/// <summary> /// Updates unit to the state before data source upload, reject data source queue/log case /// </summary> /// <param name="unit">Unit</param> /// <param name="historyUnit">History unit</param> /// <param name="userId">Id of user that rejectes data source queue</param> /// <param name="type">Type of statistical unit</param> public async Task UpdateUnitTask(dynamic unit, dynamic historyUnit, string userId, StatUnitTypes type) { var unitForUpdate = type == StatUnitTypes.LegalUnit ? Mapper.Map <LegalUnit>(unit) : (type == StatUnitTypes.LocalUnit ? Mapper.Map <LocalUnit>(unit) : Mapper.Map <EnterpriseUnit>(unit)); Mapper.Map(historyUnit, unitForUpdate); unitForUpdate.EndPeriod = unit.EndPeriod; unitForUpdate.EditComment = "This unit was edited by data source upload service and then data upload changes rejected"; unitForUpdate.RegId = unit.RegId; unitForUpdate.UserId = userId; switch (type) { case StatUnitTypes.LegalUnit: _dbContext.LegalUnits.Update(unitForUpdate); break; case StatUnitTypes.LocalUnit: _dbContext.LocalUnits.Update(unitForUpdate); break; case StatUnitTypes.EnterpriseUnit: _dbContext.EnterpriseUnits.Update(unitForUpdate); break; } await _dbContext.SaveChangesAsync(); await _elasticService.EditDocument(Mapper.Map <IStatisticalUnit, ElasticStatUnit>(unitForUpdate)); }