Beispiel #1
0
        private List <FacetDto> GetInitialFacets()
        {
            IQueryable <Index> allIndices = this._repository.GetAllIndices();
            var indicesByField            = IndexCollectionExtensions.AccumulateByField(allIndices);

            indicesByField = indicesByField.Take(InitialIndexDisplay_NumberOfFields).ToList();

            List <FacetDto> facets = new List <FacetDto>();

            foreach (var pair in indicesByField)
            {
                FacetDto newFacet = new FacetDto()
                {
                    Field = pair.Key,
                    Terms = pair.Value
                            .Take(InitialIndexDisplay_NumberOfTerms)
                            .Select(i => new TermDto()
                    {
                        Term = i.Term,
                    })
                            .ToList(),
                };
                facets.Add(newFacet);
            }

            return(facets);
        }
Beispiel #2
0
        public JsonResult EditorFacet(FacetDto model)
        {
            model.ContactId = HttpUtility.ParseQueryString(Request.UrlReferrer.Query)[ContactIdParam];
            var result  = Task.Run(() => _xconnectService.UpdateContactFacet(model)).Result;
            var message = result ? "Successfully saved" : "An error occured";

            return(Json(message));
        }
 public bool UpdateFieldValue(ref dynamic obj, FacetDto facet)
 {
     return(false);
 }
        public async Task <bool> UpdateContactFacet(FacetDto facet)
        {
            using (XConnectClient client = GetClient())
            {
                try
                {
                    var availableFacetDefinitions = client.Model.Facets.Where(f => f.Target == EntityType.Contact);

                    List <string> availableKeys = new List <string>();
                    foreach (var defenition in availableFacetDefinitions)
                    {
                        availableKeys.Add(defenition.Name);
                    }

                    ContactReference reference = new ContactReference(Guid.Parse(facet.ContactId));
                    var contactTask            = client.GetAsync <Contact>(
                        reference,
                        new ContactExpandOptions(availableKeys.ToArray())
                        );

                    var contact = await contactTask;

                    if (contact == null)
                    {
                        return(false);
                    }

                    var facets = contact.Facets;
                    foreach (var f in facets)
                    {
                        var facetName = f.Key;

                        if (facetName == facet.FacetName)
                        {
                            Type type = f.Value.GetType();
                            if (string.IsNullOrEmpty(facet.Container))
                            {
                                var property = type.GetProperty(facet.FieldName);
                                if (property == null)
                                {
                                    return(false);
                                }
                                property.SetValue(f.Value, Convert.ChangeType(facet.Value, property.PropertyType),
                                                  null);
                            }
                            else
                            {
                                var          paths = facet.Container.Split(new[] { "$" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                PropertyInfo property;
                                while (paths.Count > 0)
                                {
                                    var current = paths[0];
                                    paths.RemoveAt(0);
                                    property = type.GetProperty(current);
                                    if (property != null)
                                    {
                                        var value = property.GetValue(f.Value);
                                        type     = property.PropertyType;
                                        property = type.GetProperty(facet.FieldName);
                                        if (property != null)
                                        {
                                            property.SetValue(value, Convert.ChangeType(facet.Value, property.PropertyType), null);
                                        }
                                    }
                                }
                            }
                            client.SetFacet <Facet>(contact, facet.FacetName, f.Value);
                            await client.SubmitAsync();

                            return(true);
                        }
                    }
                }
                catch (XdbExecutionException ex)
                {
                }
            }

            return(false);
        }