public async Task <IHttpActionResult> putSystemAdmin(int id, DTOsystemadmin dtosysAdmin) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dtosysAdmin.SystemAdmin_ID) { return(BadRequest()); } var putSysadmin = db.systemadmins.Single(e => e.SystemAdmin_ID == id); db.Entry(EntityMapper.updateEntity(putSysadmin, dtosysAdmin)).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!userExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <DTOsystemadmin> Postsystemadmin(DTOsystemadmin newDTO) { systemadmin newProd = EntityMapper.updateEntity(null, newDTO); db.systemadmins.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public async Task <IHttpActionResult> Putsystemadmin(int ID, DTOsystemadmin editedDTO) { systemadmin toUpdate = db.systemadmins.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> getSystemAdmin(int id) { DTOsystemadmin toReturn = new DTOsystemadmin(await db.systemadmins.FindAsync(id)); if (toReturn == null) { return(NotFound()); } return(CreatedAtRoute("DefaultApi", new { id = toReturn.SystemAdmin_ID }, toReturn)); }
public async Task <IHttpActionResult> postSystemAdmin(DTOsystemadmin dtoSysadmin) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.systemadmins.Add(EntityMapper.updateEntity(null, dtoSysadmin)); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = dtoSysadmin.SystemAdmin_ID }, dtoSysadmin)); }
public static systemadmin updateEntity(systemadmin entityObjct, DTOsystemadmin dto) { if (entityObjct == null) { entityObjct = new systemadmin(); } entityObjct.SystemAdmin_ID = dto.SystemAdmin_ID; entityObjct.User_ID = dto.User_ID; entityObjct.systemAdminOTP = dto.systemAdminOTP; entityObjct.systemAdminHasTwoPartAuth = dto.systemAdminHasTwoPartAuth; return(entityObjct); }