Пример #1
0
        // POST api/DailyEntry
        public HttpResponseMessage PostDailyEntry(DailyEntry dailyEntry)
        {
            if (ModelState.IsValid)
            {
                _db.DailyEntries.Add(dailyEntry);
                _db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, dailyEntry);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = dailyEntry.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Пример #2
0
        // PUT api/DailyEntry/5
        public HttpResponseMessage PutDailyEntry(int id, DailyEntry dailyEntry)
        {
            if (ModelState.IsValid && id == dailyEntry.Id)
            {
                _db.Entry(dailyEntry).State = EntityState.Modified;

                try
                {
                    _db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK, dailyEntry);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }