Ejemplo n.º 1
0
        public async Task <SampleTable> MongoSave(SampleTableInput model)
        {
            /*
             * 接收请求参数方式一:
             * 接收参数类型是 JObject
             * 因此需要转换json对象到实体对象方式如下:
             * 首先设置id的标签  [JsonConverter(typeof(ObjectIdConverter))]
             * 然后通过对象转换 var model = jobject.ToObject<SampleTableInput>();
             *
             *  接收请求参数方式二:
             *  接收参数类型是 SampleTableInput
             *  这种方式请求会自动转换数据id为ObjectId类型,系统已经默认注册了转换对象
             */

            //SampleTableInput model = new SampleTableInput();

            if (!model.Id.HasValue)
            {
                SampleTable modelInput = model.MapTo <SampleTable>();
                // JObject model
                return(await _sampleRepository.InsertAsync(modelInput));
            }
            else
            {
                //获取需要更新的数据
                //SampleTable data = await _sampleRepository.GetAsync(ObjectId.Parse(model.Id.ToString()));
                SampleTable data = await _sampleRepository.GetAsync(model.Id.Value);

                //映射需要修改的数据对象
                SampleTable m = ObjectMapper.Map(model, data);
                //修改菜单主数据
                return(await _sampleRepository.UpdateAsync(m));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// JObject
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <JsonResult> MongoSave(SampleTableInput model)
        {
            var reslut = await _sampleAppService.MongoSave(model);

            return(Json(reslut));
        }