コード例 #1
0
        public ActionResult Edit(AdministrationEditViewModel model, string id)
        {
            var character = m_session.Characters.GetByName(id);

            if (character == null)
                return RedirectToAction("Index");

            // reset the character
            model.Character = character;

            if (!ModelState.IsValid)
                return View(model);

            try
            {
                // set the new character level
                character.Level = model.Level;

                // save changes to the database
                if (m_session.SaveChanges())
                {
                    return RedirectToAction("Index");
                }
            }
            catch (DbEntityValidationException ex)
            {
                ControllerUtilities.MergeValidationErrors(ModelState, ex);
            }

            return View(model);
        }
コード例 #2
0
        public ActionResult Edit(string id)
        {
            var character = m_session.Characters.GetByName(id);

            if (character == null)
                return RedirectToAction("Index");

            var model = new AdministrationEditViewModel
            {
                Character = character,
                Level = character.Level
            };

            return View(model);
        }
コード例 #3
0
        public ActionResult Edit(AdministrationEditViewModel model, string id)
        {
            var character = m_session.Characters.GetByName(id);

            if (character == null)
                return RedirectToAction("Index");

            // reset the character
            model.Character = character;

            if (!ModelState.IsValid)
                return View(model);

            try
            {
                // set the new character level
                character.Level = model.Level;

                // validate updates made to a character
                m_session.Characters.Update(character);

                // save changes to the database
                m_session.SaveChanges();

                return RedirectToAction("Index");
            }
            catch (ValidationException ex)
            {
                foreach (var error in ex.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }
            }

            return View(model);
        }