コード例 #1
0
        public async Task<ActionResult> Edit(ObjectId id, ContentSubmitVM contentVM,
            [Bind(Include = "Title,FullContent,ShortContent,CategoryID,PublishTimeUtc,IsPublished")]
            Post<ObjectId> content)
        {
            content.PublishTimeUtc = content.PublishTimeUtc.ToUniversalTime();
            content.FullContent = HttpUtility.HtmlDecode(content.FullContent);
            content.ShortContent = HttpUtility.HtmlDecode(content.ShortContent);
            content.ContentID = id;
            content.AuthorID = _currentUser.Id;
            content.AuthorName = _currentUser.UserName;
            
            List<string> userRoles = _userRoles.Select(p => p.ToString()).ToList();

            ContentEditVM<ObjectId> result = 
                await _postManager.Update(contentVM, content, (int)CategoryPermission.Edit, userRoles);
            return View(result);
        }
コード例 #2
0
        public async Task<ActionResult> Add(ContentSubmitVM contentVM,
            [Bind(Include = "Title,FullContent,ShortContent,CategoryID,PublishTimeUtc,IsPublished")]
            Post<ObjectId> content)
        {
            contentVM.ContentID = _contentEncryption.Decrypt(contentVM.ContentID);
            content.PublishTimeUtc = content.PublishTimeUtc.ToUniversalTime();
            content.FullContent = HttpUtility.HtmlDecode(content.FullContent);
            content.ShortContent = HttpUtility.HtmlDecode(content.ShortContent);
            content.ContentID = new ObjectId(contentVM.ContentID);
            content.AuthorID = _currentUser.Id;
            content.AuthorName = _currentUser.UserName;

            List<string> userRoles = _userRoles.Select(p => p.ToString()).ToList();

            ContentEditVM<ObjectId> result = await _postManager.Insert(
                contentVM, content, (int)CategoryPermission.Insert, userRoles);
                        
            if (string.IsNullOrEmpty(result.Error))
            {
                return RedirectToAction("Edit", null, new { id = content.ContentID } );
            }
            else
            {
                result.ContentID = _contentEncryption.Encrypt(contentVM.ContentID);
                return View("Edit", result);
            }
        }