示例#1
0
        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
        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();
        }