public async Task <ActionResult <AnnualBalance> > PostAnnualBalance(AnnualBalance annualBalance) { _context.AnnualBalance.Add(annualBalance); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAnnualBalance", new { id = annualBalance.Id }, annualBalance)); }
public async Task <IActionResult> PutAnnualBalance(int id, AnnualBalance annualBalance) { if (id != annualBalance.Id) { return(BadRequest()); } _context.Entry(annualBalance).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnnualBalanceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> SaveBalance(ProjectManageViewModel model) { if (ModelState.IsValid) { var balances = await _projectService.GetAnnualBalances(model.EditingBalance.ProjectId, model.EditingBalance.Year); //1. 检查和保存incoming var incoming = balances.Where(b => b.BalanceCategory == (int)BalanceCategory.Incoming).FirstOrDefault(); if (incoming == null || incoming.Id <= 0) { //新增 incoming = new AnnualBalance { ProjectId = model.EditingBalance.ProjectId, Year = model.EditingBalance.Year, BalanceCategory = (int)BalanceCategory.Incoming, }; } incoming.Balance = model.EditingBalance.Incoming; await _projectService.SaveBalance(incoming); //2. 检查和保存settle var settle = balances.Where(b => b.BalanceCategory == (int)BalanceCategory.Settlement).FirstOrDefault(); if (settle == null || settle.Id <= 0) { //新增 settle = new AnnualBalance { ProjectId = model.EditingBalance.ProjectId, Year = model.EditingBalance.Year, BalanceCategory = (int)BalanceCategory.Settlement, }; } settle.Balance = model.EditingBalance.Settlement; await _projectService.SaveBalance(settle); //3. 检查和保存retrieve var retrieve = balances.Where(b => b.BalanceCategory == (int)BalanceCategory.Retrievable).FirstOrDefault(); if (retrieve == null || retrieve.Id <= 0) { //新增 retrieve = new AnnualBalance { ProjectId = model.EditingBalance.ProjectId, Year = model.EditingBalance.Year, BalanceCategory = (int)BalanceCategory.Retrievable, }; } retrieve.Balance = model.EditingBalance.Retrievable; await _projectService.SaveBalance(retrieve); return(RedirectToAction(nameof(Manage), new { id = model.EditingBalance.ProjectId })); } return(StatusCode(500)); }
public async Task SaveBalance(AnnualBalance balance) { if (balance.Id > 0) { await _apiConnector.HttpPutAsync <AnnualBalance, StatusCodeResult>( ROUTE_BALANCE + $"/{balance.Id}", balance); } else { await _apiConnector.HttpPostAsync <AnnualBalance, AnnualBalance>( ROUTE_BALANCE, balance); } }