public async Task <JsonResult> PostRegisterInvestmentProductAmount([FromBody] RegisterInvestmentProductRequestAmountDto dto) { await this._financial.RegisterInvestmentProductAmount(dto); return(new JsonResult(new { Result = true })); }
/// <summary> /// 投資商品取得量登録 /// </summary> /// <param name="dto">DTO</param> public async Task RegisterInvestmentProductAmount(RegisterInvestmentProductRequestAmountDto dto) { var date = DateTime.Parse(dto.Date); await using var transaction = await this._db.Database.BeginTransactionAsync(); var record = await this._db.InvestmentProductAmounts .FirstOrDefaultAsync(x => x.InvestmentProductId == dto.InvestmentProductId && x.InvestmentProductAmountId == dto.InvestmentProductAmountId); if (record == null) { var max = this._db .InvestmentProductAmounts .Where(x => x.InvestmentProductId == dto.InvestmentProductId) .Max(x => (int?)x.InvestmentProductAmountId) ?? 0; await this._db.InvestmentProductAmounts.AddAsync(new InvestmentProductAmount { InvestmentProductId = dto.InvestmentProductId, InvestmentProductAmountId = max + 1, Date = date, Amount = dto.Amount, Price = dto.Price }); } else { record.Date = date; record.Amount = dto.Amount; record.Price = dto.Price; this._db.InvestmentProductAmounts.Update(record); } await this._db.SaveChangesAsync(); await transaction.CommitAsync(); }