public async Task <IActionResult> EditAsync() { //返回值对象 var result = new PageResultDto(); //获取表单提交的数据(文件和文本框等) var files = Request.Form.Files; var para = Request.Form["data"]; //将表单数据转为实体对象 var model = System.Text.Json.JsonSerializer.Deserialize <InterInvite>(para); if (model == null || string.IsNullOrEmpty(model.CompanyID)) { result.Code = (int)ResultCode.UNAUTHORIZED; result.Msg = "参数无效"; return(Ok(result)); } model.State = model.State == "on" ? "0" : "1"; if (files != null && files.Count > 0) { var list = await new Common.FileUpload(_host).UploadAsync(files, "brand"); if (list != null && list.Count > 0) { model.Images = list.FirstOrDefault(); } } int res; try { if (!string.IsNullOrEmpty(model.ID) && !model.ID.ToString().ToLower().Equals("string")) { res = _services.Update <InterInvite>(model); } else { SnowFlakeWork snowFlake = new SnowFlakeWork(1);//雪花ID model.ID = snowFlake.NextID().ToString(); res = _services.Insert <InterInvite>(model); } result.Count = res > 0 ? 1 : 0; } catch (Exception ex) { result.Code = (int)ResultCode.INTERNAL_SERVER_ERROR; result.Msg = "内部操作错误,请联系管理员或查看错误日志。"; log.Error($"/{System.Reflection.MethodBase.GetCurrentMethod().Name}方法/错误信息:【{ex.Message}】"); } return(Ok(result)); }
public IActionResult Edit(RetailCategory model) { var result = new PageResultDto(); if (model == null || string.IsNullOrEmpty(model.Name)) { result.Code = (int)ResultCode.UNAUTHORIZED; result.Msg = "参数无效"; return(Ok(result)); } model.State = model.State == "on" ? "0" : "1"; int res; try { if (!string.IsNullOrEmpty(model.ID) && !model.ID.ToString().ToLower().Equals("string")) { res = _services.Update <RetailCategory>(model); } else { SnowFlakeWork snowFlake = new SnowFlakeWork(1); model.ID = snowFlake.NextID().ToString(); res = _services.Insert <RetailCategory>(model); } result.Count = res > 0 ? 1 : 0; } catch (Exception ex) { result.Code = (int)ResultCode.INTERNAL_SERVER_ERROR; result.Msg = "内部操作错误,请联系管理员或查看错误日志。"; log.Error($"/{System.Reflection.MethodBase.GetCurrentMethod().Name}方法/错误信息:【{ex.Message}】"); } return(Ok(result)); }
public async Task <IActionResult> EditAsync() { //返回值对象 var result = new PageResultDto(); //获取表单提交的数据(文件和文本框等) var files = Request.Form.Files; var para = Request.Form["data"]; //将表单数据转为实体对象 var brand = System.Text.Json.JsonSerializer.Deserialize <RetailBrand>(para); if (brand == null || string.IsNullOrEmpty(brand.BrandName)) { result.Code = (int)ResultCode.UNAUTHORIZED; result.Msg = "参数无效"; return(Ok(result)); } //string sql = ""; brand.State = brand.State == "on" ? "0" : "1"; if (files != null && files.Count > 0) { var list = await new Common.FileUpload(_host).UploadAsync(files, "brand"); if (list != null && list.Count > 0) { brand.Logo = list.FirstOrDefault(); } } int res; try { //注释的sql语句和执行语句为直接采用dapper if (!string.IsNullOrEmpty(brand.ID) && !brand.ID.ToString().ToLower().Equals("string")) { res = _services.Update <RetailBrand>(brand); //sql = "update retail_brand set brandname=@brandname,description=@description,sort=@sort,state=@state where id=@id"; } else { SnowFlakeWork snowFlake = new SnowFlakeWork(1);//雪花ID brand.ID = snowFlake.NextID().ToString(); res = _services.Insert <RetailBrand>(brand); //sql = "insert into retail_brand (id,brandname,description,logo,sort,state) " + // "values(@id,@brandname,@description,@logo,@sort,@state)"; } //res = _dapper.Execute(sql, brand); result.Count = res > 0 ? 1 : 0; } catch (Exception ex) { result.Code = (int)ResultCode.INTERNAL_SERVER_ERROR; result.Msg = "内部操作错误,请联系管理员或查看错误日志。"; log.Error($"/{System.Reflection.MethodBase.GetCurrentMethod().Name}方法/错误信息:【{ex.Message}】"); } return(Ok(result)); }