private YandexMarketCategoryRecord InsertParserCategoryHierarhy(YandexMarketCategoryRecord yaCategory) { var oldYaCategory = this._yandexMarketCategoryService.GetAll() .SingleOrDefault(x => x.Name == yaCategory.Name && x.ParentId == yaCategory.ParentId); if (oldYaCategory != null) { return(oldYaCategory); } // Создаем только листья, категории-контейнеры для других категорий нам не нужны для парсенья if (yaCategory.Children.Count == 0) { _yandexMarketCategoryService.Insert(yaCategory); } foreach (var currentYaCategory in yaCategory.Children) { currentYaCategory.ParentId = yaCategory.Id; InsertParserCategoryHierarhy(currentYaCategory); } return(yaCategory); }
public ActionResult Add(YandexMarketParserModel model) { var newItem = new YandexMarketCategoryRecord() { Name = model.AddCategoryName }; _yandexMarketCategoryService.Insert(newItem); return(Json(new { Result = true })); }