public async Task <IHttpActionResult> UpdateCardTypes(int id, [FromBody] SidCardType entity) { SidCardType existingEntity = await context.SidCardTypes.FindAsync(entity.Id); if (entity == null) { return(NotFound()); } if (id != entity.Id) { return(BadRequest(ModelState)); } if (entity == null) { return(BadRequest(ModelState)); } if (existingEntity != null && context.Entry(existingEntity).State != EntityState.Detached) { context.Entry(existingEntity).State = EntityState.Detached; } //Overide entity if exist context.SidCardTypes.Attach(entity); context.Entry(entity).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok <SidCardType>(entity)); }
public async Task <IHttpActionResult> CreateCardType(SidCardType entity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } context.SidCardTypes.Add(entity); await context.SaveChangesAsync(); return(Ok <SidCardType>(entity)); }