public async Task <Models.ContentManager.Category> CategoryInfo(string id) { var model = new Models.ContentManager.Category() { _id = string.Empty, blocks = new List <Block>(), parentId = string.Empty, title = string.Empty, userid = string.Empty }; try { var _model = await NoSql.Instance.RunCommandAsync <BsonDocument>("{aggregate:'categories',pipeline:[{$match:{_id:ObjectId('" + id + "')}},{$limit:1}]}"); if (_model.GetValue("result").AsBsonArray.Any()) { model = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <Models.ContentManager.Category>(_model.GetValue("result")[0].AsBsonDocument); } } catch (Exception ex) { } return(model); }
public async Task <bool> EditCategory(Models.ContentManager.Category model) { try { var _id = ObjectId.GenerateNewId().ToString(); if (!string.IsNullOrWhiteSpace(model._id)) { _id = model._id; } var res = await NoSql.Instance.RunCommandAsync <BsonDocument>("{update:'categories',updates:[{q:{_id:ObjectId('" + _id + "')},u:{$set:{_id:ObjectId('" + _id + "'),title:'" + model.title + "',userid:'" + model.userid + "',parentId:'" + model.parentId + "',blocks:" + model.blocks.toJSON() + "}},upsert:true}]}"); return(true); } catch (Exception ex) { return(false); } }