public async Task <IHttpActionResult> PutMasterDetail(int id, MasterDetailVM masterDetailVM) { MasterDetail masterDetail = ConvertToDBModel(masterDetailVM); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != masterDetail.ID) { return(BadRequest()); } db.Entry(masterDetail).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MasterDetailExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private MasterDetail ConvertToDBModel(MasterDetailVM md) { return(new MasterDetail { ID = md.ID, DisplayText = md.DisplayText, DisplayOrder = md.DisplayOrder, MasterType = md.MasterType, IsDeleted = md.IsDeleted }); }
public async Task <IHttpActionResult> PostMasterDetail(MasterDetailVM masterDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.MasterDetails.Add(ConvertToDBModel(masterDetail)); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = masterDetail.ID }, masterDetail)); }