public JsonpResult GetSchemaOfOrganizationsList(int id) { List<OrganizationSchemaViewModel> pos = new List<OrganizationSchemaViewModel>(); var orgs = _organizationRepository.Organizations .Where(x => x.Id.Equals(id) || x.ParentId.Equals(id) && x.StatusId == (byte)Status.Approved) .ToList(); foreach(var item in orgs) { var categories = _productRepository.Categories.Where(x => x.OrganizationId == item.Id); List<CategoryStructureViewModel> cs = new List<CategoryStructureViewModel>(); foreach (var c in categories) { cs.Add(new CategoryStructureViewModel { Id = c.Id, Name = c.Name, Sizes = _productRepository.GetAvailableSizes(c.Id) ?? new string[] { "" } }); } var orgVm = new OrganizationSchemaViewModel { Id = item.Id, Name = item.Name, Categories = cs.ToArray() }; pos.Add(orgVm); } return new JsonpResult { Data = new { Results = pos }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
// // GET: /balance/getorganizationstructure/100002 public JsonpResult GetOrganizationSchema(int id) { throw new Exception("Use GetSchemaOfOrganizationsList method instead!"); InfoFormat("Preparing JSON schema for main page (shops, categories). POS ID is {0}", id); OrganizationSchemaViewModel orgVm = new OrganizationSchemaViewModel(); var pos = _organizationRepository.GetById(id); orgVm.Id = pos.Id; orgVm.Name = pos.Name; //orgVm.Id = 100002; //orgVm.Name = "GJ"; orgVm.ReceivedAt = Common.GetTimestamp(DateTime.Now); var categories = new List<CategoryStructureViewModel>(); foreach(var c in _productRepository.Categories.Where(x => x.OrganizationId == pos.Id)) { categories.Add(new CategoryStructureViewModel { Id = c.Id, Name = c.Name, Sizes = _productRepository.GetAvailableSizes(c.Id) }); } //int catId = 1000; //categories.Add(new CategoryStructureViewModel //{ // Id = ++catId, // Name = "Avalyne", // Sizes = dbProduct.GetAvailableSizes(catId) //}); //categories.Add(new CategoryStructureViewModel //{ // Id = ++catId, // Name = "Apranga vyrams ir apranga moteris", // Sizes = dbProduct.GetAvailableSizes(catId) //}); //categories.Add(new CategoryStructureViewModel //{ // Id = ++catId, // Name = "Apranga vaikams", // Sizes = dbProduct.GetAvailableSizes(catId) //}); //categories.Add(new CategoryStructureViewModel //{ // Id = ++catId, // Name = "Kepures (priedai)", // Sizes = dbProduct.GetAvailableSizes(catId) //}); ////categories.Add(new ViewModels.Balance.CategoryStructureViewModel ////{ //// Id = ++catId, //// Name = "Kojines (priedai)", //// Sizes = new string[] { "122cm", "128", "134", "140", "152", "158", "164", "170", "176" } ////}); //categories.Add(new CategoryStructureViewModel //{ // Id = ++catId, // Name = "Kamuoliai (kita)", // Sizes = dbProduct.GetAvailableSizes(catId) //}); List<OrganizationViewModel> shops = new List<OrganizationViewModel>(); //var q = dbOrg.Items // .Where(x => x.StatusId == (byte)Status.Approved && (x.Id == id || x.ParentId == id)); var q = _organizationRepository.GetByParentId(pos.ParentId); InfoFormat("Organization which belong to organization #{0}", id); foreach(var item in q) { InfoFormat(" #{0}. {1}", item.Id, item.Name); shops.Add(new OrganizationViewModel { Id = item.Id, Name = item.Name }); } orgVm.Categories = categories.ToArray(); orgVm.Shops = shops; return new JsonpResult { Data = new { Results = orgVm }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }