private static void AddLensToManufacturer(PhotographySystemEntities context, Manufacturer manufacturer, Lens lense)
 {
     if (manufacturer != null)
     {
         if (manufacturer.Lenses.Contains(lense))
         {
             Console.WriteLine("Existing lens: {0}", lense.Model);
         }
         else
         {
             manufacturer.Lenses.Add(lense);
             context.SaveChanges();
             Console.WriteLine("Created lens: {0}", lense.Model);
         }
     }
 }
        private static void CreateNewLensesIfNotExists(PhotographySystemEntities context, Manufacturer manufacturer, IEnumerable<XElement> xLenses)
        {
            foreach (var xLense in xLenses)
            {
                var lenseModel = xLense.Attribute("model").Value;
                var lenseType = xLense.Attribute("type").Value;
                var xLensePrice = xLense.Attribute("price");
                string lensePrice = null;
                if (xLensePrice != null)
                {
                    lensePrice = xLensePrice.Value;
                }

                var lense = context.Lenses
                    .FirstOrDefault(l => l.Model == lenseModel);

                if (lense != null)
                {
                    Console.WriteLine("Existing lens: {0}", lenseModel);
                }
                else
                {
                    lense = new Lens()
                    {
                        Model = lenseModel,
                        Type = lenseType
                    };

                    if (lensePrice != null)
                    {
                        lense.Price = decimal.Parse(lensePrice);
                    }

                    context.Lenses.Add(lense);
                }

                AddLensToManufacturer(context, manufacturer, lense);
            }
        }