public async Task <ServiceResponse <GetCharacter> > UpdateCharacter(UpdateCharacter updateCharacter) { ServiceResponse <GetCharacter> serviceResponse = new ServiceResponse <GetCharacter>(); Character character = characters.FirstOrDefault(c => c.Id == updateCharacter.Id); try { character.Name = updateCharacter.Name; character.Strength = updateCharacter.Strength; character.Class = updateCharacter.Class; character.Defence = updateCharacter.Defence; character.HitPoints = updateCharacter.HitPoints; character.Intelligence = updateCharacter.Intelligence; serviceResponse.Data = _mapper.Map <GetCharacter>(character); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <IActionResult> UpdateCharacter(UpdateCharacter updatedcharacter) { ServiceResponse <GetCharacter> response = await _characterService.UpdateCharacter(updatedcharacter); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public ActionResult CharacterUpdateView(UpdateCharacter uModel) { try { Character character = characterClient.Find(uModel.Name); characterClient.Update(character); return(RedirectToAction("CharacterView")); } catch (Exception ex) { Console.WriteLine(ex); return(View("CharacterUpdateView")); } }
public void MasterUpdateCharacter(string gameRefId, string characterId, PlayerCharacter info, Hashtable model, string world, int exp) { UpdateCharacter op = new UpdateCharacter { Deleted = false, CharacterId = characterId, GameRefId = gameRefId, Model = model, Race = (byte)info.Race, Workshop = (byte)info.Workshop, Exp = exp, WorldId = world }; OperationRequest request = new OperationRequest((byte)ServerToServerOperationCode.UpdateCharacter, op); this.MasterPeer.SendOperationRequest(request, new SendParameters()); }
public async Task <IActionResult> UpdateCharacter(int id, [FromBody] UpdateCharacter model) { try { if (model == null) { _logger.LogError("Character object sent from client is null."); return(BadRequest("Character object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Character object sent from client."); return(BadRequest("Invalid model object")); } Character entity = await _db.Characters.FirstOrDefaultAsync(x => x.Id == id); if (entity == null) { _logger.LogError($"Character with id: {id}, hasn't been found in db."); return(NotFound()); } _mapper.Map(model, entity); _db.Characters.Update(entity); await _db.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateCharacter action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public ActionResult CharacterUpdateView(string Name) { if (Name == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } else { Character character = characterClient.Find(Name); if (character == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } else { UpdateCharacter uModel = new UpdateCharacter(); uModel.Name = character.Name; uModel.Level = character.Level; uModel.Class = character.Class; uModel.BackGroundStory = character.BackGroundStory; return(View(uModel)); } } }
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { try { if (log.IsDebugEnabled) { log.DebugFormat("OnOperationRequest: pid={0}, op={1}", this.ConnectionId, operationRequest.OperationCode); } OperationResponse response = null; switch ((ServerToServerOperationCode)operationRequest.OperationCode) { default: response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = -1, DebugMessage = "Unknown operation code" }; break; case ServerToServerOperationCode.RegisterGameServer: { response = this.ServerId.HasValue ? new OperationResponse(operationRequest.OperationCode) { ReturnCode = -1, DebugMessage = "Already registered" } : this.HandleRegisterGameServerRequest(operationRequest); break; } case ServerToServerOperationCode.UpdateShipModel: { UpdateShipModel operation = new UpdateShipModel(this.Protocol, operationRequest); if (!operation.IsValid) { response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = (short)ReturnCode.InvalidOperationParameter, DebugMessage = "InvalidOperationParameter" }; } else { UpdateShipModelEvent evtData = new UpdateShipModelEvent { CharacterId = operation.CharacterId, GameRefId = operation.GameRefId, SlotType = operation.SlotType, TemplateId = operation.TemplateId }; EventData evt = new EventData((byte)S2SEventCode.UpdateShipModel, evtData); application.GameServers.SendEvent(evt, new SendParameters(), ServerType.SelectCharacter); } break; } case ServerToServerOperationCode.UpdateCharacter: { UpdateCharacter operation = new UpdateCharacter(this.Protocol, operationRequest); UpdateCharacterEvent evtData = new UpdateCharacterEvent { CharacterId = operation.CharacterId, Deleted = operation.Deleted, GameRefId = operation.GameRefId, Model = operation.Model, Race = operation.Race, Workshop = operation.Workshop, Exp = operation.Exp, WorldId = operation.WorldId }; EventData evt = new EventData((byte)S2SEventCode.UpdateCharacter, evtData); application.GameServers.SendEvent(evt, new SendParameters(), ServerType.SelectCharacter); break; } } if (response != null) { this.SendOperationResponse(response, sendParameters); } } catch (Exception ex) { log.Error(ex); } }
public ICharacterModel Any(UpdateCharacter request) { return(workflow.Update(request)); }