public async Task <Boolean> AddOldCustomerAsync(OldCustomer customer)
        {
            using (var context = new ShopContext())
            {
                //var y = context.Customers.ToList();

                // if customer already exists, return error
                if (context.OldCustomers.Where(c => c.OldDbId == customer.OldDbId).FirstOrDefault() != null)
                {
                    return(false);
                }

                await context.OldCustomers.AddAsync(new OldCustomer()
                {
                    FirstName   = customer.FirstName,
                    MiddleName  = customer.MiddleName,
                    LastName    = customer.LastName,
                    PhoneNumber = customer.PhoneNumber,
                    Address     = customer.Address,
                    City        = customer.City,
                    PostalCode  = customer.PostalCode,
                    OldDbId     = customer.OldDbId,
                    ExposeId    = customer.ExposeId
                });

                await context.SaveChangesAsync();
            }
            return(true);
        }
        public void UpdateAccount(OldCustomer customer, Account account, string newAcctName)
        {
            _customers.Remove(customer);
            customer.Accounts.Remove(account);

            account.Name = newAcctName;
            customer.Accounts.Add(account);
            _customers.Add(customer);
        }
        public bool CreateDebitTransaction(OldCustomer customer, Account account, decimal amount, string memo)
        {
            if (account.AcctType == AccountType.Savings)
            {
                var currentMonth = DateTime.Now.Month;
                var counter      = 0;
                if (account.Transactions != null)
                {
                    foreach (var t in account.Transactions)
                    {
                        var transMonth = t.TransactionDate.Month;
                        if (transMonth == currentMonth)
                        {
                            counter += 1;
                        }
                    }
                    if (counter >= 3)
                    {
                        return(false);
                    }
                }
            }

            _customers.Remove(customer);
            customer.Accounts.Remove(account);

            if (account.Transactions == null)
            {
                account.Transactions = new List <Transaction>()
                {
                };
            }

            if (account.Balance < amount)
            {
                if (account.AcctType == AccountType.Checkings)
                {
                    var transactionOC = CreateTransaction(15, "Overdraft fee", TransactionType.Debit);
                    account.Transactions.Add(transactionOC);
                }
                else
                {
                    var transactionOS = CreateTransaction(20, "Overdraft fee", TransactionType.Debit);
                    account.Transactions.Add(transactionOS);
                }
            }

            var transaction = CreateTransaction(amount, memo, TransactionType.Debit);

            account.Transactions.Add(transaction);
            customer.Accounts.Add(account);
            _customers.Add(customer);

            return(true);
        }
 public bool RemoveAccount(OldCustomer customer, Account account)
 {
     if (account.Balance == 0.0M)
     {
         _customers.Remove(customer);
         customer.Accounts.Remove(account);
         _customers.Add(customer);
         return(true);
     }
     return(false);
 }
        public int Create(string name, string email)
        {
            var customer = new OldCustomer
            {
                Id    = _customers.Max(c => c.Id) + 1,
                Name  = name,
                Email = email
            };

            _customers.Add(customer);
            return(customer.Id);
        }
Пример #6
0
 private Customer MapOldToNew(OldCustomer oldCustomer)
 {
     return(new Customer
     {
         Id = oldCustomer.id,
         RegNumber = oldCustomer.reg_broj,
         FirstName = oldCustomer.ime.ToPascalHRCase(),
         LastName = oldCustomer.prezime.ToPascalHRCase(),
         Address = string.IsNullOrEmpty(oldCustomer.mjesto) ? oldCustomer.adresa.ToPascalHRCase() : $"{oldCustomer.adresa.ToPascalHRCase()}, {oldCustomer.mjesto.ToPascalHRCase()}",
         Email = oldCustomer.mail.ToPascalHRCase(),
         RegDate = oldCustomer.datum_registracije,
         ValidUntil = oldCustomer.vrijeme_do
     });
 }
Пример #7
0
        // Add old customer in current data base
        public async Task <Boolean> AddOldCustomerAsync(OldCustomer customer)
        {
            using (var context = new ShopContext())
            {
                // if customer already exists, return error
                if (context.OldCustomers.Where(c => c.OldDbId == customer.OldDbId).FirstOrDefault() != null)
                {
                    return(false);
                }

                await context.OldCustomers.AddAsync(customer);

                await context.SaveChangesAsync();
            }
            return(true);
        }
Пример #8
0
        static void Main(string[] args)
        {
            Product product = new Product()
            {
                ProductName = "Cep Telefonu", UnitPrice = 7000
            };

            Console.WriteLine("-----------------ESKİ MÜŞTERİ----------------------");
            ProductManager productManager = new OldCustomer();

            productManager.Get(product);                          // Burada eski müşteri olarak hesap yapacak

            Console.WriteLine("*********************************");

            Console.WriteLine("-----------------YENİ MÜŞTERİ----------------------");
            ProductManager productManager2 = new NewCustomer();

            productManager2.Get(product);                         // Burada yeni müşteri olarak %10 indirimli bir şekilde ürünü görecek
        }
Пример #9
0
        /* This method packages the data from the different contexts into one combined object */
        private CombinedLink GetFullLinkFromContexts(CustomerLink bareCustomerLink)
        {
            NewCustomer newCustomerData = null;

            using (NewCustomersContext newContext = new NewCustomersContext(newCOptions))
            {
                if (bareCustomerLink.NewID != "")
                {
                    IQueryable <NewCustomer> filteredContext =
                        newContext.NewCustomer.Where(x => x.Id == bareCustomerLink.NewID);
                    if (filteredContext.Count() == 1)
                    {
                        newCustomerData = filteredContext.Single();
                    }
                }
            }

            OldCustomer oldCustomerData = null;

            using (OldCustomersContext oldContext = new OldCustomersContext(oldCOptions))
            {
                if (bareCustomerLink.OldID != -1)
                {
                    IQueryable <OldCustomer> filteredContext =
                        oldContext.OldCustomer.Where(x => x.Id == bareCustomerLink.OldID);
                    if (filteredContext.Count() == 1)
                    {
                        oldCustomerData = filteredContext.Single();
                    }
                }
            }

            CombinedLink fullLink = new CombinedLink
            {
                Link = bareCustomerLink,
                OldC = oldCustomerData,
                NewC = newCustomerData
            };

            return(fullLink);
        }
Пример #10
0
        static void Main(string[] args)
        {
            ICustomer customer1 = new OldCustomer()
            {
                TcNo = "12151413162", PlayerName = "James", PlayerLastName = "Herson", BirthYear = 1996, ParticipantDate = 2015
            };
            ICustomer customer2 = new OldCustomer()
            {
                TcNo = "13151416253", PlayerName = "Lonate", PlayerLastName = "dovar", BirthYear = 2000, ParticipantDate = 2016
            };
            ICustomer customer3 = new OldCustomer()
            {
                TcNo = "87898685425", PlayerName = "Lorem", PlayerLastName = "Ipsum", BirthYear = 1999, ParticipantDate = 2016
            };

            CustomerManager customerManager = new CustomerManager();

            customerManager.Add(customer1);
            customerManager.Add(customer2);
            customerManager.Add(customer3);

            GameManager gameManager = new GameManager();


            gameManager.Add(new Game()
            {
                GameName = "talent2", GameType = "Rpg", GamePrice = 24.99, ReleasedTime = 2023
            });
            gameManager.Add(new Game()
            {
                GameName = "orpto", GameType = "Action", GamePrice = 58.99, ReleasedTime = 2022
            });
            gameManager.Add(new Game()
            {
                GameName = "thortum", GameType = "Story", GamePrice = 299, ReleasedTime = 2021
            });


            customerManager.ListCustomer();
            gameManager.ListGame();
        }
        public void CreateCreditTransaction(OldCustomer customer, Account account, decimal amount, string memo)
        {
            var transaction = CreateTransaction(amount, memo, TransactionType.Credit);

            _customers.Remove(customer);
            customer.Accounts.Remove(account);

            if (account.Transactions != null)
            {
                account.Transactions.Add(transaction);
            }
            else
            {
                account.Transactions = new List <Transaction>
                {
                    transaction
                };
            }

            customer.Accounts.Add(account);
            _customers.Add(customer);
        }
Пример #12
0
        private CombinedLink GetFullLinkFromContexts(CustomerLink bareCustomerLink)
        {
            NewCustomer newCustomerData = null;

            if (bareCustomerLink.NewID != "")
            {
                IQueryable <NewCustomer> filteredContext =
                    _newContext.NewCustomer.Where(x => x.Id == bareCustomerLink.NewID);
                if (filteredContext.Count() == 1)
                {
                    newCustomerData = filteredContext.Single();
                }
            }

            OldCustomer oldCustomerData = null;

            if (bareCustomerLink.OldID != -1)
            {
                IQueryable <OldCustomer> filteredContext =
                    _oldContext.OldCustomer.Where(x => x.Id == bareCustomerLink.OldID);
                if (filteredContext.Count() == 1)
                {
                    oldCustomerData = filteredContext.Single();
                }
            }

            System.Diagnostics.Debug.WriteLine("Id: " /*+ oldCustomerData.Id*/);

            CombinedLink fullLink = new CombinedLink
            {
                Link = bareCustomerLink,
                OldC = oldCustomerData,
                NewC = newCustomerData
            };

            return(fullLink);
        }
Пример #13
0
        public void SetupDb()
        {
            using (var context = new OldCustomersContext(oldCOptions))
            {
                OldCustomer customer0a = new OldCustomer()
                {
                    Id        = oldIDs[0],
                    Username  = "******",
                    FirstName = "Elon",
                    Surname   = "Musk",
                    Address   = "Los Angeles",
                };

                OldCustomer customer1a = new OldCustomer()
                {
                    Id        = oldIDs[1],
                    Username  = "******",
                    FirstName = "Jimmy",
                    Surname   = "Whales",
                    Address   = "San Francisco"
                };

                context.OldCustomer.Add(customer0a);
                context.OldCustomer.Add(customer1a);
                context.SaveChanges();
            }

            using (var context = new NewCustomersContext(newCOptions))
            {
                NewCustomer customer0b = new NewCustomer()
                {
                    Id         = newIDs[0],
                    Username   = "******",
                    GivenNames = { "Elon", "Reeve", "Musk" },
                    Email      = "*****@*****.**"
                };

                NewCustomer customer1b = new NewCustomer()
                {
                    Id         = newIDs[1],
                    Username   = "******",
                    GivenNames = { "Jimmy", "Whales" },
                    Email      = "*****@*****.**"
                };

                context.NewCustomer.Add(customer0b);
                context.NewCustomer.Add(customer1b);
                context.SaveChanges();
            }

            using (var context = new LinksContext(linksOptions))
            {
                CustomerLink customer0 = new CustomerLink()
                {
                    OldID = oldIDs[0],
                    NewID = newIDs[0]
                };

                CustomerLink customer1a = new CustomerLink()
                {
                    OldID = oldIDs[1]
                };

                CustomerLink customer1b = new CustomerLink()
                {
                    NewID = newIDs[1]
                };

                context.CustomerLink.Add(customer0);
                context.CustomerLink.Add(customer1a);
                context.CustomerLink.Add(customer1b);
                context.SaveChanges();
            }
        }
Пример #14
0
        public OldCustomer CloseAccount(long accountNumber, string userName, string password)
        {
            OldCustomer oldCustomer = new OldCustomer();

            return(oldCustomer);
        }