public ActionResult CategorySelector(string parentid) { var cats = db.trademe_categories .Where(x => x.parentid == parentid && x.id != parentid && x.active); var viewmodel = new EbayCategoryCondition(); if (!cats.Any() && !string.IsNullOrEmpty(parentid)) { // we have reached a leaf, get item conditions var selectedCat = db.trademe_categories.SingleOrDefault(x => x.id == parentid); if (selectedCat != null) { viewmodel.durations = selectedCat.trademe_listingdurations .Where(x => x.categoryid == selectedCat.id) .Select(x => new IdName() { name = x.duration == 1 ? (x.duration + " day"):(x.duration + " days"), id = x.duration.ToString(), }); } } else { viewmodel.categories = cats.Select(x => new IdName() { id = x.id, name = x.name }); } return(Json(viewmodel.ToJsonOKData(), JsonRequestBehavior.AllowGet)); }
public ActionResult CategorySelector(ListingTypeCodeType type, SiteCodeType site, int?parentid, int?level) { Debug.Assert(parentid.HasValue || level.HasValue); var cats = db.ebay_categories.Where(x => x.siteid == site.ToString()); if (parentid.HasValue) { cats = cats.Where(x => x.parentid == parentid.Value && x.categoryid != parentid.Value); } if (level.HasValue) { cats = cats.Where(x => x.level == level.Value); } var viewmodel = new EbayCategoryCondition(); if (!cats.Any() && parentid.HasValue) { // we have reached a leaf, get item conditions var condition_category = db.ebay_categories.SingleOrDefault(x => x.siteid == site.ToString() && x.categoryid == parentid.Value); if (condition_category != null) { viewmodel.conditions = condition_category.ebay_conditions .Select(x => new IdName() { name = x.name, id = x.value.ToString() }); viewmodel.durations = condition_category.ebay_listingdurations .Where(x => x.listingtypeid == type.ToString()) .Select(x => new IdName() { name = EbayProductViewModel.DurationNames.ContainsKey(x.duration)?EbayProductViewModel.DurationNames[x.duration]:x.duration, id = x.duration }); } } else { viewmodel.categories = cats.Select(x => new IdName() { id = x.categoryid.ToString(), name = x.name }); } return(Json(viewmodel.ToJsonOKData(), JsonRequestBehavior.AllowGet)); }