示例#1
0
 public ActionResult Blog(BlogViewModel blog)
 {
     var domainModel = new BlogModel
     {
         BlogId = blog.BlogId ?? 0,
         Description = blog.Description,
         Name = blog.Name,
         UrlName = blog.UrlName
     };
     var blogId = BlogService.CreateOrUpdateBlog(domainModel);
     return RedirectToAction("Blogs");
 }
示例#2
0
        public int CreateOrUpdateBlog(BlogModel blog)
        {
            var dbBlog = BlogDb.Blogs.FirstOrDefault(a => a.BlogId == blog.BlogId);
            if (dbBlog == null)
            {
                dbBlog = new Data.Blog();
                BlogDb.Blogs.InsertOnSubmit(dbBlog);
            }

            dbBlog.DisplayName = blog.Name;
            dbBlog.UrlName = blog.UrlName;
            dbBlog.Description = blog.Description;

            BlogDb.SubmitChanges();

            blog.BlogId = dbBlog.BlogId;
            return blog.BlogId;
        }