public void AddSuperhero(String name, IEnumerable<Skill> skills, IEnumerable<Team> teams) { if (name == null) throw new ArgumentNullException(nameof(name)); if (skills == null) throw new ArgumentNullException(nameof(skills)); if (teams == null) throw new ArgumentNullException(nameof(teams)); var superhero = new Superhero { Name = name, Skills = skills.ToList(), Teams = teams.ToList() }; context.Superheroes.Add(superhero); var allTeams = GetTeams().ToArray(); foreach (var team in teams) { var savedTeam = allTeams.FirstOrDefault(element => element.Id == team.Id); savedTeam.SuperHeroes.Add(superhero); } context.SaveChanges(); }
public Int32 AddSuperhero(String name, IEnumerable<Skill> skills, IEnumerable<Team> teams, Boolean isOnMission) { if (name == null) throw new ArgumentNullException(nameof(name)); if (skills == null) throw new ArgumentNullException(nameof(skills)); if (teams == null) throw new ArgumentNullException(nameof(teams)); var superhero = new Superhero { Name = name, Skills = skills.ToList(), Teams = teams.ToList(), IsOnMission = isOnMission }; context.Superheroes.Add(superhero); var allTeams = GetTeams().ToArray(); foreach (var team in teams) { var savedTeam = allTeams.FirstOrDefault(element => element.Name == team.Name); savedTeam.SuperHeroes.Add(superhero); } context.SaveChanges(); idCounter++; return idCounter; }
public IHttpActionResult CreateSuperhero(Superhero superhero) { this.repository.AddSuperhero( superhero.Name, superhero.Skills, superhero.Teams ); return Ok(); }
public async Task RemoveSuperheroAsync(Superhero selectedSuperhero) { if (selectedSuperhero == null) throw new ArgumentNullException(nameof(selectedSuperhero)); var response = await client.DeleteAsync($"api/superhero/{selectedSuperhero.Id}"); if (!response.IsSuccessStatusCode) { throw new Exception($"An error has been occured during removing the selected superhero"); } }
public IHttpActionResult CreateSuperhero(Superhero superhero) { var id = this.repository.AddSuperhero( superhero.Name, superhero.Skills ?? Enumerable.Empty<Skill>(), superhero.Teams ?? Enumerable.Empty<Team>(), isOnMission: false ); return Ok(id); }
public void AddSuperhero(String name, IEnumerable<Skill> skills, IEnumerable<Team> teams) { var superhero = new Superhero { Name = name, Skills = skills?.ToList(), Teams = teams?.ToList() }; this.superheroes.Add(superhero); }
public async Task<Superhero> UpdateSuperheroAsync(Int32 id, Superhero value) { if (value == null) throw new ArgumentNullException(nameof(value)); var response = await client.PutAsJsonAsync($"api/superhero/{value.Id}", value); if (!response.IsSuccessStatusCode) { throw new Exception("An error has been occured during updating the selected superhero"); } return await response.Content.ReadAsAsync<Superhero>(); }
public async Task<Int32> CreateSuperheroAsync(Superhero superhero) { if (superhero == null) throw new ArgumentNullException(nameof(superhero)); var response = await client.PostAsJsonAsync("api/superhero", superhero); if (!response.IsSuccessStatusCode) { throw new Exception($"An error has been occured during adding a new superhero: {response.StatusCode}"); } var id = await response.Content.ReadAsAsync<Int32>(); return id; }
public Int32 AddSuperhero(String name, IEnumerable<Skill> skills, IEnumerable<Team> teams, Boolean isOnMission) { var superhero = new Superhero { Id = idCounter, Name = name, Skills = skills?.ToList(), Teams = teams?.ToList(), IsOnMission = isOnMission }; this.superheroes.Add(superhero); idCounter++; return idCounter; }
private void InitializeCommands() { addSuperheroCommand = new ActionCommand(async () => { var superhero = new Superhero { Name = $"[Hero {Superheroes?.Count + 1}]" }; await this.repository.CreateSuperheroAsync(superhero); await RefreshViewModelAsync(); }); removeSuperheroCommand = new ActionCommand(async () => { await this.repository.RemoveSuperheroAsync(this.SelectedSuperhero); await RefreshViewModelAsync(); }); }
protected virtual void OnSelectionChanged(Superhero superhero) { SelectionChanged?.Invoke(superhero); }
public SuperheroViewModel(Superhero superhero) { this.superhero = superhero; }