public void RemoveAccount(DalAccount account)
 {
     using (AccountContext db = new AccountContext())
     {
         db.Accounts.Remove(account);
         db.SaveChanges();
     }
 }
 public void AddAccount(DalAccount account)
 {
     using (AccountContext db = new AccountContext())
     {
         db.Accounts.Add(account);
         db.SaveChanges();
     }
 }
        public void UpdateAccount(DalAccount account)
        {
            using (AccountContext db = new AccountContext())
            {
                DalAccount dbAccount = db.Accounts.Find(account.Id);

                foreach (var prop in account.GetType().GetProperties())
                {
                    prop.SetValue(dbAccount, (prop.GetValue(account)));
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
        /// <inheritdoc/>
        public void DeleteRecord(Guid id)
        {
            using (var db = new AccountContext())
            {
                var record = db.AccountSet.Find(id);

                if (record is null)
                {
                    throw new ArgumentException($"No such ID: '{id}'.");
                }

                db.AccountSet.Remove(record);
                db.SaveChanges();
            }
        }
        public bool RemoveById(int id)
        {
            try
            {
                using (var accountContext = new AccountContext())
                {
                    var entityAccount = accountContext.Accounts.First(a => a.Id == id);
                    accountContext.Accounts.Remove(entityAccount);
                    accountContext.SaveChanges();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        public bool Update(Account account)
        {
            try
            {
                using (var accountContext = new AccountContext())
                {
                    var entityAccount = accountContext.Accounts.First(a => a.Id == account.Id);
                    entityAccount.Balance = account.GetBalance();
                    entityAccount.Bonuses = account.GetBonuses();
                    accountContext.SaveChanges();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        public Account GetAccountById(int id)
        {
            EntityAccount ea;

            try
            {
                using (var accountContext = new AccountContext())
                {
                    ea = accountContext.Accounts.First(a => a.Id == id);
                    accountContext.Accounts.Remove(ea);
                    accountContext.SaveChanges();
                }
            }
            catch
            {
                return(null);
            }

            return(new Account(ea.Id, ea.CardType, ea.Owner, ea.Balance, ea.Bonuses));
        }
Exemplo n.º 8
0
        /// <inheritdoc/>
        public void AddRecord(IAccountDto dto)
        {
            if (dto is null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            var record = new AccountRecord()
            {
                Id      = dto.Id,
                Type    = dto.Type,
                Owner   = dto.Owner,
                Balance = dto.Balance,
                Bonus   = dto.Bonus,
            };

            using (var db = new AccountContext())
            {
                db.AccountSet.Add(record);
                db.SaveChanges();
            }
        }
Exemplo n.º 9
0
        /// <inheritdoc/>
        public void UpdateRecord(IAccountDto dto)
        {
            if (dto is null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            using (var db = new AccountContext())
            {
                var record = db.AccountSet.Find(dto.Id);

                if (record is null)
                {
                    throw new ArgumentException($"No such ID: '{dto.Id}'.");
                }

                record.Type    = dto.Type;
                record.Owner   = dto.Owner;
                record.Balance = dto.Balance;
                record.Bonus   = dto.Bonus;

                db.SaveChanges();
            }
        }
        public int OpenAccount(AccountType accountType, Person owner)
        {
            int id;

            try
            {
                using (var accountContext = new AccountContext())
                {
                    id = accountContext.Accounts.Count();
                    accountContext.Accounts
                    .Add(new EntityAccount
                    {
                        Id = id, CardType = accountType, Balance = 0, Bonuses = 0, Owner = owner
                    });
                    accountContext.SaveChanges();
                }
            }
            catch
            {
                return(-1);
            }

            return(id);
        }
 /// <summary>
 /// Appends given account to repository
 /// </summary>
 /// <param name="account">Account to append</param>
 public void AppendAccountToFile(Account account)
 {
     context.Add(account);
     context.SaveChanges();
 }