public ActionResult Create([Bind(Include = "ProductID,Name,Description,Price,Category")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Example #2
0
 public HttpResponseMessage Delete(int id)
 {
     SportsDB.TblProducts.Remove(SportsDB.TblProducts.FirstOrDefault(x => x.Id == id));
     return(ToJson(SportsDB.SaveChanges()));
 }
Example #3
0
 public HttpResponseMessage Put(int id, [FromBody] TblProduct value)
 {
     SportsDB.Entry(value).State = EntityState.Modified;
     return(ToJson(SportsDB.SaveChanges()));
 }
Example #4
0
 public HttpResponseMessage Post([FromBody] TblProduct value)
 {
     SportsDB.TblProducts.Add(value);
     return(ToJson(SportsDB.SaveChanges()));
 }