public async Task <IActionResult> AddOrUpdate(Guid appHeaderId, Guid appStructId, string Id) { var itemList = await dbContext.AppStructItem .Where(x => x.AppHeaderId == appHeaderId && x.AppStructId == appStructId) .ToListAsync(); var tmp = DataExtension.StrucItemToModelType(itemList); tmp.Add(new ModelInfo { PropName = "hide", Name = "_id" }); ViewData["ModelType"] = tmp; var appHeaderIdStr = appHeaderId.ToString(); var appStructIdStr = appStructId.ToString(); if (!string.IsNullOrEmpty(Id)) { //new QueryComplete(); var collection = mongo.GetDatabase(appHeaderIdStr).GetCollection <BsonDocument>(appStructIdStr); var data = await collection.Find(new BsonDocument("_id", ObjectId.Parse(Id))).FirstAsync(); ViewData["ModelData"] = data.BsonToModelData(); } return(View()); }
public async Task <IActionResult> AddOrUpdate(Guid appHeaderId, Guid appStructId) { var itemList = await dbContext.AppStructItem .Where(x => x.AppHeaderId == appHeaderId && x.AppStructId == appStructId) .ToListAsync(); var tmp = DataExtension.StrucItemToModelType(itemList); tmp.Add(new ModelInfo { PropName = "hide", Name = "_id" }); ViewData["ModelType"] = tmp; var appHeaderIdStr = appHeaderId.ToString(); var appStructIdStr = appStructId.ToString(); var entityData = HttpContext.Request.Form.GetBson(); var entity = HttpContext.Request.Form.GetJson(); var id = entity["_id"]?.ToString(); var apiMsg = await ApiMessage.Wrap(async() => { var collection = mongo.GetDatabase(appHeaderIdStr).GetCollection <BsonDocument>(appStructIdStr); if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString()) { await collection.InsertOneAsync(entityData); } else { await collection.FindOneAndUpdateAsync(filter: new BsonDocument("_id", ObjectId.Parse(id)), update: entityData); } }); return(Json(apiMsg)); }