public async Task <IHttpActionResult> UpdateDictionaryCardType(int id, DictionaryCardType entity) { var existingEntity = await context.DictionaryCardTypes.FindAsync(entity.Id); if (id != entity.Id) { return(BadRequest(ModelState)); } if (existingEntity != null && context.Entry(existingEntity).State != EntityState.Detached) { context.Entry(existingEntity).State = EntityState.Detached; } var local = context.Set <DictionaryCardType>().Local.FirstOrDefault(f => f.Id == entity.Id); if (local != null) { context.Entry(local).State = EntityState.Detached; } context.DictionaryCardTypes.Attach(entity); context.Entry(entity).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok <DictionaryCardType>(entity)); }
public async Task <IHttpActionResult> CreateDictionaryCardType(DictionaryCardType entity) { string userId = User.Identity.GetUserId(); var newEntity = new DictionaryCardType() { SidCardTypeId = entity.SidCardTypeId, CardCodeName = entity.CardCodeName }; context.DictionaryCardTypes.Add(newEntity); await context.SaveChangesAsync(); return(Ok <DictionaryCardType>(newEntity)); }