Exemplo n.º 1
0
        protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
        {
            string descriptor = bindingContext.ModelName;
            if (!String.IsNullOrEmpty(descriptor))
                descriptor = descriptor + ".";
            string availabilityContentDataType =
                GetValue(bindingContext, descriptor +"ContentDataType");
            ContentTypeEnums ContentDataType;
            if (availabilityContentDataType != null)
            {
                Enum.TryParse(availabilityContentDataType, out ContentDataType);
                IContentType model = null;
                UnicodeEncoding encoding = new UnicodeEncoding();
                switch (ContentDataType)
                {
                    case ContentTypeEnums.Text:
                        ContentTextVm tempModelText = new ContentTextVm();
                        tempModelText.ContentData = GetTextContent(bindingContext, descriptor);
                        model = tempModelText;
                        break;
                    case ContentTypeEnums.Image:
                        ContentImageVm tempModelImage = new ContentImageVm();
                        model = tempModelImage;
                        break;
                    default:
                        throw new NotImplementedException("Unknown content type: " + ContentDataType);
                }

                return model;
            }
            throw new NotImplementedException("Property ContentDataType not found");
        }
 public ActionResult CreateContentText()
 {
     IContentType TextContent = new ContentTextVm();
     return View("EditContent",TextContent);
 }
 PostContent GetPostContentText(ContentTextVm srcModel, PostContent dstModel)
 {
     PostContent result = Mapper.Map<ContentTextVm, PostContent>(srcModel, dstModel);
     UnicodeEncoding encoding = new UnicodeEncoding();
     result.ContentData = encoding.GetBytes(srcModel.ContentData);
     return result;
 }