示例#1
0
文件: PostEditModel.cs 项目: wdq/Blog
        public static Blog.Post PostEditPost(PostEditModel model)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Blog.Post databaseModel = database.Posts.FirstOrDefault(x => x.Id == model.Id);

            if (databaseModel != null)
            {
                databaseModel.Title           = model.Title;
                databaseModel.Body            = model.Body;
                databaseModel.Author          = new Guid("cebe8069-bd64-4dc9-8622-d3de189287b1"); // todo: get current user id
                databaseModel.Timestamp       = Convert.ToDateTime(model.Timestamp);
                databaseModel.CommentsEnabled = model.CommentsEnabled;
                databaseModel.Status          = model.Status;
                databaseModel.Visibility      = model.Visibility;
                databaseModel.FeaturedImage   = model.FeaturedImage;
                databaseModel.Slug            = model.Slug;
            }
            else
            {
                databaseModel = new Blog.Post();

                databaseModel.Id = Guid.NewGuid();

                databaseModel.Title           = model.Title;
                databaseModel.Body            = model.Body;
                databaseModel.Author          = new Guid("cebe8069-bd64-4dc9-8622-d3de189287b1"); // todo: get current user id
                databaseModel.Timestamp       = Convert.ToDateTime(model.Timestamp);
                databaseModel.CommentsEnabled = model.CommentsEnabled;
                databaseModel.Status          = model.Status;
                databaseModel.Visibility      = model.Visibility;
                databaseModel.FeaturedImage   = model.FeaturedImage;
                databaseModel.Slug            = model.Slug;

                database.Posts.InsertOnSubmit(databaseModel);
            }
            database.SubmitChanges();

            return(databaseModel);
        }