public async Task <IActionResult> AddSkill([FromBody] AddSkillCommand command) { try { if (ModelState.IsValid) { var response = await _mediator.Send(command); return(StatusCode(response.ResponseStatusCode, response.Value)); } return(StatusCode(StatusCodes.Status400BadRequest)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
// Constructor public PlayerViewModel(IBasePoints basePoints, IPlayerStat playerStat) { this.BasePoints = basePoints; this.PlayerStat = playerStat; this.Skills = new ObservableCollection <IActiveSkill>(); this.Advantages = new ObservableCollection <IActiveAdvantage>(); this.Disadvantages = new ObservableCollection <IActiveDisadvantage>(); AddAttributeCommand = new DelegateCommand(PlayerStat.AddAttribute, null); SubAttributeCommand = new DelegateCommand(PlayerStat.SubAttribute, null); Scope = IoCContainer.Container.BeginLifetimeScope(); AddSkillCommand = new DelegateCommand( x => { Skills.Add(Scope.Resolve <IActiveSkill>()); AddSkillCommand.OnCanExecuteChanged(); }, x => AddSkillCanExecute() ); RemoveSkillCommand = new DelegateCommand( x => { var SelectedItem = Scope.Resolve <ISelectedItem>(); IActiveSkill z = Skills.First(p => p.Skill.Name == SelectedItem.SelectedSkillRemove.Skill.Name); BasePoints.UsedPoints -= z.Cost; RemoveSkillCommand.OnCanExecuteChanged(); Skills.Remove(SelectedItem.SelectedSkillRemove); }, x => Scope.Resolve <ISelectedItem>().SelectedSkillRemove != null); AddAdvantageCommand = new DelegateCommand( x => { IActiveAdvantage z = Scope.Resolve <IActiveAdvantage>(); if (z.Advantage.PtPerLvl > BasePoints.UnspentPoints) { return; } Advantages.Add(z); BasePoints.UsedPoints += z.Advantage.PtPerLvl; AddAdvantageCommand.OnCanExecuteChanged(); }, x => AddAdvantageCanExecute() ); RemoveAdvantageCommand = new DelegateCommand( x => { var SelectedItem = Scope.Resolve <ISelectedItem>(); IActiveAdvantage z = Advantages.First(p => p.Advantage.Name == SelectedItem.SelectedAdvantageRemove.Advantage.Name); BasePoints.UsedPoints -= z.Cost; RemoveAdvantageCommand.OnCanExecuteChanged(); Advantages.Remove(SelectedItem.SelectedAdvantageRemove); }, x => Scope.Resolve <ISelectedItem>().SelectedAdvantageRemove != null ); AddDisadvantageCommand = new DelegateCommand( x => { IActiveDisadvantage z = Scope.Resolve <IActiveDisadvantage>(); if ((z.Disadvantage.PtCost + BasePoints.UsedDisadvantagePoints) < BasePoints.MaxDisadvantagePoints) { return; } Disadvantages.Add(z); BasePoints.UsedDisadvantagePoints += z.Disadvantage.PtCost; AddDisadvantageCommand.OnCanExecuteChanged(); }, x => AddDisadvantageCanExecute() ); RemoveDisadvantageCommand = new DelegateCommand( x => { var SelectedItem = Scope.Resolve <ISelectedItem>(); IActiveDisadvantage z = Disadvantages.First(p => p.Disadvantage.Name == SelectedItem.SelectedDisadvantageRemove.Disadvantage.Name); BasePoints.UsedDisadvantagePoints -= z.Cost; RemoveDisadvantageCommand.OnCanExecuteChanged(); Disadvantages.Remove(SelectedItem.SelectedDisadvantageRemove); }, x => Scope.Resolve <ISelectedItem>().SelectedDisadvantageRemove != null ); }