Exemple #1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var postModel = new PostViewModel
            {
                Post =
                    new PostEntity
                {
                    PostID             = int.Parse(bindingContext.GetValue("Post.PostID")),
                    PostTitle          = bindingContext.GetValue("Post.PostTitle"),
                    PostContent        = bindingContext.GetValue("Post.PostContent"),
                    PostUrl            = bindingContext.GetValue("Post.PostUrl"),
                    PostAddedDate      = DateTime.Parse(bindingContext.GetValue("Post.PostAddedDate")),
                    UserCanAddComments = bool.Parse(bindingContext.GetValue("Post.UserCanAddComments")),
                    CanBeShared        = bool.Parse(bindingContext.GetValue("Post.CanBeShared")),
                    IsPrivate          = bool.Parse(bindingContext.GetValue("Post.IsPrivate")),
                    EntryType          = byte.Parse(bindingContext.GetValue("Post.EntryType")),
                    BitlyUrl           = bindingContext.GetValue("Post.BitlyUrl"),
                    BitlySourceUrl     = bindingContext.GetValue("Post.BitlySourceUrl"),
                }
            };

            postModel.Post.Order = postModel.Post.EntryType == 2 ? (int?)GetOrder(bindingContext.GetValue("Post.Order")) : null;

            IModelBinder ckBinder = new CheckBoxListViewModelBinder();

            postModel.Categories = (CheckBoxListViewModel)ckBinder.BindModel(controllerContext, bindingContext);

            if (postModel.Post.EntryType == 1)
            {
                if (!postModel.Categories.Items.Any(c => c.IsChecked))
                {
                    var general = postModel.Categories.Items.SingleOrDefault(c => c.Value == "1");
                    if (general != null)
                    {
                        general.IsChecked = true;
                    }
                }

                postModel.Tags = bindingContext.GetValue("hdnAddedTags");
            }

            postModel.AjaxSaved = bool.Parse(bindingContext.GetValue("AjaxSaved"));

            return(postModel);
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var postModel = new PostViewModel
                                {
                                    Post =
                                        new PostEntity
                                            {
                                                PostID = int.Parse(bindingContext.GetValue("Post.PostID")),
                                                PostTitle = bindingContext.GetValue("Post.PostTitle"),
                                                PostContent = bindingContext.GetValue("Post.PostContent"),
                                                PostUrl = bindingContext.GetValue("Post.PostUrl"),
                                                PostAddedDate = DateTime.Parse(bindingContext.GetValue("Post.PostAddedDate")),
                                                UserCanAddComments = bool.Parse(bindingContext.GetValue("Post.UserCanAddComments")),
                                                CanBeShared = bool.Parse(bindingContext.GetValue("Post.CanBeShared")),
                                                IsPrivate = bool.Parse(bindingContext.GetValue("Post.IsPrivate")),
                                                EntryType = byte.Parse(bindingContext.GetValue("Post.EntryType")),
                                                BitlyUrl = bindingContext.GetValue("Post.BitlyUrl"),
                                                BitlySourceUrl = bindingContext.GetValue("Post.BitlySourceUrl"),                                                
                                            }
                                };

            postModel.Post.Order = postModel.Post.EntryType == 2 ? (int?)GetOrder(bindingContext.GetValue("Post.Order")) : null;

            IModelBinder ckBinder = new CheckBoxListViewModelBinder();
            postModel.Categories = (CheckBoxListViewModel)ckBinder.BindModel(controllerContext, bindingContext);

            if (postModel.Post.EntryType == 1)
            {
                if (!postModel.Categories.Items.Any(c => c.IsChecked))
                {
                    var general = postModel.Categories.Items.SingleOrDefault(c => c.Value == "1");
                    if (general != null)
                    {
                        general.IsChecked = true;
                    }
                }

                postModel.Tags = bindingContext.GetValue("hdnAddedTags");
            }

            postModel.AjaxSaved = bool.Parse(bindingContext.GetValue("AjaxSaved"));

            return postModel;
        }