コード例 #1
0
ファイル: ReadingController.cs プロジェクト: dlenno/Buildnrg
        public HttpResponseMessage PostReading(Reading rd)
        {
            if (ModelState.IsValid)
            {
                repo.InsertReading(rd);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, rd);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = rd.ReadingId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
ファイル: Repository.cs プロジェクト: dlenno/Buildnrg
        public void InsertReading(Reading rd)
        {
            //Building b = new Building { BuildingId = Guid.NewGuid(), Location = "here", Name = "house" };
            //db.Buildings.Add(b);
            //db.SaveChanges();

            //Pi p = new Pi { Building = b, BuildingId = b.BuildingId, Name = "P1", PiId = Guid.NewGuid() };
            //db.Pis.Add(p);
            //db.SaveChanges();

            //rd.Building = b;
            //rd.BuildingId = b.BuildingId;
            //rd.PiId = p.PiId;

            db.Readings.Add(rd);
            db.SaveChanges();
        }