public object PerformAction(Category category, ISession dataSession) { // been told that the Id is 0 if there is no value sent if (category.Id == 0) { try { dataSession.Save(category); } catch (Exception e) { throw (e); } } return GenerateCategory(category); }
protected static object GenerateCategory(Category result, bool recurseOnce = false) { return new { id = result.Id, title = result.Title, blurb = result.Blurb, tags = result.Tags.UnwrapCommas(), parentId = result.Parent == null ? 0 : result.Parent.Id, searchResultLinks = result.SearchResultLinks == null ? null : result.SearchResultLinks .Select(link => new { id = link.Id, title = link.Title, tags = link.Tags.UnwrapCommas() }), subCategories = result.SubCategories == null ? null : recurseOnce ? (object) result.SubCategories .Select(category => GenerateCategory(category)) : new { } }; }