//修改 public async Task <FuncResult> Update(int year, Param model) { ApdDimRatio entity = await _context.ApdDimRatio.FindAsync(year); if (entity == null) { return(new FuncResult() { IsSuccess = false, Message = "未找到当前年份ID" }); } entity.NetAssesProfit = model.NetAssesProfit; entity.PollutantDischarge = model.PollutantDischarge; entity.Procuctivity = model.Procuctivity; entity.RDExpenditureRatio = model.RDExpenditureRatio; entity.TaxPerMu = model.TaxPerMu; entity.AddValuePerMu = model.TaxPerMu; entity.EnergyConsumption = model.EnergyConsumption; _context.ApdDimRatio.Update(entity); await _context.SaveChangesAsync(); return(new FuncResult() { IsSuccess = true, Content = entity, Message = "修改成功" }); }
/// <summary> /// 新增 /// </summary> /// <param name="model"></param> /// <param name="currentUserId"></param> /// <returns></returns> public async Task <FuncResult> Add(Params model) { ApdDimRatio entity = new ApdDimRatio { PeriodYear = model.PeriodYear, TaxPerMu = model.TaxPerMu, AddValuePerMu = model.AddValuePerMu, Procuctivity = model.Procuctivity, PollutantDischarge = model.PollutantDischarge, EnergyConsumption = model.EnergyConsumption, NetAssesProfit = model.NetAssesProfit, RDExpenditureRatio = model.RDExpenditureRatio }; await _context.ApdDimRatio.AddAsync(entity); using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trans = _context.Database.BeginTransaction()) { try { await _context.SaveChangesAsync(); trans.Commit(); } catch (Exception ex) { trans.Rollback(); return(new FuncResult() { IsSuccess = false, Content = ex.Message }); } } return(new FuncResult() { IsSuccess = true, Content = entity, Message = "添加成功" }); }
/// <summary> /// 删除 /// </summary> /// <param name="id"></param> /// <param name="currentUserId"></param> /// <returns></returns> public async Task <FuncResult> Delete(int year) { ApdDimRatio entity = await _context.ApdDimRatio.FindAsync(year); if (entity == null) { return(new FuncResult() { IsSuccess = false, Message = "ID不存在!" }); } _context.ApdDimRatio.Remove(entity); using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trans = _context.Database.BeginTransaction()) { try { await _context.SaveChangesAsync(); trans.Commit(); } catch (Exception ex) { trans.Rollback(); LogService.WriteError(ex); return(new FuncResult() { IsSuccess = false, Message = "删除时发生了意料之外的错误" }); } } ; return(new FuncResult() { IsSuccess = true, Content = entity, Message = "删除成功" }); }