コード例 #1
0
        private static void SaveStoredData(AddrbookDbContext ctx, string contact_name, string address)
        {
            Addrbook addrBook = ctx.Addrbooks.FirstOrDefault(p => p.Address == address);

            if (addrBook == null)
            {
                ctx.Addrbooks.Add(new Addrbook
                {
                    ContactName = contact_name,
                    Address     = address
                });
            }
            else
            {
                addrBook.ContactName = contact_name;
            }
        }
コード例 #2
0
 public bool DeleteAddress(string address)
 {
     using (AddrbookDbContext ctx = new AddrbookDbContext(DbPath))
     {
         Addrbook addrbook = ctx.Addrbooks.FirstOrDefault(p => p.Address.SequenceEqual(address));
         if (address != null)
         {
             ctx.Addrbooks.Remove(addrbook);
             try
             {
                 ctx.SaveChanges();
             }
             catch (Exception ex)
             {
                 string str = ex.Message;
             }
         }
     }
     return(true);
 }