Exemple #1
0
        public Analogy CreateOrUpdate(Analogy analogy)
        {
            //analogy.Product1.VendorCode = Regex.Replace(analogy.Product1.VendorCode, "[,\\./-]", string.Empty);
            //analogy.Product2.VendorCode = Regex.Replace(analogy.Product2.VendorCode, "[,\\./-]", string.Empty);
            //analogy.Product1.Manufacturer = analogy.Product1.Manufacturer.ToLower();
            //analogy.Product2.Manufacturer = analogy.Product2.Manufacturer.ToLower();
            using (var _context = new AnalogyContext())
            {
                var productRepository = new ProductRepository();
                analogy.Product1   = productRepository.CreateOrUpdate(analogy.Product1);
                analogy.Product2   = productRepository.CreateOrUpdate(analogy.Product2);
                analogy.Product1Id = analogy.Product1.Id;
                analogy.Product2Id = analogy.Product2.Id;

                var existAnalogy = Find(analogy.Product1.Id, analogy.Product2.Id);
                if (existAnalogy != null)
                {
                    _context.Entry(analogy).State = EntityState.Modified;
                    _context.SaveChanges();
                    return(analogy);
                }

                analogy = Create(analogy);
                return(analogy);
            }
        }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            Analogy item = dgAnalogues.SelectedItem as Analogy;

            analogyRepository.Delete(item.Product1.Id, item.Product2.Id);
            analogies.RemoveAt(dgAnalogues.SelectedIndex);
        }
Exemple #3
0
 public Analogy Create(Analogy entity)
 {
     using (var _context = new AnalogyContext())
     {
         _context.Products.Attach(entity.Product1);
         _context.Products.Attach(entity.Product2);
         entity = _context.Analogues.Add(entity);
         _context.SaveChanges();
         return(entity);
     }
 }
Exemple #4
0
 void Awake()
 {
     _instance = this;
 }
Exemple #5
0
        public static void Read(string file)
        {
            Analogy analogy;
            string name;
            List <string> answers;

            try
            {
                StreamReader stream = new StreamReader (file);
                XmlTextReader reader = new XmlTextReader (stream);
                answers = new List <string> ();

                for (int i = 0; i < (int) Analogy.Type.Last; i++)
                    analogies_arrays[i].Clear ();

                analogy = new Analogy ();
                while (reader.Read ())
                {
                    name = reader.Name.ToLower ();
                    switch (name) {
                    case "analogy":
                        if (reader.NodeType == XmlNodeType.Element) {
                            analogy = new Analogy ();
                            answers.Clear ();
                        }
                        else {
                            if (reader.NodeType == XmlNodeType.EndElement &&
                                // Ignores verbal analogies disabled for a specific locale
                                ServiceLocator.Instance.GetService <ITranslations> ().GetString (analogy.question) != IgnoreAnalogy) {
                                analogy.answers = answers.ToArray ();
                                analogies_arrays [(int) analogy.type].Add (analogies_arrays [(int) analogy.type].Count, analogy);
                            }
                        }
                        break;
                    case "_question":
                        if (reader.NodeType != XmlNodeType.Element)
                            return;

                        string type;

                        type = reader.GetAttribute ("type");

                        if (String.IsNullOrEmpty (type) == false) {
                            switch (type.ToLower ()) {
                            case "multipleoptions":
                                analogy.type = Analogy.Type.MultipleOptions;
                                break;
                            case "pairofwordsoptions":
                                analogy.type = Analogy.Type.PairOfWordsOptions;
                                break;
                            case "pairofwordscompare":
                                analogy.type = Analogy.Type.PairOfWordsCompare;
                                break;
                            default:
                                analogy.type = Analogy.Type.QuestionAnswer;
                                break;
                            }
                        }

                        analogy.question = reader.ReadElementString ();
                        break;
                    case "_tip":
                        if (reader.NodeType == XmlNodeType.Element)
                            analogy.tip = reader.ReadElementString ();

                        break;
                    case "_rationale":
                        if (reader.NodeType == XmlNodeType.Element)
                            analogy.rationale = reader.ReadElementString ();

                        break;
                    case "_answer":
                        if (reader.NodeType != XmlNodeType.Element)
                            break;

                        string right;

                        right = reader.GetAttribute ("correct");

                        if (String.IsNullOrEmpty (right) == false)
                            if (right.ToLower () == "yes")
                                analogy.right = answers.Count;

                        answers.Add (reader.ReadElementString ());
                        break;
                    }
                }

                reader.Close ();
                stream.Dispose ();
            }

            catch (Exception e)
            {
                Console.WriteLine ("AnalogiesFactory. Error loading file: {0}", e.Message);
            }
        }
Exemple #6
0
 public static Dictionary<int, Analogy> Get(Analogy.Type type)
 {
     return analogies_arrays [(int) type];
 }