示例#1
0
文件: Helper.cs 项目: crowar/MVCDemo
        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();
            }
        }
示例#2
0
文件: Helper.cs 项目: crowar/MVCDemo
        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();
            }
        }
示例#3
0
文件: Helper.cs 项目: crowar/MVCDemo
        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;
        }
示例#4
0
文件: Helper.cs 项目: crowar/MVCDemo
        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();
            }
        }
示例#5
0
文件: Helper.cs 项目: crowar/MVCDemo
        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;
        }
示例#6
0
文件: Helper.cs 项目: crowar/MVCDemo
        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;
            }
        }
示例#7
0
文件: Helper.cs 项目: crowar/MVCDemo
        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();
            }
        }
示例#8
0
文件: Helper.cs 项目: crowar/MVCDemo
        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;
        }