public async Task <IHttpActionResult> putUser(int id, DTOusertype dtousertype) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dtousertype.UserType_ID) { return(BadRequest()); } var putUsertype = db.usertypes.Single(e => e.UserType_ID == id); db.Entry(EntityMapper.updateEntity(putUsertype, dtousertype)).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!userExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <DTOusertype> Postusertype(DTOusertype newDTO) { usertype newProd = EntityMapper.updateEntity(null, newDTO); db.usertypes.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public async Task <IHttpActionResult> Putusertype(int ID, DTOusertype editedDTO) { usertype toUpdate = db.usertypes.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> getUserType(int id) { DTOusertype toReturn = new DTOusertype(await db.usertypes.FindAsync(id)); if (toReturn == null) { return(NotFound()); } return(CreatedAtRoute("DefaultApi", new { id = toReturn.UserType_ID }, toReturn)); }
public async Task <IHttpActionResult> postUserType(DTOusertype dtoUsertype) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.usertypes.Add(EntityMapper.updateEntity(null, dtoUsertype)); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = dtoUsertype.UserType_ID }, dtoUsertype)); }
public static usertype updateEntity(usertype entityObjct, DTOusertype dto) { if (entityObjct == null) { entityObjct = new usertype(); } entityObjct.UserType_ID = dto.UserType_ID; entityObjct.UserTypeDescription = dto.UserTypeDescription; return(entityObjct); }
public async Task <IHttpActionResult> deleteUserType(int id) { var userTypeToDel = db.usertypes.SingleOrDefault(x => x.UserType_ID == id); if (userTypeToDel == null) { return(NotFound()); } DTOusertype temp = new DTOusertype(userTypeToDel); db.usertypes.Remove(userTypeToDel); await db.SaveChangesAsync(); return(Ok(temp)); }