コード例 #1
0
        public async Task <IActionResult> UpdateCharactor(UpdateCharactorDto updateCharactor)
        {
            ServiceResponse <GetCharactorDto> response = await _charactorService.UpdateCharactor(updateCharactor);

            if (response.Data == null)
            {
                return(NotFound(response));
            }
            return(Ok(response));
        }
コード例 #2
0
        public async Task <ServiceResponse <GetCharactorDto> > UpdateCharactor(UpdateCharactorDto updateCharactorDto)
        {
            ServiceResponse <GetCharactorDto> serviceResponse = new ServiceResponse <GetCharactorDto>();
            string           cls       = string.Format("{0:d2}", Convert.ToInt64(updateCharactorDto.Class));
            string           updateSql = $@"update charactor
                                     set name         = '{updateCharactorDto.Name}', 
                                         hitpoints    = {updateCharactorDto.HitPoints}, 
                                         strength     = {updateCharactorDto.Strength}, 
                                         defense      = {updateCharactorDto.Defense}, 
                                         intelligence = {updateCharactorDto.Intelligence}, 
                                         class        = '{cls}'
                                  where id = {updateCharactorDto.Id}";
            OracleConnection conn      = await OpenConnAsync();

            int affectRows = 0;

            try
            {
                affectRows = await ExecuteSqlAsync(updateSql, null, conn);

                if (affectRows < 1)
                {
                    throw new Exception($@"更新失败,未找到id为{updateCharactorDto.Id}的记录!");
                }

                serviceResponse = await GetCharactorById(updateCharactorDto.Id);

                // Charactor charactor = charactors.FirstOrDefault(c => c.Id == updateCharactorDto.Id);
                // charactor.Name = updateCharactorDto.Name;
                // charactor.HitPoints = updateCharactorDto.HitPoints;
                // charactor.Strength = updateCharactorDto.Strength;
                // charactor.Defense = updateCharactorDto.Defense;
                // charactor.Intelligence = updateCharactorDto.Intelligence;
                // charactor.Class = updateCharactorDto.Class;
                //serviceResponse.Data = _mapper.Map<GetCharactorDto>(charactor);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return(serviceResponse);
        }