Exemplo n.º 1
0
        public static void AddAccount(AccountDTO dto)
        {
            using (var db = new WebDBEntities())
            {
                var account = new Account
                {
                    AccountCode = dto.AccountCode,
                    CustomerId = dto.CustomerId
                };

                db.Accounts.Add(account);

                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void AddCustomer(CustomerDTO dto)
        {
            using (var db = new WebDBEntities())
            {
                var customer = new Customer
                {
                    Name = dto.Name,
                    Surname = dto.Surname,
                    Phone = dto.Phone,
                    Email = dto.Email
                };

                db.Customers.Add(customer);

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public static int DeleteAccount(int id)
        {
            int customerId;

            using (var db = new WebDBEntities())
            {
                var account = db.Accounts.First(r => r.Id == id);

                customerId = account.CustomerId;

                db.Transactions.RemoveRange(db.Transactions.Where(r => r.AccountId == account.Id));
                db.Accounts.Remove(account);

                db.SaveChanges();

            }

            return customerId;
        }
Exemplo n.º 4
0
        public static int AddTransaction(TransactionDTO dto)
        {
            int customerId;

            using (var db = new WebDBEntities())
            {
                var transaction = new Transaction()
                {
                    CreateDate = dto.CreateDate,
                    CallDuration = dto.CallDuration,
                    AccountId = dto.AccountId
                };

                db.Transactions.Add(transaction);

                db.SaveChanges();

                customerId = db.Accounts.First(r => r.Id == dto.AccountId).CustomerId;
            }

            return customerId;
        }
Exemplo n.º 5
0
        public static void DeleteCustomer(int id)
        {
            using (var db = new WebDBEntities())
            {
                var accounts = db.Accounts.Where(r => r.CustomerId == id);
                foreach (var acc in accounts)
                {
                    db.Transactions.RemoveRange(db.Transactions.Where(r => r.AccountId == acc.Id));
                }

                db.Accounts.RemoveRange(db.Accounts.Where(r => r.CustomerId == id));

                db.Customers.RemoveRange(db.Customers.Where(r => r.Id == id));

                db.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public static int UpdateTransfer(TransactionDTO dto)
        {
            using (var db = new WebDBEntities())
            {
                var transaction = db.Transactions.FirstOrDefault(r => r.Id == dto.Id) ?? new Transaction { Id = dto.Id };

                transaction.AccountId = dto.AccountId;
                transaction.CallDuration = dto.CallDuration;
                transaction.CreateDate = dto.CreateDate;

                db.Transactions.AddOrUpdate(transaction);

                db.SaveChanges();

                return db.Accounts.First(r => r.Id == dto.AccountId).CustomerId;
            }
        }
Exemplo n.º 7
0
        public static void UpdateCustomer(CustomerDTO customerDto)
        {
            using (var db = new WebDBEntities())
            {
                var customer = db.Customers.FirstOrDefault(r => r.Id == customerDto.Id) ?? new Customer { Id = customerDto.Id };

                customer.Name = customerDto.Name;
                customer.Surname = customerDto.Surname;
                customer.Email = customerDto.Email;
                customer.Phone = customerDto.Phone;

                db.Customers.AddOrUpdate(customer);

                db.SaveChanges();
            }
        }
Exemplo n.º 8
0
 public static List<TransactionDTO> GetTransactions(int accountId)
 {
     using (var db = new WebDBEntities())
     {
         return db.Transactions.Where(r => r.AccountId == accountId).Select(t => new TransactionDTO
         {
             Id = t.Id,
             AccountId = t.AccountId,
             CreateDate = t.CreateDate,
             CallDuration = t.CallDuration
         }).ToList();
     }
 }
Exemplo n.º 9
0
        public static TransactionDTO GetTransaction(int id)
        {
            using (var db = new WebDBEntities())
            {
                var transaction = db.Transactions.First(r => r.Id == id);
                var dto = new TransactionDTO
                {
                    Id = transaction.Id,
                    CallDuration = transaction.CallDuration,
                    CreateDate = transaction.CreateDate,
                    AccountId = transaction.AccountId
                };

                return dto;
            }
        }
Exemplo n.º 10
0
 public static List<CustomerDTO> GetCustomers()
 {
     using (var db = new WebDBEntities())
     {
         return db.Customers.Select(customer => new CustomerDTO
         {
             Id = customer.Id,
             Name = customer.Name,
             Surname = customer.Surname,
             Phone = customer.Phone,
             Email = customer.Email
         }).ToList();
     }
 }
Exemplo n.º 11
0
        public static CustomerDTO GetCustomer(int id)
        {
            using (var db = new WebDBEntities())
            {
                var customer = db.Customers.FirstOrDefault(r => r.Id == id);

                if (customer == null) throw new ArgumentException("Неверное значение параметра", nameof(id));

                var customerDTO = new CustomerDTO
                {
                    Id = customer.Id,
                    Name = customer.Name,
                    Surname = customer.Surname,
                    Phone = customer.Phone,
                    Email = customer.Email
                };

                return customerDTO;
            }
        }
Exemplo n.º 12
0
        public static List<AccountDTO> GetAllAccounts()
        {
            var result = new List<AccountDTO>();

            using (var db = new WebDBEntities())
            {
                result.AddRange(db.Accounts.Select(a => new AccountDTO
                {
                    Id = a.Id,
                    AccountCode = a.AccountCode,
                    CustomerId = a.CustomerId,

                }).ToList());

            }

            return result;
        }
Exemplo n.º 13
0
 public static List<AccountDTO> GetAccountsWithTransaction(int customerId)
 {
     using (var db = new WebDBEntities())
     {
         return db.Accounts.Where(r => r.CustomerId == customerId).Select(a => new AccountDTO
         {
             Id = a.Id,
             AccountCode = a.AccountCode,
             CustomerId = a.CustomerId,
             Transactions = a.Transactions.Select(t => new TransactionDTO
             {
                 Id = t.Id,
                 AccountId = t.AccountId,
                 CreateDate = t.CreateDate,
                 CallDuration = t.CallDuration
             }).ToList()
         }).ToList();
     }
 }
Exemplo n.º 14
0
        public static List<AccountDTO> GetAccounts(IEnumerable<int> accountIds)
        {
            var result = new List<AccountDTO>();

            using (var db = new WebDBEntities())
            {
                foreach (var aid in accountIds)
                {
                    result.AddRange(db.Accounts.Where(r => r.Id == aid).Select(a => new AccountDTO
                    {
                        Id = a.Id,
                        AccountCode = a.AccountCode,
                        CustomerId = a.CustomerId,
                        Transactions = a.Transactions.Select(t => new TransactionDTO
                        {
                            Id = t.Id,
                            AccountId = t.AccountId,
                            CreateDate = t.CreateDate,
                            CallDuration = t.CallDuration
                        }).ToList()
                    }).ToList());
                }
            }

            return result;
        }
Exemplo n.º 15
0
 public static List<AccountDTO> GetAccounts(int customerId)
 {
     using (var db = new WebDBEntities())
     {
         return db.Accounts.Where(r => r.CustomerId == customerId).Select(a => new AccountDTO
         {
             Id = a.Id,
             AccountCode = a.AccountCode,
             CustomerId = a.CustomerId
         }).ToList();
     }
 }
Exemplo n.º 16
0
        public static object DeleteTransfer(int id)
        {
            int customerId;

            using (var db = new WebDBEntities())
            {
                var transaction = db.Transactions.First(r => r.Id == id);

                var account = db.Accounts.First(r => r.Id == transaction.AccountId);

                customerId = account.CustomerId;

                db.Transactions.Remove(transaction);

                db.SaveChanges();

            }

            return customerId;
        }