public BlogPostAddViewModel Edit(BlogPostEditViewModel inModel) { var badRedirectResult = new BlogPostAddViewModel { ResultOverride = new RedirectResult(_resolver.PageNotFoundUrl()) }; var outModel = new BlogPostAddViewModel(); if (inModel.Slug.IsEmpty()) { return(badRedirectResult); } var post = _repository.Query(new PostBySlug(inModel.Slug)).SingleOrDefault(); if (post == null) { return(badRedirectResult); } outModel.Id = post.ID.ToString(); outModel.Title = post.Title; outModel.BodyShort = post.BodyShort; outModel.Body = post.Body; outModel.Slug = post.Slug; outModel.Published = post.Published; post.GetTags().Each(tag => outModel.Tags += tag.Name + ", "); return(outModel); }
public BlogPostViewModel Save(BlogPostAddViewModel inModel) { var post = new Post(); if (inModel.Id.IsNotEmpty()) { post = _repository.Load <Post>(new Guid(inModel.Id)); } post.Title = inModel.Title; post.BodyShort = inModel.BodyShort; post.Body = inModel.Body; post.Slug = inModel.Slug; // Looks like oxite is doing this in jQuery so don't need: post.Slug.IsEmpty() ? _slugService.CreateSlugFromText(inModel.Slug.IsEmpty() ? inModel.Title : inModel.Slug) : post.Slug; post.User = inModel.CurrentUser; post.Published = inModel.Published; if (inModel.Tags.IsNotEmpty()) { var tags = inModel.Tags.Split(','); tags.Each(tag => { if (tag.Trim().IsNotEmpty()) { post.AddTag(_tagService.CreateOrGetTagForItem(tag.ToLowerInvariant().Trim())); } }); } //Todo: Validation on input _repository.Save(post); return(new BlogPostViewModel()); }
public BlogPostAddViewModel Add(BlogPostAddViewModel inModel) { return(new BlogPostAddViewModel()); }