public async Task <IHttpActionResult> GetHiramsCraftProduct([FromUri] int id) { HiramsCraftProduct hiramscraftproduct = await db.HiramsCraftProducts.FindAsync(id); if (hiramscraftproduct == null) { return(NotFound()); } HiramsCraftProductEntity prodEntity = new HiramsCraftProductEntity(hiramscraftproduct); return(Ok(prodEntity)); }
public async Task <IHttpActionResult> PostHiramsCraftProduct([FromBody] HiramsCraftProduct hiramscraftproduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.HiramsCraftProducts.Add(hiramscraftproduct); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = hiramscraftproduct.ProductId }, hiramscraftproduct)); }
public async Task <IHttpActionResult> DeleteHiramsCraftProduct([FromUri] int id) { HiramsCraftProduct hiramscraftproduct = await db.HiramsCraftProducts.FindAsync(id); if (hiramscraftproduct == null) { return(NotFound()); } db.HiramsCraftProducts.Remove(hiramscraftproduct); await db.SaveChangesAsync(); return(Ok(hiramscraftproduct)); }
// PUT api/Products/5 public async Task <IHttpActionResult> PutHiramsCraftProduct([FromUri] int id, [FromBody] HiramsCraftProduct hiramscraftproduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hiramscraftproduct.ProductId) { return(BadRequest()); } var prod = await db.HiramsCraftProducts.FindAsync(id); prod.ProductImage = hiramscraftproduct.ProductImage; prod.ImageFileName = hiramscraftproduct.ImageFileName; prod.ImageMIMEType = hiramscraftproduct.ImageMIMEType; prod.ProductName = hiramscraftproduct.ProductName; prod.ProductCode = hiramscraftproduct.ProductCode; prod.ProductCost = hiramscraftproduct.ProductCost; prod.LastUpdate = hiramscraftproduct.LastUpdate; prod.ProductDescription = hiramscraftproduct.ProductDescription; prod.ProductCategory = hiramscraftproduct.ProductCategory; prod.ProductSubCategory = hiramscraftproduct.ProductSubCategory; prod.Units = hiramscraftproduct.Units; prod.ProductType = hiramscraftproduct.ProductType; prod.WoodType = hiramscraftproduct.WoodType; prod.WoodStainType = hiramscraftproduct.WoodStainType; prod.MetalType = hiramscraftproduct.MetalType; prod.MetalFinish = hiramscraftproduct.MetalFinish; prod.MaterialProviders.Clear(); prod.MaterialProviders = new List <MaterialProvider>(hiramscraftproduct.MaterialProviders); prod.ServiceProviders.Clear(); prod.ServiceProviders = new List <ServiceProvider>(hiramscraftproduct.ServiceProviders); //db.Entry(hiramscraftproduct).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HiramsCraftProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }