Exemple #1
0
        private async Task ProcessPropertyLocalFacets(PropertyModel model, bool isEdit, Property property)
        {
            List <PropertyFacetValue> existing;
            var definitions = await _dbContext.PropertyFacetDefinitions.ToListAsync();

            if (isEdit)
            {
                existing = await _dbContext.PropertyFacetValues.Where(x => x.PropertyId == model.Id).ToListAsync();
            }
            else
            {
                existing = new List <PropertyFacetValue>();
            }
            if (model.LocalFacets != null)
            {
                foreach (var localFacet in model.LocalFacets)
                {
                    var facet = existing.FirstOrDefault(x => x.FacetDefinition.Name == localFacet.FacetName);
                    if (facet == null)
                    {
                        facet = new PropertyFacetValue
                        {
                            Property        = property,
                            FacetDefinition = definitions.Single(x => x.Name == localFacet.FacetName)
                        };
                        _dbContext.PropertyFacetValues.Add(facet);
                    }
                    if (facet.Value != localFacet.Value)
                    {
                        facet.Value = localFacet.Value;
                    }
                }
                _dbContext.PropertyFacetValues.RemoveRange(existing.Where(x => !model.LocalFacets.Any(l => l.FacetName == x.FacetDefinition.Name)));
            }
        }
Exemple #2
0
        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());
        }
 internal static PropertyFacet Create(PropertyFacetValue y)
 {
     return(CreateInternal(y.FacetDefinition.Name, y.Value, y.FacetDefinition.FacetTypeId));
 }