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;
 }
        public CharacterFormModel GenerateForm()
        {
            var vModel = new CharacterFormModel()
                             {
                                 Authors = new List<IAuthor>(),
                                 Books = new List<IBook>()
                             };
            BuildFormDdLs(vModel);

            return vModel;
        }
        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");
        }
        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);
        }