ABsoluteMaybe.Persistence.Xml.XmlExperimentCommands.Convert C# (CSharp) Метод

Convert() публичный Метод

public Convert ( string conversionKeyword, string userId ) : void
conversionKeyword string
userId string
Результат void
        public void Convert(string conversionKeyword,
		                    string userId)
        {
            var xml = Load();

            var utcNow = UtcNow;
            var experiments = xml.Root.Elements("Experiment")
                .Where(x =>
                       x.Attribute("Name").Value == conversionKeyword ||
                       (x.Attribute("ConversionKeyword") != null && x.Attribute("ConversionKeyword").Value == conversionKeyword));
            foreach (var participant in experiments
                .Select(experiment => experiment.Element("Participants"))
                .Select(participants => participants.Elements("Participant").Single(x => x.Attribute("Id").Value == userId))
                .Where(participant => participant.Attribute("HasConverted") == null))
            {
                participant.Add(new XAttribute("HasConverted", true));
                participant.Add(new XAttribute("DateConverted", utcNow));
            }
            Save(xml);
        }