public ActionResult Populate() { var repo = new MongoRepository<Customer>(); repo.Collection.Drop(); string file = Server.MapPath("~/Controllers/interface1.xml"); var writer = new System.Xml.Serialization.XmlSerializer(typeof(g)); var wfile = new System.IO.StreamReader(file); var o = (g)writer.Deserialize(wfile); string file2 = Server.MapPath("~/Controllers/interface2.xml"); var writer2 = new System.Xml.Serialization.XmlSerializer(typeof(root)); var wfile2 = new System.IO.StreamReader(file2); var o2 = (root)writer2.Deserialize(wfile2); var kommuner = o2.län.SelectMany(x => x.kommun).ToList(); foreach (var customer in o.path) { string name = ""; var kommun = kommuner.FirstOrDefault(x => x.kommunkod == customer.id); if (kommun != null) { name = kommun.kommunnamn; } var c = new Customer() { InternalId = customer.id, IsCustomer = false, Path = customer.d, Name = name }; repo.Add(c); } return Content("!"); }
[HttpPost] // ekleme gerçekleştirilirse dönderiyor. public IActionResult customerAdd(Customer c) { data.Customers.Add(c); data.SaveChanges(); return(RedirectToAction("Index")); }