예제 #1
0
        public ActionResult CreatePOST(WikiPage model){

            var wikiPage = _orchardServices.ContentManager.New("WikiPage");
            var wikiCreatePerm = new Permission
            {
                Name = "PublishOwn_WikiPage"
            };

            if (_orchardServices.WorkContext.CurrentUser == null ||
                !_authorizationService.TryCheckAccess(wikiCreatePerm, _orchardServices.WorkContext.CurrentUser, wikiPage))
            {
                return new HttpUnauthorizedResult();
            }

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var files = new List<string>();
            foreach (string fileName in Request.Files)
            {
                try
                {
                   Image image = Image.FromStream(Request.Files[fileName].InputStream);
                   Image thumb = ImageUtil.ResizeCropExcess(image, 100, 100);

                   var imageFileName = Request.Files[fileName].FileName;
                   var originalFile = _mediaService.UploadMediaFile("wiki", Request.Files[fileName].FileName, Image2Bytes(image, image.RawFormat), false);
                   var thumbFile = _mediaService.UploadMediaFile("wiki", "thumb_" + imageFileName, Image2Bytes(thumb, image.RawFormat), false);

                   files.Add(originalFile);
                   files.Add(thumbFile);
                }
                catch (ArgumentException e)
                {
                    _orchardServices.Notifier.Error(T("Uploading media file failed: {0} {1}", e.Message, e.StackTrace));
                    return View(model);
                }
            }
           
            var user = _orchardServices.ContentManager.Get(_orchardServices.WorkContext.CurrentUser.Id);
           
           
            wikiPage.As<WikiPagePart>().Creator = user.As<UserPart>().Record;
            wikiPage.As<WikiPagePart>().Rating = model.Rating;
            wikiPage.As<WikiPagePart>().RatingCount = 1;
            wikiPage.As<WikiPagePart>().FaceDetail = files.FirstOrDefault();
            wikiPage.As<WikiPagePart>().FaceSummary = files.Count > 1 ? files[1] : files.FirstOrDefault();

            wikiPage.As<TitlePart>().Title = model.Title;
            wikiPage.As<BodyPart>().Text = model.Description;
            wikiPage.As<CommonPart>().Container = wikiPage.As<WikiPagePart>().ContentItem;
            //wikiPage.As<AutoroutePart>().DisplayAlias = "test-wiki-page";

            _orchardServices.ContentManager.Create(wikiPage);
            
            
            // Has to use PublisherLater service class if you want to publish later
            //wikiPage.As<PublishLaterPart>().ScheduledPublishUtc = 


            var tagNames = TagHelpers.ParseCommaSeparatedTagNames(model.Tags);

            // as the tag names are used in the route directly, prevent them from having ASP.NET disallowed chars
            // c.f., http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx

            var disallowedTags = tagNames.Where(x => _disalowedChars.Intersect(x).Any()).ToList();

            if (disallowedTags.Any())
            {
                _notifier.Warning(T("The tags \"{0}\" could not be added because they contain forbidden chars: {1}", String.Join(", ", disallowedTags), String.Join(", ", _disalowedChars)));
                tagNames = tagNames.Where(x => !disallowedTags.Contains(x)).ToList();
            }


            _tagService.UpdateTagsForContentItem(wikiPage, tagNames);

            /*
            var attachment1 = new WikiPageAttachmentRecord
            {
                MimeType = "text/json",
                Src = "http://www.google.com/download.json",
                Title = "Google Stats",
                WikiPagePartRecord = wikiPage.As<WikiPagePart>().Record
            };
            
            var attachment2 = new WikiPageAttachmentRecord
            {
                MimeType = "text/json",
                Src = "http://www.google.com/download.json",
                Title = "Google Stats",
                WikiPagePartRecord = wikiPage.As<WikiPagePart>().Record
            };

            _repoWikiAttachment.Create(attachment1);
            _repoWikiAttachment.Create(attachment2);

            */
          
            return Redirect("~/" + wikiPage.As<AutoroutePart>().DisplayAlias);
        }
예제 #2
0
        public ActionResult Create()
        {
            var newWikiItem = _orchardServices.ContentManager.New("WikiPage");
            var wikiCreatePerm = new Permission
            {
                Name = "PublishOwn_WikiPage"
            };

            if(_orchardServices.WorkContext.CurrentUser == null || 
                !_authorizationService.TryCheckAccess(wikiCreatePerm, _orchardServices.WorkContext.CurrentUser, newWikiItem))
            {
                return new HttpUnauthorizedResult();
            }

            var model = new WikiPage();
            return View(model);
        }