public SuperheroDto CreateOrUpdate(SuperheroDto superhero) { SuperheroDto result; ListItem superheroEntity; ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); if (!superhero.SuperheroId.HasValue) { superheroEntity = website.Lists.GetByTitle("Superheroes").AddItem(itemCreateInfo); } else { superheroEntity = website.Lists.GetByTitle("Superheroes").GetItemById(Convert.ToInt32(superhero.SuperheroId)); } superheroEntity["Title"] = superhero.superheroName; superheroEntity["description"] = superhero.description; superheroEntity["actor"] = superhero.actor; superheroEntity["superpower"] = superhero.superpower; superheroEntity["side"] = superhero.side; result = mapper.Map <SuperheroDto>(superheroEntity); return(result); }
public IHttpActionResult GetSuperhero(int id) { SuperheroDto result = superheroRepository.GetById(id); if (result == null) { return(NotFound()); } return(Ok(result)); }
public IHttpActionResult PostSuperhero(SuperheroDto superhero) { SuperheroDto result; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } result = superheroRepository.CreateOrUpdate(superhero); return(Ok(result)); }
public SuperheroDto GetById(int id) { SuperheroDto result = null; Superhero superheroEntity = dbContext.Superheroes.Find(id); if (superheroEntity != null) { result = mapper.Map <SuperheroDto>(superheroEntity); } return(result); }
public SuperheroDto GetById(int id) { SuperheroDto result = null; ListItem superheroEntity = website.Lists.GetByTitle("Superheroes").GetItemById(id); clientContext.Load(superheroEntity); clientContext.ExecuteQuery(); if (superheroEntity != null) { result = mapper.Map <SuperheroDto>(superheroEntity); } return(result); }
public string ExportSuperheroDetails(object superheroId) { var hero = this.db.Superheroes.GetById(superheroId); var dto = new SuperheroDto() { Name = hero.Name, City = hero.City.Name, Alignment = hero.Alignment.ToString(), Id = hero.Id, SecretIdentity = hero.SecretIdentity, Powers = hero.Powers.Select(p => p.Name).ToArray() }; var container = new SuperheroesCollection { Superheroes = new[] { dto } }; var result = Serialize(container, $"HeroWithId{(int)superheroId}-Export.xml"); return(result); }
public SuperheroDto CreateOrUpdate(SuperheroDto superhero) { SuperheroDto result; Superhero superheroEntity; if (!superhero.SuperheroId.HasValue) { superheroEntity = new Superhero(); dbContext.Superheroes.Add(superheroEntity); } else { superheroEntity = dbContext.Superheroes.Find(superhero.SuperheroId); } mapper.Map(superhero, superheroEntity); dbContext.SaveChanges(); result = mapper.Map <SuperheroDto>(superheroEntity); return(result); }