コード例 #1
0
        public void EditStar()
        {
            var xml         = new XmlSerializer(typeof(StarPair));
            var requestBody = HttpContext.Request.Body;
            var st          = (StarPair)xml.Deserialize(requestBody /*new StringReader(s)*/);
            //var st = JsonConvert.DeserializeObject<Star>(s);
            var dbs = new DBStar(st.Star);

            dbs.Id = st.Id;
            using (var db = new AstronomicDirectoryDbContext())
            {
                db.Entry(dbs).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
コード例 #2
0
        public async Task StarViews(/*string s*/)
        {
            var xml         = new XmlSerializer(typeof(Star));
            var requestBody = HttpContext.Request.Body;
            var st          = (Star)xml.Deserialize(requestBody /*new StringReader(s)*/);
            //var st = JsonConvert.DeserializeObject<Star>(s);
            var dbs = new DBStar(st);

            using (var db = new AstronomicDirectoryDbContext())
            {
                //if (db.Stars.FirstOrDefault(s => s.Name == st.Name) == null)
                await db.Stars.AddAsync(dbs);

                await db.Planets.AddRangeAsync(dbs.Planets);

                await db.Moons.AddRangeAsync(dbs.Planets.SelectMany(pl => pl.Moons));

                //foreach (var pl in dbs.Planets)
                //    if(pl.Moons != null)
                await db.SaveChangesAsync();
            }
        }