public async Task <IHttpActionResult> Putproduct(int id, DTOproduct productDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productDTO.Product_ID) { return(BadRequest()); } var putProd = db.products.Single(e => e.Product_ID == id); db.Entry(EntityMapper.updateEntity(putProd, productDTO)).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!productExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <DTOproduct> Postproduct(DTOproduct newDTO) { product newProd = EntityMapper.updateEntity(null, newDTO); db.products.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public IHttpActionResult Getproduct(int id) { DTOproduct toReturn = new DTOproduct(db.products.Find(id)); if (toReturn == null) { return(NotFound()); } return(CreatedAtRoute("DefaultApi", new { id = toReturn.Product_ID }, toReturn));; }
public async Task <IHttpActionResult> Putproduct(int ID, DTOproduct editedDTO) { product toUpdate = db.products.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Postproduct(DTOproduct productT) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } product p = EntityMapper.updateEntity(null, productT); db.products.Add(p); db.SaveChanges(); productT.Product_ID = p.Product_ID; return(CreatedAtRoute("DefaultApi", new { id = productT.Product_ID }, productT)); }
public static product updateEntity(product entityObjct, DTOproduct dto) { if (entityObjct == null) { entityObjct = new product(); } entityObjct.Product_ID = dto.Product_ID; entityObjct.ProductProvider_ID = dto.ProductProvider_ID; entityObjct.ProductType_ID = dto.ProductType_ID; entityObjct.productName = dto.productName; entityObjct.productDescription = dto.productDescription; entityObjct.detailedDescription = dto.detailedDescription; entityObjct.productPolicyDocPath = dto.productPolicyDocPath; entityObjct.isAvailableForPurchase = dto.isAvailableForPurchase; entityObjct.salesTargetAmount = dto.salesTargetAmount; entityObjct.ratingAverage = dto.ratingAverage; entityObjct.numTimesRated = dto.numTimesRated; return(entityObjct); }