public async Task <ServiceResult> PostEditBlockRssBind([FromBody] ViewModel.ContentManager.CategoryRssBindEditVM model) { try { //Clean All Blocks Then Add BlockRssIdBind var res = await ContentManagerRepository.DeleteUserCategoriesBlocks(); foreach (var CategoryGroup in model.BlockRssBind.GroupBy(q => q.CategoryId)) { foreach (var BlockCodeGroup in CategoryGroup.GroupBy(q => q.BlockCode)) { var BlockModel = new Models.ContentManager.Block { code = BlockCodeGroup.FirstOrDefault().BlockCode, blockrssbind = (from b in BlockCodeGroup select b.RssId).ToList() }; res = await ContentManagerRepository.EditCategoryBlocks(BlockCodeGroup.FirstOrDefault().CategoryId, BlockModel); } } return(new ViewModel.ServiceResult() { ServiceResultStatus = (int)Rdio.Util.Common.ServiceResultStatus.OK, ServiceResultMassage = Util.Common.ServiceResultMessage.OKMessage.ToString() }); } catch (Exception ex) { return(new ViewModel.ServiceResult() { ServiceResultStatus = (int)Rdio.Util.Common.ServiceResultStatus.Error, ServiceResultMassage = ex.GetBaseException().Message }); } }
public async Task <bool> EditCategoryBlocks(string CategoryId, Models.ContentManager.Block block) { try { var res = await NoSql.Instance.RunCommandAsync <BsonDocument>("{update:'categories',updates:[{q:{_id:ObjectId('" + CategoryId + "'),'blocks.code':'" + block.code + "'},u:{$set:{'blocks.$.blockrssbind':" + block.blockrssbind.toJSON() + "}},upsert:false}]}"); return(true); } catch (Exception ex) { return(false); } }