public bool Create(CryptocurrencyWallet item)
        {
            try
            {
                using var context = new OlavCryptoContext();

                context.WalletList.Attach(item.Wallet);
                context.CryptocurrencyList.Attach(item.Cryptocurrency);
                context.CryptocurrencyWalletList.Add(item);

                context.SaveChanges();

                var newItem = new CryptocurrencyDetails {
                    CryptocurrencyWallet = item
                };
                context.CryptocurrencyWalletList.Attach(newItem.CryptocurrencyWallet);
                context.CryptocurrencyDetailsList.Add(newItem);

                context.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #2
0
 public bool Delete(int id)
 {
     try
     {
         using var context = new OlavCryptoContext();
         context.CryptocurrencyList.Remove(context.CryptocurrencyList.Find(id));
         context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
 public bool Update(Cryptocurrency item)
 {
     try
     {
         using var context = new OlavCryptoContext();
         context.CryptocurrencyList.Attach(item);
         context.Entry(item).State = EntityState.Modified;
         context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }