public async Task GetSuperheroes() { IsLoading = true; try { var superheroesJson = await _customHttpClient.GetStringAsync("superhero"); var superheroes = JsonConvert.DeserializeObject <Superhero[]>(superheroesJson); Superheroes.Clear(); foreach (var hero in superheroes) { Superheroes.Add(hero); } } catch (HttpRequestException ex) when(ex.Message.Contains("304")) { // Intentionally left blank, 304 response is fine } finally { IsLoading = false; } }
public ActionResult Edit([Bind(Include = "Id,Name,AlterEgo,PrimarySuperheroAbility,SecondarySuperheroAbility,Catchphrase")] Superheroes hero) { if (ModelState.IsValid) { db.Entry(hero).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hero)); }
public ActionResult Create([Bind(Include = "Id,Name,AlterEgo,PrimarySuperheroAbility,SecondarySuperheroAbility,Catchphrase")] Superheroes superhero) { if (ModelState.IsValid) { db.Superheroes.Add(superhero); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(superhero)); }
private async Task LoadSuperheroes() { var superheroes = await _backendService.GetSuperheroes(); Superheroes.Clear(); foreach (var hero in superheroes) { Superheroes.Add(hero); } }
public ActionResult Edit([Bind(Include = "ID,Name,alterEgo,superHeroAbility,secondSuperHeroAbility,catchphrase")] Superheroes superhero) { var thisSuper = db.Superheroes.Where(s => s.ID == superhero.ID).FirstOrDefault(); thisSuper.Name = superhero.Name; thisSuper.alterEgo = superhero.alterEgo; thisSuper.superHeroAbility = superhero.superHeroAbility; thisSuper.secondSuperHeroAbility = superhero.secondSuperHeroAbility; thisSuper.catchphrase = superhero.catchphrase; db.SaveChanges(); return(RedirectToAction("Index")); }
private void LoadSuperheroes() { _backendService.GetSuperheroes().Subscribe((superheroes) => { Superheroes.Clear(); foreach (var hero in superheroes) { Superheroes.Add(hero); } }); }
public ActionResult Create([Bind(Include = "ID,Name,Alterego, PrimaryAbility, SecondaryAbility, Catchphrase")] Superheroes superheroes) { if (ModelState.IsValid) { db.Superheros.Add(superheroes); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Name = new SelectList(db.Superheros, "ID", "Name", superheroes.Name); return(View(superheroes)); }
public ActionResult Create(Superheroes superheroes) { try { context.Superheroes.Add(superheroes); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Superheroes hero = db.Superheroes.Find(id); if (hero == null) { return(HttpNotFound()); } return(View(hero)); }
public ActionResult Delete(int id, Superheroes superheroes) { try { // TODO: Add delete logic here var superheroToDelete = context.Superheroes.FirstOrDefault(s => s.superheroId == id); context.Superheroes.Remove(superheroToDelete); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public Superhero AddNewSuperhero(string name, string date, string city, string skill, string gender, string phone) { var superhero = new Superhero { fullName = name, birthDate = date, city = city, mainSkill = skill, gender = gender, phone = phone }; var request = new Superheroes(); var newSuperhero = request.AddSuperhero(superhero); return(newSuperhero); }
public ActionResult Edit(int id, Superheroes superheroes) { try { // TODO: Add update logic here var superheroToEdit = context.Superheroes.FirstOrDefault(s => s.superheroId == id); superheroToEdit.superheroName = Request.Form["superheroName"]; superheroToEdit.alterEgo = Request.Form["alterEgo"]; superheroToEdit.primaryAbility = Request.Form["primaryAbility"]; superheroToEdit.secondaryAbility = Request.Form["secondaryAbility"]; superheroToEdit.catchphrase = Request.Form["catchphrase"]; context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: Superheroes/Create public ActionResult Create() { Superheroes superheroes = new Superheroes(); return(View(superheroes)); }
public ActionResult Create([Bind(Include = "Name,alterEgo,superHeroAbility,secondSuperHeroAbility,catchphrase")] Superheroes superhero) { db.Superheroes.Add(superhero); db.SaveChanges(); return(RedirectToAction("Index")); }