Пример #1
0
        public int CreateOrUpdatePost(PostModel model)
        {
            Post dbPost;
            if (model.PostId.HasValue)
            {
                dbPost = BlogDb.Posts.Single(a => a.PostId == model.PostId.Value);
            }
            else
            {
                dbPost = new Post
                {
                    PermalinkGuid = model.Identifier,
                    CreatedOn = DateTime.UtcNow,
                    CreatedBy = System.Threading.Thread.CurrentPrincipal.Identity.Name
                };
                BlogDb.Posts.InsertOnSubmit(dbPost);
            }

            dbPost.BlogId = model.BlogId;
            dbPost.Body = model.Body;
            dbPost.Title = model.Title;
            dbPost.PublishDate = model.PublishDate;
            dbPost.IsDraft = model.IsDraft;

            var urlTitle = model.UrlTitle;
            if (urlTitle.IsBlank())
            {
                urlTitle = Regex.Replace(model.Title, @"[^A-Za-z0-9_\.~]+", "-");
            }
            if (urlTitle.IsNotBlank())
            {
                urlTitle = urlTitle.Truncate(100);
            }
            dbPost.UrlTitle = urlTitle;

            BlogDb.SubmitChanges();

            model.PostId = dbPost.PostId;

            return dbPost.PostId;
        }
Пример #2
0
 public void DodajPost(PostModel post)
 {
     throw new NotImplementedException();
 }