Esempio n. 1
0
        // GET: CharRace/Edit/5
        public ActionResult Edit(int id)
        {
            var service = new CharRaceServices();

            var detail = service.GetRaceById(id);
            var model  = new CharRaceEdit
            {
                RaceName          = detail.RaceName,
                Size              = detail.Size,
                Speed             = detail.Speed,
                SpecialAttributes = detail.SpecialAttributes,
                Languages         = detail.Languages,
            };

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Edit(CharRaceEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new CharRaceServices();

            if (service.UpdateRaces(model))
            {
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Race could not be edited.");
            return(View(model));
        }
Esempio n. 3
0
        public bool UpdateRaces(CharRaceEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .CharRaces
                    .Single(e => e.ID == model.ID);

                entity.RaceName          = model.RaceName;
                entity.Size              = model.Size;
                entity.Speed             = model.Speed;
                entity.SpecialAttributes = model.SpecialAttributes;
                entity.Languages         = model.Languages;


                return(ctx.SaveChanges() == 1);
            }
        }