Exemple #1
0
        // GET: CharClass/Edit/5
        public ActionResult Edit(int id)
        {
            var service = new CharClassServices();

            var detail = service.GetClassById(id);
            var model  = new CharClassEdit
            {
                ID                  = detail.ID,
                ClassName           = detail.ClassName,
                SpellCaster         = detail.SpellCaster,
                HitPointsFirstLevel = detail.HitPointsFirstLevel,
                Proficiencies       = detail.Proficiencies
            };

            return(View(model));
        }
Exemple #2
0
        public ActionResult Edit(CharClassEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new CharClassServices();

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

            ModelState.AddModelError("", "Class could not be edited.");
            return(View(model));
        }
Exemple #3
0
        public bool UpdateClass(CharClassEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .CharClasses
                    .Single(e => e.ID == model.ID);

                entity.ClassName           = model.ClassName;
                entity.SpellCaster         = model.SpellCaster;
                entity.HitPointsFirstLevel = model.HitPointsFirstLevel;
                entity.Proficiencies       = model.Proficiencies;

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