コード例 #1
0
 public DataObjectOperationResult CommitChanges(CharacterFormModel postedData)
 {
     Mapper.CreateMap<CharacterFormModel, Character>();
     var character = new Character(Db);
     Mapper.Map<CharacterFormModel, Character>(postedData, character);
     var results = character.Save();
     postedData.Id = character.Id;
     return results;
 }
コード例 #2
0
        public CharacterFormModel GenerateForm()
        {
            var vModel = new CharacterFormModel()
                             {
                                 Authors = new List<IAuthor>(),
                                 Books = new List<IBook>()
                             };
            BuildFormDdLs(vModel);

            return vModel;
        }
コード例 #3
0
        public void BuildFormDdLs(CharacterFormModel vModel)
        {
            var authorChoices = Author.GetAll(Db).ToList().Except(vModel.Authors);

            vModel.AuthorAssoiationOptions = ListToSelectList.ConvertToSelectList(
                authorChoices, "Id", "LastName", true, "Select Author To Add");

            var bookChoices = Book.GetAll(Db).ToList().Except(vModel.Books);

            vModel.BookAssoiationOptions = ListToSelectList.ConvertToSelectList(
                bookChoices, "Id", "Title", true, "Select Book To Add");
        }
コード例 #4
0
        public ActionResult AddUpatde(CharacterFormModel postedData)
        {
            bool isNew = postedData.Id == null;
            var results = CWorker.CommitChanges(postedData);
            if (results.Success)
            {
                if (isNew)
                {
                    return RedirectToAction("Edit", new {cId = postedData.Id});
                }
                return View("InputSuccess", results);
            }

            postedData.PopupTitle = "Edit Character - ERROR";
            results.PassErrorsToMvcModelState(ModelState);
            return View("Form", postedData);
        }