コード例 #1
0
        public async void Delete(int id)
        {
            using (DataContext context = new DataContext())
            {
                TelephoneEntry entity = await context.TelephoneEntries.FirstOrDefaultAsync(t => t.Id == id);
                if (entity != null)
                {
                    context.Entry(entity).State = EntityState.Deleted;
                }

                await context.SaveChangesAsync();
            }
        }
コード例 #2
0
        public async Task<int> Post([FromBody]TelephoneEntry telephoneEntry)
        {
            using (DataContext context = new DataContext())
            {
                if (telephoneEntry.Id == 0)
                {
                    context.Entry(telephoneEntry).State = EntityState.Added;
                }
                else
                {
                    context.Entry(telephoneEntry).State = EntityState.Modified;
                }

                await context.SaveChangesAsync();
                return telephoneEntry.Id;
            }
        }