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");
        }
 PostContent GetPostContentImage(ContentImageVm srcModel, PostContent dstModel)
 {
     PostContent result = Mapper.Map<ContentImageVm, PostContent>(srcModel, dstModel);
     result.ContentData = srcModel.ContentData;
     return result;
 }
 public ActionResult CreateContentFile()
 {
     IContentType model = new ContentImageVm();
     return View("EditContent", model);
 }
        public void LoadFile(HttpPostedFileBase file, string comment)
        {
            IList<IContentType> Contents = Session["PostContents"] as IList<IContentType>;
            if (Contents == null)
            {
                Contents = new List<IContentType>();
            }
            string arViewResults = "";
              //  foreach (var i in files)
               // {
                IContentType newContent = null;
                switch (file.ContentType)
                {
                    case "image/jpeg":
                        ContentImageVm newContentImage = new ContentImageVm();
                        newContentImage.ContentDataType = ContentTypeEnums.Image;
                        MemoryStream s = new MemoryStream();
                        file.InputStream.CopyTo(s);
                        newContentImage.ContentData = s.ToArray();
                        newContent = newContentImage;
                        break;
                    case "video":
                        break;
                    default:
                        throw new NotImplementedException("Неизвестный тип файла");
                }
                var ids = from c in Contents
                          select c.PostContentId;

                int next_id = ids.Count() == 0 ? -1 : ids.Min() - 1;
                newContent.PostContentId = next_id;
                newContent.Comment = comment;
                Contents.Add(newContent);
                arViewResults = arViewResults + this.RenderPartialViewToString("AttachedContent", newContent); // View("AttachedContent", newContent);
            //}
            Session["PostContents"] = Contents;

            string json_object = JsonConvert. SerializeObject(arViewResults,Formatting.Indented);
            HttpContext.Response.Write(arViewResults);
        }