public async Task <ActionResult> SavePropertyLocalFacetValue(SaveLocalFacetRequest request) { if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata))) { return(Unauthorized()); } var validationMessage = await MetadataValidationLogic.SavePropertyLocalFacetValueValidation(request, _dbContext); if (!string.IsNullOrEmpty(validationMessage)) { return(StatusCode(400, validationMessage)); } var existing = await _dbContext.PropertyFacetValues .Where(x => x.Property.OwnerEntityType.Name == request.EntityTypeName && x.Property.Name == request.PropertyName && x.FacetDefinition.Name == request.FacetName) .SingleOrDefaultAsync(); if (request.ClearLocalValue) { if (existing != null) { _dbContext.PropertyFacetValues.Remove(existing); } } else { if (existing == null) { existing = new PropertyFacetValue { FacetDefinition = await _dbContext.PropertyFacetDefinitions.SingleAsync(x => x.Name == request.FacetName), Property = await _dbContext.Properties.SingleAsync(x => x.OwnerEntityType.Name == request.EntityTypeName && x.Name == request.PropertyName) }; _dbContext.PropertyFacetValues.Add(existing); } existing.Value = request.Value; } await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult> SaveTypeLocalFacetValue(SaveLocalFacetRequest request) { if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata))) { return(Unauthorized()); } var existing = await _dbContext.EntityFacetValues .Where(x => x.Entity.Name == request.EntityName && x.FacetDefinition.Name == request.FacetName) .SingleOrDefaultAsync(); if (request.ClearLocalValue) { if (existing != null) { _dbContext.EntityFacetValues.Remove(existing); } } else { if (existing == null) { existing = new EntityFacetValue { FacetDefinition = await _dbContext.EntityFacetDefinitions.SingleAsync(x => x.Name == request.FacetName), Entity = await _dbContext.Entities.SingleAsync(x => x.Name == request.EntityName) }; _dbContext.EntityFacetValues.Add(existing); } existing.Value = request.Value; } await _dbContext.SaveChangesAsync(); return(Ok()); }
public static async Task <string> SavePropertyLocalFacetValueValidation(SaveLocalFacetRequest model, MetadataDbContext dbContext) { return(await Task.FromResult(string.Empty)); }