Exemple #1
0
        // POST api/Loyalty
        public HttpResponseMessage PostLoyalty(Loyalty loyalty)
        {
            if (ModelState.IsValid)
            {
                db.Loyalties.Add(loyalty);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, loyalty);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = loyalty.LoyaltyId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Exemple #2
0
        // PUT api/Loyalty/5
        public HttpResponseMessage PutLoyalty(Guid id, Loyalty loyalty)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != loyalty.LoyaltyId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(loyalty).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }