예제 #1
0
        public IHttpActionResult PutFeatured(int id, FeaturedDTO modified)
        {
            if (!FeaturedExists(id))
            {
                return(NotFound());
            }

            Featured thisFeature = (from x in db.Featureds
                                    where x.Id == id
                                    select x).First();

            thisFeature.Id        = modified.Id;
            thisFeature.ProductId = modified.ProductId;

            //db.Entry(featured).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
 private FeaturedDTO ToDTO(Featured f)
 {
     return(new FeaturedDTO()
     {
         Id = f.Id,
         ProductId = f.ProductId
     });
 }
예제 #3
0
        public IHttpActionResult PostFeatured(FeaturedDTO featuredInfo)
        {
            Featured NewFeatured = ToEntity(featuredInfo);

            db.Featureds.Add(NewFeatured);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = NewFeatured.Id }, NewFeatured));
        }
예제 #4
0
        public IHttpActionResult GetFeatured(int id)
        {
            Featured featured = db.Featureds.Find(id);

            if (featured == null)
            {
                return(NotFound());
            }

            return(Ok(ToDTO(featured)));
        }
예제 #5
0
        public IHttpActionResult DeleteFeatured(int id)
        {
            Featured featured = db.Featureds.Find(id);

            if (featured == null)
            {
                return(NotFound());
            }

            db.Featureds.Remove(featured);
            db.SaveChanges();

            return(Ok(featured));
        }