private void GenerateCustomersForCompany(SellingCompany sellingCompany, SalesHubDbContext context) { Tuple <string, string>[] customerSeedData = new[] { new Tuple <string, string>("Blauer See Delikatessen", "Europe"), new Tuple <string, string>("Bottom-Dollar Markets", "North America"), new Tuple <string, string>("Chop-suey Chinese", "North America"), new Tuple <string, string>("Godos Cocina Típica", "South America"), new Tuple <string, string>("Lazy K Kountry Store", "North America"), new Tuple <string, string>("Let's Stop N Shop", "North America"), new Tuple <string, string>("Santé Gourmet", "Europe"), new Tuple <string, string>("Save-a-lot Markets", "North America"), new Tuple <string, string>("Suprêmes délices", "Europe"), new Tuple <string, string>("The Big Cheese", "North America"), new Tuple <string, string>("The Cracker Box", "North America"), new Tuple <string, string>("Okudacho Sushi", "Asia"), new Tuple <string, string>("Oyucho Japanese Cuisine", "Asia"), new Tuple <string, string>("LuLu Hypermarket", "Middle East") }; var customers = new List <Customer>(); foreach (var customerData in customerSeedData) { var customer = new Customer { CustomerName = customerData.Item1, Region = customerData.Item2, SellingCompany = sellingCompany, Orders = new List <Order>() }; customers.Add(customer); context.Customers.Add(customer); } context.SaveChanges(); var orders = new List <Order>(); foreach (var customer in customers) { orders.AddRange(GenerateOrdersForCustomer(customer, context)); } context.SaveChanges(); var origins = _originRepository.GetAllOrigins().ToList(); foreach (var order in orders) { var orderDetails = GenerateOrderDetailsForOrder(order, context, origins); order.ContractAmount = orderDetails.Sum(od => od.PricePerUnitOfWeight * od.Units); order.ContractWeight = orderDetails.Sum(od => od.Units * od.UnitWeight); } context.SaveChanges(); }
protected override void OnInit(EventArgs e) { base.OnInit(e); this.SellCompName.DataSource = SellingCompany.FetchAll(); this.SellCompName.FieldValue = CurrentSession.User.SellingCompanyId; SellingCompanyConfig sellingCompanyConfig = SellingCompanyConfig.FetchAllBySellingCompanyIdKeyName(CurrentSession.User.SellingCompanyId, "SC_VAT_METHOD").First(); this.VATCalculation.FieldValue = sellingCompanyConfig.IntValue.ToString(); }
protected override void Seed(SalesHubDbContext context) { base.Seed(context); User user = new User { UserId = 1, UserName = "******", FullName = "John Smith", PhoneNumber = "Something", EmailAddress = "*****@*****.**" }; SellingCompany sellingCompany = new SellingCompany { CompanyName = "Goods Selling Company", Abbreviation = "GSC", ManagedBy = new List <User> { user } }; CurrencyType currencyType = new CurrencyType { CurrencyName = "USD" }; context.CurrencyTypes.Add(currencyType); context.SellingCompanies.Add(sellingCompany); user.SellingCompanies = new List <SellingCompany> { sellingCompany }; context.Users.Add(user); context.SaveChanges(); GeneratePackageTypes(context); GeneratePaymentTermTypes(context); context.SaveChanges(); GenerateCustomersForCompany(sellingCompany, context); context.SaveChanges(); }
private SellingCompanyTreeViewItem BuildTreeViewForCompany(SellingCompany sellingCompany) { var treeViewItem = new SellingCompanyTreeViewItem { Text = sellingCompany.CompanyName, Expanded = true, Items = new List <SellingCompanyTreeViewItem>() }; var customersForCompany = _customerRepository.GetCustomersForSellingCompany(sellingCompany.SellingCompanyId) .GroupBy(c => c.Region) .OrderBy(c => c.Key); foreach (var grouping in customersForCompany) { treeViewItem.Items.Add(BuildTreeViewItemForCustomerGrouping(sellingCompany, grouping.Key, grouping.ToList())); } return(treeViewItem); }
private SellingCompanyTreeViewItem BuildTreeViewItemForCustomerGrouping(SellingCompany sellingCompany, string groupName, IEnumerable <Customer> customers) { var treeViewItem = new SellingCompanyTreeViewItem { Text = groupName, Items = new List <SellingCompanyTreeViewItem>() }; foreach (var customer in customers) { treeViewItem.Items.Add(new SellingCompanyTreeViewItem { CustomerId = customer.CustomerId, Text = customer.CustomerName }); } return(treeViewItem); }