示例#1
0
        public ActionResult Create(ContentPostModel model)
        {
            var content = model.ConvertToBaseModel() as BaseContent;

            ContentManager.CreateContent(content, content.ParentId);
            return(RedirectToAction("Index"));
        }
示例#2
0
        public static ContentPostModel ConvertModelToPost(this object input)
        {
            var model = new ContentPostModel();

            ConvertToIPost(input, model);
            return(model);
        }
示例#3
0
        public IActionResult Create(ContentPostModel model, IEnumerable <string> multi)
        {
            var content = model.ConvertToBaseModel();

            content.AddContent();
            return(RedirectToAction("Index", "Page", new { area = "Admin", id = content.Id }));
        }
示例#4
0
        public void UpdateContent(ContentPostModel input)
        {
            var content = Find(BaseIContentModelType, input.Id, out ISave db);

            if (content == null)
            {
                return;
            }
            input.ConvertToBaseModel(content);
            db.SaveChanges();
        }
示例#5
0
        public static void UpdateContent(ContentPostModel input)
        {
            var content = ContentCruds.GetByPK <BaseContent>(input.Id, out ISave db);

            if (content == null)
            {
                return;
            }
            input.ConvertToBaseModel(content);
            db.SaveChanges();
        }
示例#6
0
        public IActionResult Edit(ContentPostModel model, IEnumerable <string> multi)
        {
            if (model == null)
            {
                return(RedirectToAction("Index", "Page", new { area = "Admin", id = "" }));
            }
            var content = model.ConvertToBaseModel();

            content.UpdatePageContent();
            return(RedirectToAction("Index", "Page", new { area = "Admin", id = content.Id }));
        }
示例#7
0
        public IActionResult Index(string id = "")
        {
            ContentPostModel model = null;

            if (!string.IsNullOrEmpty(id))
            {
                var content = db.GetContent(id);
                if (content != null && users.IsUserInRoles(User, content.AdminReadRoles, true))
                {
                    model = content.ConvertToPassingModel();
                }
            }
            return(View(model));
        }
示例#8
0
        public IActionResult Timeline()
        {
            var contentModels = contents.GetAll();

            var contentResults = contentModels.Select(result => new ContentModel
            {
                Id          = result.Id,
                UploadDate  = result.UploadDate,
                Type        = contents.GetType(result.Id),
                Location    = contents.GetLocation(result.Id),
                Description = contents.GetDescription(result.Id),
                ImageUrl    = result.ImageUrl,
                UserId      = result.UserId
            }).ToList();

            var model = new ContentPostModel()
            {
                Contents = contentResults
            };

            return(View(model));
        }
示例#9
0
        public IActionResult Index()
        {
            IEnumerable <Data.Models.Content> contentModels = contents.GetAll();

            List <ContentModel> contentResults = contentModels.Select(result => new ContentModel
            {
                Id          = result.Id,
                Description = result.Description,
                ImageUrl    = result.ImageUrl,
                Location    = result.Location,
                Tags        = result.Tags,
                Type        = result.Type,
                UploadDate  = result.UploadDate,
                UserId      = result.UserId
            }).ToList();

            ContentPostModel model = new ContentPostModel()
            {
                Contents = contentResults
            };

            return(View(model));
        }
示例#10
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> OnPostAsync(int id, ContentPostModel model, IFormCollection formCollection)
        {
            try
            {
                var content = await _contentRepository.GetContent(id);

                var latestUnpublishedVersion = (await _contentVersionRepository.GetAll(id)).Where(w => w != null && w.Id > content.PublishedVersion).OrderByDescending(w => w.Id).FirstOrDefault();
                var contentVersion           = await _contentVersionRepository.GetContent(model.SavedVersion);

                var currentVersion = await _contentVersionRepository.GetContent(model.SavedVersion);

                if (string.IsNullOrWhiteSpace(model.UrlSlug) && ParentId.HasValue)
                {
                    model.UrlSlug = Name.ReplaceDiacritics();
                }

                if (!string.IsNullOrWhiteSpace(model.UrlSlug))
                {
                    model.UrlSlug = model.UrlSlug.ReplaceDiacritics();
                }

                if (model.Id == model.ParentId)
                {
                    Id              = content.Id;
                    ParentId        = contentVersion?.ParentId ?? content.ParentId;
                    Name            = contentVersion?.Name ?? content.Name;
                    UrlSlug         = contentVersion?.UrlSlug ?? content.UrlSlug;
                    Properties      = _editorReflectionService.GetModelProperties((IContent)contentVersion ?? content, out var modelType, formCollection);
                    ContentTypeGuid = modelType.GetPageDataValues().Guid;
                    AllowedGroups   = contentVersion != null ? contentVersion.AllowedGroups : content.AllowedGroups;

                    ModelState.AddModelError(nameof(IContent.ParentId), $"{nameof(IContent.ParentId)} can't be set to the current content id");

                    TryValidateModel(model);
                    if (Request.IsAjaxRequest())
                    {
                        return(new JsonResult(new { Result = false }));
                    }

                    return(Page());
                }

                var createNewVersion = false;
                if (contentVersion == null)
                {
                    createNewVersion = true;
                    contentVersion   = _mapper.Map <ContentVersion>(content);
                }
                else
                {
                    if (content.PublishedVersion == contentVersion.Id)
                    {
                        createNewVersion = true;
                    }

                    if (latestUnpublishedVersion != null && latestUnpublishedVersion.Id > contentVersion.Id && latestUnpublishedVersion.Id > content.PublishedVersion)
                    {
                        contentVersion    = _mapper.Map <ContentVersion>(content);
                        contentVersion.Id = latestUnpublishedVersion.Id;
                        createNewVersion  = false;
                    }
                }

                contentVersion.Name          = model.Name;
                contentVersion.UrlSlug       = model.UrlSlug;
                contentVersion.ParentId      = model.ParentId;
                contentVersion.Order         = content.Order;
                contentVersion.AllowedGroups = model.AllowedGroups.IsNullOrEmpty() ? null : model.AllowedGroups.ToList();
                _editorReflectionService.AddPropertiesToModel(contentVersion, formCollection);

                if (string.IsNullOrEmpty(contentVersion.ContentTypeGuid))
                {
                    contentVersion.ContentTypeGuid = _typeMappings.GetContentType(model.ContentTypeGuid).GetPageDataValues().Guid;
                }

                var cv = _mapper.Map <ContentVersion>(contentVersion);
                cv.ContentId = content.Id;

                if (cv.CompareTo(currentVersion) == 0)
                {
                    try
                    {
                        ContentVersion version;
                        if (createNewVersion)
                        {
                            version = await _contentVersionRepository.Create(cv);
                        }
                        else
                        {
                            version = await _contentVersionRepository.Update(cv);
                        }

                        content.SavedVersion = version.Id;
                        await _contentRepository.Update(content);

                        currentVersion = version;
                    }
                    catch (Exception ex)
                    {
                        Id              = content.Id;
                        ParentId        = contentVersion?.ParentId ?? content.ParentId;
                        Name            = contentVersion?.Name ?? content.Name;
                        UrlSlug         = contentVersion?.UrlSlug ?? content.UrlSlug;
                        Properties      = _editorReflectionService.GetModelProperties((IContent)contentVersion ?? content, out var modelType, formCollection);
                        ContentTypeGuid = modelType.GetPageDataValues().Guid;
                        AllowedGroups   = contentVersion != null ? contentVersion.AllowedGroups : content.AllowedGroups;

                        ModelState.AddModelError("Error", ex.Message);
                        TryValidateModel(model);

                        if (Request.IsAjaxRequest())
                        {
                            return(new JsonResult(new { Result = false }));
                        }

                        return(Page());
                    }
                }

                if (Request.IsAjaxRequest())
                {
                    return(new JsonResult(new { Result = true, CurrentVersion = currentVersion }));
                }

                return(RedirectToPage("Edit", new { id = content.Id }));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#11
0
        public async Task <IActionResult> OnPostAsync(int id, ContentPostModel model, IFormCollection formCollection)
        {
            try
            {
                var content = new Content {
                    ContentTypeGuid = model.ContentTypeGuid
                };

                var modelType = _typeMappings.GetContentType(model.ContentTypeGuid);
                var pageType  = modelType.BaseType;
                var cModel    = EditorReflectionService.GetDefault(pageType);
                ((Content)cModel).ContentTypeGuid = model.ContentTypeGuid;
                content.ModelAsJson = JsonConvert.SerializeObject(cModel, Formatting.None, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All,
                    TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full
                });
                content.ContentTypeGuid = model.ContentTypeGuid;

                if (string.IsNullOrWhiteSpace(model.UrlSlug) && model.ParentId.HasValue)
                {
                    model.UrlSlug = model.Name.ReplaceDiacritics();
                }

                if (!string.IsNullOrWhiteSpace(model.UrlSlug))
                {
                    model.UrlSlug = model.UrlSlug.ReplaceDiacritics();
                }

                if (model.Id == model.ParentId)
                {
                    ParentId        = content.ParentId;
                    Name            = content.Name;
                    UrlSlug         = content.UrlSlug;
                    Properties      = _editorReflectionService.GetModelProperties(content, out var _, formCollection);
                    ContentTypeGuid = model.ContentTypeGuid;

                    ModelState.AddModelError(nameof(IContent.ParentId), $"{nameof(IContent.ParentId)} can't be set to the current content id");

                    TryValidateModel(model);
                    return(Page());
                }

                content.Name     = model.Name;
                content.UrlSlug  = model.UrlSlug;
                content.ParentId = model.ParentId;
                _editorReflectionService.AddPropertiesToModel(content, formCollection);

                try
                {
                    await _contentRepository.Create(content);

                    var cv = _mapper.Map <ContentVersion>(content);
                    cv.ContentId = content.Id;
                    var version = await _contentVersionRepository.Create(cv);

                    content.SavedVersion = version.Id;
                    await _contentRepository.Update(content);
                }
                catch (Exception ex)
                {
                    ParentId        = content.ParentId;
                    Name            = content.Name;
                    UrlSlug         = content.UrlSlug;
                    Properties      = _editorReflectionService.GetModelProperties(content, out var _, formCollection);
                    ContentTypeGuid = model.ContentTypeGuid;

                    ModelState.AddModelError("Error", ex.Message);
                    TryValidateModel(model);
                    return(Page());
                }

                return(RedirectToPage("Edit", new { id = content.Id }));
            }
            catch
            {
                throw;
            }
        }
示例#12
0
 public ActionResult Edit(ContentPostModel model)
 {
     ContentManager.UpdateContent(model);
     return(RedirectToAction("Index"));
 }