コード例 #1
0
        public async Task <PhoneRecord> AddRecordAsync(PhoneRecord record)
        {
            context.PhoneRecords.Add(record);
            await context.SaveChangesAsync();

            return(record);
        }
コード例 #2
0
        public async Task <PhoneRecord> UpdateRecordAsync(PhoneRecord record)
        {
            var temp = context.ChangeTracker.Entries();

            if (!context.PhoneRecords.Local.Any(r => r.PhoneRecordId == record.PhoneRecordId))
            {
                context.PhoneRecords.Attach(record);
            }

            var existingEntity = context.PhoneRecords.Local.SingleOrDefault(r => r.PhoneRecordId == record.PhoneRecordId);

            if (existingEntity != null)
            {
                context.Entry(existingEntity).CurrentValues.SetValues(record);
            }
            else
            {
                context.Entry(record).State = EntityState.Modified;
            }

            await context.SaveChangesAsync();

            return(record);
        }