Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
        private async Task LoadSuperheroes()
        {
            var superheroes = await _backendService.GetSuperheroes();

            Superheroes.Clear();

            foreach (var hero in superheroes)
            {
                Superheroes.Add(hero);
            }
        }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
0
        private void LoadSuperheroes()
        {
            _backendService.GetSuperheroes().Subscribe((superheroes) =>
            {
                Superheroes.Clear();

                foreach (var hero in superheroes)
                {
                    Superheroes.Add(hero);
                }
            });
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
 public ActionResult Create(Superheroes superheroes)
 {
     try
     {
         context.Superheroes.Add(superheroes);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
 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());
     }
 }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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());
            }
        }
Ejemplo n.º 13
0
        // GET: Superheroes/Create
        public ActionResult Create()
        {
            Superheroes superheroes = new Superheroes();

            return(View(superheroes));
        }
Ejemplo n.º 14
0
 public ActionResult Create([Bind(Include = "Name,alterEgo,superHeroAbility,secondSuperHeroAbility,catchphrase")] Superheroes superhero)
 {
     db.Superheroes.Add(superhero);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }