public static void CostUtemLoad() { if (_costItemLogic.Count() < 10) { List <CostItemBindingModel> list = new List <CostItemBindingModel> { new CostItemBindingModel { Name = "Мясо", Sum = 10000 }, new CostItemBindingModel { Name = "Питьевая вода", Sum = 3000 }, new CostItemBindingModel { Name = "Расчёски для пингвинов", Sum = 800 }, new CostItemBindingModel { Name = "Сахарная вата для гориллы", Sum = 1234 }, new CostItemBindingModel { Name = "Львиная зубная нить", Sum = 4321 }, new CostItemBindingModel { Name = "И", Sum = 6666 }, new CostItemBindingModel { Name = "Ещё", Sum = 5674 }, new CostItemBindingModel { Name = "5", Sum = 3643 }, new CostItemBindingModel { Name = "Статей", Sum = 23467 }, new CostItemBindingModel { Name = "Затрат", Sum = 99999 }, }; try { var routes = _routeLogic.Read(null); if (routes == null) { return; } int count = routes.Count(); Random rnd = new Random(); foreach (var cost in list) { var elem = _costItemLogic.GetElement(cost); if (elem != null) { cost.Id = elem.Id; cost.CostItemRoute = elem.CostItemRoute; } else { cost.CostItemRoute = routes.Skip(rnd.Next(0, count / 3)).Take(rnd.Next(1, count / 2)) .ToDictionary(x => x.Id, x => x.Name); } _costItemLogic.CreateOrUpdate(cost); } } catch { throw; } } }
public void CostUtemLoad() { List <CostItemBindingModel> list = new List <CostItemBindingModel> { new CostItemBindingModel { Name = "Мясо", Sum = 10000 }, new CostItemBindingModel { Name = "Питьевая вода", Sum = 3000 }, new CostItemBindingModel { Name = "Расчёски для пингвинов", Sum = 800 }, new CostItemBindingModel { Name = "Сахарная вата для гориллы", Sum = 1234 }, new CostItemBindingModel { Name = "Львиная зубная нить", Sum = 4321 }, new CostItemBindingModel { Name = "И", Sum = 6666 }, new CostItemBindingModel { Name = "Ещё", Sum = 5674 }, new CostItemBindingModel { Name = "5", Sum = 3643 }, new CostItemBindingModel { Name = "Статей", Sum = 23467 }, new CostItemBindingModel { Name = "Затрат", Sum = 99999 }, new CostItemBindingModel { Name = "Бэргеры", Sum = 5 } }; var routes = _routeLogic.Read(new RouteBindingModel { NoCost = true }); if ((routes == null || routes.Count == 0) && _costItemLogic.Count() >= list.Count) { return; } try { Random rand = new Random(); foreach (var route in routes) { int costCount = rand.Next(1, list.Count - 1); int start = rand.Next(0, list.Count - 2); if (start > costCount) { int temp = start; start = costCount; costCount = temp; } for (int i = start; i <= costCount; ++i) { var cost = list[i]; if (cost.CostItemRoute == null) { var elem = _costItemLogic.GetElement(cost); if (elem != null) { cost.CostItemRoute = elem.CostItemRoute; cost.Id = elem.Id; } else { cost.CostItemRoute = new Dictionary <int, string>(); } } if (!cost.CostItemRoute.ContainsKey(route.Id)) { cost.CostItemRoute.Add(route.Id, route.Name); } } } foreach (var cost in list) { if (cost.CostItemRoute != null && cost.CostItemRoute.Count > 0) { _costItemLogic.CreateOrUpdate(cost); } } } catch { throw; } }