public async Task <IHttpActionResult> putProductProvider(int id, DTOproductprovider dtoproductProvider) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dtoproductProvider.ProductProvider_ID) { return(BadRequest()); } var putProductProvider = db.productproviders.Single(e => e.ProductProvider_ID == id); db.Entry(EntityMapper.updateEntity(putProductProvider, dtoproductProvider)).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!userExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <DTOproductprovider> Postproductprovider(DTOproductprovider newDTO) { productprovider newProd = EntityMapper.updateEntity(null, newDTO); db.productproviders.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public async Task <IHttpActionResult> Putproductprovider(int ID, DTOproductprovider editedDTO) { productprovider toUpdate = db.productproviders.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> getProductProvider(int id) { DTOproductprovider toReturn = new DTOproductprovider(await db.productproviders.FindAsync(id)); if (toReturn == null) { return(NotFound()); } return(CreatedAtRoute("DefaultApi", new { id = toReturn.ProductProvider_ID }, toReturn)); }
public async Task <IHttpActionResult> postProductProvider(DTOproductprovider dtoprodprovider) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.productproviders.Add(EntityMapper.updateEntity(null, dtoprodprovider)); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = dtoprodprovider.ProductProvider_ID }, dtoprodprovider)); }
public static productprovider updateEntity(productprovider entityObjct, DTOproductprovider dto) { if (entityObjct == null) { entityObjct = new productprovider(); } entityObjct.ProductProvider_ID = dto.ProductProvider_ID; entityObjct.User_ID = dto.User_ID; entityObjct.ppCompanyName = dto.ppCompanyName; entityObjct.ppVATnumber = dto.ppVATnumber; entityObjct.ppFaxNumber = dto.ppFaxNumber; entityObjct.ppAddress = dto.ppAddress; entityObjct.lastAssignedPolicyNumber = dto.lastAssignedPolicyNumber; return(entityObjct); }