예제 #1
0
        public async Task <IHttpActionResult> UpdateChipTypes(int id, [FromBody] SidChipType entity)
        {
            SidChipType existingEntity = await context.SidChipTypes.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.SidChipTypes.Attach(entity);
            context.Entry(entity).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(Ok <SidChipType>(entity));
        }
예제 #2
0
        public async Task <IHttpActionResult> CreateChipType(SidChipType entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.SidChipTypes.Add(entity);
            await context.SaveChangesAsync();

            return(Ok <SidChipType>(entity));
        }