internal static void Initialize(CustomerManagerContext context)
        {
            var random = new Random();

            //Generate customers and orders
            for (int i = 0; i < customerNames.Length; i++)
            {
                var nameGender = SplitValue(customerNames[i]);
                var cityState = SplitValue(citiesStates[i]);
                var cust = new Customer
                {
                    Id = i + 1,
                    FirstName = nameGender[0],
                    LastName = nameGender[1],
                    Address = addresses[i],
                    City = cityState[0],
                    State = cityState[1],
                    Zip = zip + i,
                    Gender = (Gender)Enum.Parse(typeof(Gender), nameGender[2])
                };
                context.Customers.Add(cust);

                //Generate customer orders
                var skip = random.Next(orders.Count - 1);
                var take = orders.Count - skip;
                var custOrders = orders.Skip(skip).Take(take);
                foreach (var order in custOrders)
                {
                    var custOrder = order.Clone();
                    custOrder.CustomerId = cust.Id;
                    context.Orders.Add(custOrder);
                }
            }
        }
        internal static void Initialize(CustomerManagerContext context)
        {
            var random = new Random((int)DateTime.Now.Ticks);
            var randomOrder = new Random((int)DateTime.Now.Ticks);
            var randomQuantity = new Random((int)DateTime.Now.Ticks);

            var sortedStates = states.OrderBy(s => s.Name);
            foreach (var state in sortedStates)
            {
                context.States.Add(state);
            }

            //Generate customers and orders
            for (int i = 0; i < customerNames.Length; i++)
            {
                var nameGenderHost = SplitValue(customerNames[i]);
                var cityState = SplitValue(citiesStates[i]);
                var cust = new Customer 
                {
                    Id = i + 1,
                    FirstName = nameGenderHost[0],
                    LastName = nameGenderHost[1],
                    Email= String.Format("{0}.{1}@{2}", nameGenderHost[0], nameGenderHost[1], nameGenderHost[3]),
                    Address = addresses[i],
                    City = cityState[0],
                    State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault(),
                    Zip = zip + i,
                    Gender = (Gender)Enum.Parse(typeof(Gender), nameGenderHost[2])
                };
                context.Customers.Add(cust);

                //Generate customer orders
                var numToGrab = random.Next(orders.Count - 1);
                var custOrders = new List<Order>();
                for (int j = 0; j < numToGrab; j++)
                {
                    var orderPosition = randomOrder.Next(orders.Count - 1);
                    custOrders.Add(orders[orderPosition]);
                }

                foreach (var order in custOrders)
                {
                    var quantity = randomQuantity.Next(5);
                    var multiplier = (quantity % 2 == 0) ? 1 : -1;
                    var custOrder = order.Clone();
                    custOrder.Quantity = (quantity == 0) ? 1 : quantity;
                    custOrder.Date = DateTime.Now.AddDays(randomQuantity.Next(30) * multiplier);
                    custOrder.CustomerId = cust.Id;
                    context.Orders.Add(custOrder);
                }
            }
             
        }
        internal static void Initialize(CustomerManagerContext context)
        {
            var random         = new Random((int)DateTime.Now.Ticks);
            var randomOrder    = new Random((int)DateTime.Now.Ticks);
            var randomQuantity = new Random((int)DateTime.Now.Ticks);

            var sortedStates = states.OrderBy(s => s.Name);

            foreach (var state in sortedStates)
            {
                context.States.Add(state);
            }

            //Generate customers and orders
            for (int i = 0; i < customerNames.Length; i++)
            {
                var nameGenderHost = SplitValue(customerNames[i]);
                var cityState      = SplitValue(citiesStates[i]);
                var cust           = new Customer
                {
                    Id        = i + 1,
                    FirstName = nameGenderHost[0],
                    LastName  = nameGenderHost[1],
                    Email     = String.Format("{0}.{1}@{2}", nameGenderHost[0], nameGenderHost[1], nameGenderHost[3]),
                    Address   = addresses[i],
                    City      = cityState[0],
                    State     = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault(),
                    Zip       = zip + i,
                    Gender    = (Gender)Enum.Parse(typeof(Gender), nameGenderHost[2])
                };
                context.Customers.Add(cust);

                //Generate customer orders
                var numToGrab  = random.Next(orders.Count - 1);
                var custOrders = new List <Order>();
                for (int j = 0; j < numToGrab; j++)
                {
                    var orderPosition = randomOrder.Next(orders.Count - 1);
                    custOrders.Add(orders[orderPosition]);
                }

                foreach (var order in custOrders)
                {
                    var quantity   = randomQuantity.Next(5);
                    var multiplier = (quantity % 2 == 0) ? 1 : -1;
                    var custOrder  = order.Clone();
                    custOrder.Quantity   = (quantity == 0) ? 1 : quantity;
                    custOrder.Date       = DateTime.Now.AddDays(randomQuantity.Next(30) * multiplier);
                    custOrder.CustomerId = cust.Id;
                    context.Orders.Add(custOrder);
                }
            }
        }
Example #4
0
 public CustomerRepository()
 {
     _Context = new CustomerManagerContext();
     //System.Threading.Thread.Sleep(5000);
 }
 public CustomerRepository()
 {
     _Context = new CustomerManagerContext();
     //System.Threading.Thread.Sleep(5000);
 }
 public DataServiceController()
 {
     _Context = new CustomerManagerContext();
 }
 public DataServiceController()
 {
     _Context = new CustomerManagerContext();
     //System.Threading.Thread.Sleep(5000);
 }
 public CustomerRepository()
 {
     _context = new CustomerManagerContext();
 }
        internal static void Initialize(CustomerManagerContext context)
        {
            var random = new Random();

            var sortedStates = states.OrderBy(s => s.Name);
            foreach (var state in sortedStates)
            {
                context.States.Add(state);
            }

            //Generate customers and orders
            for (int i = 0; i < customerNames.Length; i++)
            {
                var nameGenderHost = SplitValue(customerNames[i]);
                var cityState = SplitValue(citiesStates[i]);
                var cust = new Customer
                {
                    Id = i + 1,
                    FirstName = nameGenderHost[0],
                    LastName = nameGenderHost[1],
                    Email= String.Format("{0}.{1}@{2}", nameGenderHost[0], nameGenderHost[1], nameGenderHost[3]),
                    Address = addresses[i],
                    City = cityState[0],
                    State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault(),
                    Zip = zip + i,
                    Gender = (Gender)Enum.Parse(typeof(Gender), nameGenderHost[2])
                };
                context.Customers.Add(cust);

                //Generate customer orders
                var skip = random.Next(orders.Count - 1);
                var take = orders.Count - skip;
                var custOrders = orders.Skip(skip).Take(take);
                foreach (var order in custOrders)
                {
                    var custOrder = order.Clone();
                    custOrder.CustomerId = cust.Id;
                    context.Orders.Add(custOrder);
                }
            }
        }