/// <summary> /// 保存幻灯片文件:更新和新增 /// </summary> /// <param name="param"></param> /// <returns></returns> public async Task <BaseResult> SaveStaticFileAsync(SaveStaticFilesParamBase param) { var model = await _staticFilesRep.GetModelAsync(param.Id);//.Count($" and id ={param.Id}") > 0; if (model == null) { return(await SaveUploadFileAsync(param)); } else { return(await UpdateStaticFileAsync(param, model)); } }
/// <summary> /// 修改菜单 /// </summary> /// <param name="param"></param> /// <param name="model"></param> /// <returns></returns> private async Task <BaseResult> UpdateIconAndMenuInfoAsync(SaveMenuParam param, ClientMenus model) { var iconInfo = await _staticFilesRep.GetModelAsync(model.IconFileID); param.MenuIcon.Id = param.IconFileID.Value; //文件不同,需要重新保存修改 if (param.MenuIcon.SavePath.Substring(param.MenuIcon.SavePath.LastIndexOf('/') + 1) != iconInfo.SavePath) { _staticFilesSer.DeleteFile(iconInfo.SavePath); } using (var conn = _staticFilesRep.CreateMysqlConnection()) { using (var tran = conn.BeginTransaction()) { try { //根据id更新图片信息 param.MenuIcon.SavePath = param.MenuIcon.SavePath.Substring(param.MenuIcon.SavePath.LastIndexOf('/') + 1); param.MenuIcon.CreateTime = iconInfo.CreateTime; //param.MenuIcon.Title = iconInfo.Title; var updateResult = await _staticFilesRep.UpdateAsync(Mapper.Map <StaticFiles>(param.MenuIcon), tran); if (updateResult <= 0) { throw new Exception("图标信息保存失败"); } var menuUpdateResult = await _clientMenusRep.UpdateAsync(Mapper.Map <ClientMenus>(param), tran); if (menuUpdateResult <= 0) { throw new Exception("菜单信息保存失败"); } tran.Commit(); return(new Success("操作成功")); } catch (Exception ex) { tran.Rollback(); Trace.TraceError(ex.Message); return(new Fail("操作错误:" + ex.Message)); } } } }