예제 #1
0
        public HttpResponseMessage PutPriceTag(int id, PriceTag priceTag)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpRequestException("Model not valid"));
            }

            if (id != priceTag.ID)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpRequestException("Model not valid"));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PriceTagExists(id))
                {
                    return Request.CreateErrorResponse(HttpStatusCode.NotFound, new HttpRequestException("Price not found"));
                }
                else
                {
                    throw;
                }
            }

            return Request.CreateResponse<PriceTag>(HttpStatusCode.OK, priceTag);
        }
예제 #2
0
        public HttpResponseMessage PostPriceTag(PriceTag priceTag)
        {
            priceTag.Likes = 0;
            priceTag.Dislikes = 0;
            priceTag.Created = DateTime.Now;
            priceTag.Updated = DateTime.Now;
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpRequestException("Model not valid"));
            }

            db.PriceTags.Add(priceTag);
            db.SaveChanges();

            return Request.CreateResponse<PriceTag>(HttpStatusCode.Created, priceTag);
        }