public async Task <ServiceResponse <List <GetCharactorDto> > > AddCharactor(AddCharactorDto newCharactor) { ServiceResponse <List <GetCharactorDto> > serviceResponse = new ServiceResponse <List <GetCharactorDto> >(); // Charactor charactor = _mapper.Map<Charactor>(newCharactor); // charactor.Id = charactors.Max(c => c.Id) + 1; // charactors.Add(charactor); string cls = string.Format("{0:d2}", Convert.ToInt64(newCharactor.Class)); string insertSql = $@"insert into charactor (id, name, hitpoints, strength, defense, intelligence, class) values (SEQ_CHARACTORS.NEXTVAL, '{newCharactor.Name}', {newCharactor.HitPoints}, {newCharactor.Strength}, {newCharactor.Defense}, {newCharactor.Intelligence}, '{cls}')"; // OracleParameter[] param = new OracleParameter[] // { // AddInputParameter("viId", 1, OracleDbType.Int64), // AddInputParameter("viName", newCharactor.Name, OracleDbType.Varchar2, 50), // AddInputParameter("viHitpoints", newCharactor.HitPoints, OracleDbType.Int64), // AddInputParameter("viStrength", newCharactor.Strength, OracleDbType.Int64), // AddInputParameter("viDefense", newCharactor.Defense, OracleDbType.Int64), // AddInputParameter("viIntelligence", newCharactor.Intelligence, OracleDbType.Int64), // AddInputParameter("viRpgclass", string.Format("{0:d2}", Convert.ToInt64(newCharactor.Class)), OracleDbType.Varchar2, 2) // }; OracleConnection conn = await OpenConnAsync(); int affectRows = 0; //when try { affectRows = await ExecuteSqlAsync(insertSql, null, conn); serviceResponse = await GetAllCharactors(); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message + "; " + newCharactor.Class; } //then finally { conn.Close(); } return(serviceResponse); }
public async Task <IActionResult> AddCharactor(AddCharactorDto newCharactor) { return(Ok(await _charactorService.AddCharactor(newCharactor))); }