Esempio n. 1
0
        // PUT api/RepeatType/5
        public HttpResponseMessage PutRepeatType(int id, RepeatType repeattype)
        {
            if (ModelState.IsValid && id == repeattype.ID)
            {
                db.Entry(repeattype).State = EntityState.Modified;

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

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Esempio n. 2
0
 // POST api/RepeatType
 public HttpResponseMessage PostRepeatType(RepeatType repeattype)
 {
     if (ModelState.IsValid)
     {
         if (!db.RepeatTypes.Any())
         {
             repeattype.ID = 0;
         }
         else
         {
             repeattype.ID = db.RepeatTypes.Max(record => record.ID) + 1;
         }
         db.RepeatTypes.Add(repeattype);
         db.SaveChanges();
         db.Configuration.ProxyCreationEnabled = false;
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, repeattype);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = repeattype.ID }));
         return response;
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }