public OffnetAttributeInfoWeb(string name, string value, AttributeInfoWeb attributeInfo)
 {
     Attribute = new Dictionary <string, string> {
         { name, value }
     };
     AttributeProperties = attributeInfo;
 }
Beispiel #2
0
        public ObjectResult Attributes(ServiceAttributesKeyWeb postData)
        {
            return(WebFunction.Execute <ServiceAttributesKeyWeb, AttributeInfoWeb[]>(this, postData, (sa) =>
            {
                AttributeInfoWeb[] list;

                if (sa == null)
                {
                    list = new AttributeInfoWeb[1];
                    list[0] = new AttributeInfoWeb {
                        ErrorString = "Key cannot be null", IsValid = false
                    };

                    return new WebResult <AttributeInfoWeb[]>(list);
                }
                var sKey = new ServiceKey(sa);
                try
                {
                    var atts = ServiceAttributes.Get(sKey, sa.PopulateLists);
                    list = new AttributeInfoWeb[atts.Count];
                    var i = 0;
                    foreach (var att in atts)
                    {
                        list[i++] = new AttributeInfoWeb(att);
                    }
                }
                catch (Exception e)
                {
                    list = new AttributeInfoWeb[1];
                    list[0] = new AttributeInfoWeb {
                        ErrorString = e.Message, IsValid = false
                    };
                }

                return new WebResult <AttributeInfoWeb[]>(list);
            }));
        }
        public static OffnetAttributeSourcesInfoWeb GetAttributes(OffnetServiceKey key, bool populateLists)
        {
            AttributeInfoWeb list;

            OffnetAttributeInfoWeb[]  info;
            OffnetAttributeSourceInfo source;

            OffnetAttributeSourceInfo[]   sources;
            OffnetAttributeSourcesInfoWeb infoWeb;

            if (key == null)
            {
                infoWeb = new OffnetAttributeSourcesInfoWeb {
                    ErrorString = "Key cannot be null"
                };
                return(infoWeb);
            }
            try
            {
                var    atts           = Get(key, populateLists);
                var    srcs           = OffnetDataAccess.GetOffnetAttributeSource(key);
                string name           = null;
                string value          = null;
                string partnerOrderId = null;
                info = new OffnetAttributeInfoWeb[atts.Count];
                var i = 0;
                foreach (var att in atts)
                {
                    name      = att.Name;
                    value     = att.GetValue();
                    list      = new AttributeInfoWeb(att);
                    info[i++] = new OffnetAttributeInfoWeb(name, value, list);
                    if (name == "PartnerOrderId")
                    {
                        partnerOrderId = value;
                    }
                }

                //var attributes= srcs.Where(x => x.PartnerOrderId.ToString() == partnerOrderId && x.OffnetServiceId == key.Id).Select(x => x.AttributeName).ToList();
                List <string> filteredSrcs = new List <string>();
                filteredSrcs = srcs.Where(x => x.PartnerOrderId.ToString() == partnerOrderId && x.OffnetServiceId == key.Id).Select(x => x.AttributeSource).Distinct().ToList();
                sources      = new OffnetAttributeSourceInfo[filteredSrcs.Count];
                var j = 0;

                foreach (var s in filteredSrcs)
                {
                    var attributes = new List <string>(srcs.Where(x => x.PartnerOrderId.ToString() == partnerOrderId && x.OffnetServiceId == key.Id && x.AttributeSource == s)
                                                       .Select(x => x.AttributeName).ToList());
                    Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();
                    foreach (var a in attributes)
                    {
                        var attrList = info.ToList();
                        var v        = attrList.Where(x => x.AttributeProperties.Name.Equals(a)).Select(x => x.AttributeProperties.Value).FirstOrDefault();
                        keyValuePairs.Add(a, v);
                    }
                    source = new OffnetAttributeSourceInfo
                    {
                        Source          = s,
                        OffnetServiceId = key.Id,
                        PartnerOrderId  = partnerOrderId,
                        Attributes      = keyValuePairs
                    };
                    sources[j++] = source;
                }
                infoWeb = new OffnetAttributeSourcesInfoWeb(sources, info);
            }
            catch (Exception e)
            {
                infoWeb = new OffnetAttributeSourcesInfoWeb {
                    ErrorString = e.Message
                };
            }

            return(infoWeb);
        }