示例#1
0
        public virtual void SetUp()
        {
            blog = new BlogEntity();

            Under_These_Conditions();
            When();
        }
        public override void Under_These_Conditions()
        {
            repository = IoC.Resolve<IBlogRepository>();
            var blog = new BlogEntity {Host = "localhost"};

            Repository<BlogEntity>.SaveOrUpdate(blog);

            UnitOfWork.Current.Flush();
        }
示例#3
0
        public Blog GetBlog(long id)
        {
            BlogEntity _blog = _blogRepository.Get(b => id == b.Id);

            if (_blog == null)
            {
                throw new NoSuchBlogException();
            }
            return(_mapper.Map <Blog>(_blog));
        }
        /// <summary>
        /// 根据ID获取博客信息
        /// </summary>
        /// <param name="sBlogID"></param>
        /// <returns></returns>
        public IActionResult Detail(string sBlogID)
        {
            BlogEntity m = null;

            if (!string.IsNullOrEmpty(sBlogID))
            {
                m = blogDAL.GetBlogByID(sBlogID);
            }
            return(View(m));
        }
示例#5
0
        public BlogDTO GetBlog(int id)
        {
            if (id < 0)
            {
                return(null);
            }
            BlogEntity blogEntity = blogRepository.Get(id);
            BlogDTO    blogDTO    = MapDataDTO(blogEntity);

            return(blogDTO);
        }
示例#6
0
        public bool UpdateBlog(BlogDTO blogDTO)
        {
            if (blogDTO == null || blogDTO.BlogId < 0)
            {
                return(false);
            }
            BlogEntity blogEntity       = MapDataEntity(blogDTO);
            bool       updateSuccessful = blogRepository.Update(blogEntity);

            return(updateSuccessful);
        }
示例#7
0
        public bool AddBlog(BlogDTO blogDTO)
        {
            if (blogDTO == null)
            {
                return(false);
            }
            blogDTO.CreatedDate = DateTime.Now;
            BlogEntity blogEntity    = MapDataEntity(blogDTO);
            bool       addSuccessful = blogRepository.Add(blogEntity);

            return(addSuccessful);
        }
示例#8
0
        public async Task <string> Create(BlogEntity blog)
        {
            //Genrate SLug
            blog.Slug = SlugHelper.GenerateSlug(blog.Title);

            // blog.Content = add for alll image-> style="height:400px;width:auto;";
            var config = new MapperConfiguration(cfg => cfg.CreateMap <BlogModel, BlogEntity>().ReverseMap());
            var model  = _mapper.Map <BlogModel>(blog);

            model.Updated = DateTime.Now;
            return(await _blogRepository.InsertAsync(model));
        }
示例#9
0
        public static Blog ToBlog(this BlogEntity blogEntity)
        {
            Blog blogItem = new Blog
            {
                Author = blogEntity.Author,
                Id     = blogEntity.Id,
                Name   = blogEntity.Name,
                Posts  = blogEntity.Posts.ToPosts()
            };

            return(blogItem);
        }
示例#10
0
        public async Task <bool> Insert(BlogEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity is null");
            }

            var str = JsonSerializer.Serialize(entity);

            _redisHelper.Set(GetMd5Key(entity), str);
            return(true);
        }
示例#11
0
        /// <summary>
        /// 更新博客信息
        /// </summary>
        public bool Update(BlogEntity blogEntity)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Blog set ");
            strSql.Append(" BlogContent=@BlogContent,ModifiedBy=@ModifiedBy, ModifiedTime=@ModifiedTime ");
            strSql.Append(" where BlogID=@BlogID ");
            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                int i = connection.Execute(strSql.ToString(), blogEntity);
                return(i > 0);
            }
        }
示例#12
0
        public static DALBlog ToDALEntity(this BlogEntity item)
        {
            if (ReferenceEquals(item, null))
            {
                return(null);
            }

            return(new DALBlog()
            {
                Id = item.Id,
                UserID = item.UserId
            });
        }
示例#13
0
        public async Task <BlogEntity> GetBlog(string blogname)
        {
            TableOperation retrieveOperation = TableOperation.Retrieve <BlogEntity>(blogname, "info");
            TableResult    result            = await blogsTable.ExecuteAsync(retrieveOperation);

            if (result.HttpStatusCode == 200)
            {
                BlogEntity entity = (BlogEntity)result.Result;
                return(entity);
            }

            return(null);
        }
 public ActionResult ChangeBlog(int id)
 {
     try
     {
         Repository <BlogEntity> blogRepository = new Repository <BlogEntity>();
         BlogEntity blogEntity = blogRepository.GetList().First(b => b.Id == id);
         ViewBag.Title = "Admin Change Blog " + blogEntity.Name;
         return(View(blogEntity));
     }
     catch (Exception ex)
     {
         return(ProcessException(ex));
     }
 }
示例#15
0
 public async Task Create(Blog blog)
 {
     await Task.Run(() => {
         BlogEntity newBlog = new BlogEntity()
         {
             Id     = Guid.NewGuid(),
             Title  = blog.Title.Content,
             Body   = blog.Body.Content,
             Author = blog.Author.Name,
             Type   = blog.Type.ToString(),
         };
         BlogRepository.Add(newBlog);
     });
 }
 public ActionResult BlogItem(string blogName)
 {
     try
     {
         Repository <BlogEntity> blogRepository = new Repository <BlogEntity>();
         BlogEntity blogEntity = blogRepository.GetList().First(b => b.Name == blogName);
         ViewBag.Title = "Admin blog " + blogName;
         return(View(blogEntity));
     }
     catch (Exception ex)
     {
         return(ProcessException(ex));
     }
 }
示例#17
0
        public async Task <IEnumerable <PopularUserViewModel> > GetPopularUsers(int limit)
        {
            List <UserEntity> users = (await _blogRepository.GetPopularUsers(limit)).ToList();

            List <PopularUserViewModel> popUsers = new List <PopularUserViewModel>();

            users.ForEach(u =>
            {
                BlogEntity blog = u.Blogs.OrderBy(b => b.PublishedOn)?.FirstOrDefault();
                popUsers.Add(new PopularUserViewModel {
                    User = Mapper.Map <UserEntity, User>(u), NumberOfPosts = u.Blogs.Count, PostId = blog?.PostId ?? 0, Title = blog?.Title ?? String.Empty
                });
            });
            return(popUsers);
        }
示例#18
0
 protected BlogCategoryEntity(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     if (SerializationHelper.Optimization != SerializationOptimization.Fast)
     {
         _blogPostCategory = (EntityCollection <BlogPostCategoryEntity>)info.GetValue("_blogPostCategory", typeof(EntityCollection <BlogPostCategoryEntity>));
         _blog             = (BlogEntity)info.GetValue("_blog", typeof(BlogEntity));
         if (_blog != null)
         {
             _blog.AfterSave += new EventHandler(OnEntityAfterSave);
         }
         this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance());
     }
     // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
     // __LLBLGENPRO_USER_CODE_REGION_END
 }
        public static async Task <TableResult> InsertOrMerge(string partitionKey, string rowkey, string content)
        {
            CloudTable learningtable = await TableStorage();

            BlogEntity entity = new BlogEntity(partitionKey, rowkey)
            {
                Content = content
            };

            // Create the TableOperation that inserts the customer entity.
            TableOperation insertOperation = TableOperation.InsertOrMerge(entity);

            // Execute the insert operation.
            return(await learningtable.ExecuteAsync(insertOperation));
        }
 public IActionResult Add(BlogEntity blogEntity)
 {
     if (string.IsNullOrEmpty(this.User.Identity.Name))
     {
         return(Content("您尚未登录用户"));
     }
     if (string.IsNullOrEmpty(blogEntity.BlogID))
     {
         //新增
         blogEntity.BlogID      = Guid.NewGuid().ToString();
         blogEntity.CreatedTime = DateTime.Now;
         blogEntity.CreatedBy   = this.User.Claims.First().Value;
         blogDAL.Add(blogEntity);
     }
     return(Redirect("/Blog/Index"));
 }
        public IActionResult Update(BlogEntity blogEntity)
        {
            BlogEntity m = null;

            if (!string.IsNullOrEmpty(blogEntity.BlogID))
            {
                //修改
                m = blogDAL.GetBlogByID(blogEntity.BlogID);
                blogEntity.BlogTitle    = m.BlogTitle;
                blogEntity.BlogContent  = blogEntity.BlogContent;
                blogEntity.ModifiedTime = DateTime.Now;
                blogEntity.ModifiedBy   = this.User.Identity.Name;
                blogDAL.Update(blogEntity);
            }
            return(Redirect("/Blog/Index"));
        }
示例#22
0
        /// <summary>
        /// 根据ID获取博客信息
        /// </summary>
        public BlogEntity GetBlogByID(string sBlogID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from Blog ");
            strSql.Append(" where BlogID=@BlogID ");
            BlogEntity blog = null;

            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                var param = new DynamicParameters();
                param.Add("@BlogID", sBlogID, dbType: DbType.String);
                blog = connection.QuerySingleOrDefault <BlogEntity>(strSql.ToString(), param);
            }
            return(blog);
        }
示例#23
0
        public bool RemoveBlog(int id)
        {
            if (id < 0)
            {
                return(false);
            }
            BlogEntity blogEntity = blogRepository.Get(id);

            if (blogEntity == null)
            {
                return(false);
            }
            bool removeSuccessful = blogRepository.Remove(blogEntity);

            return(removeSuccessful);
        }
示例#24
0
        private string GetMd5Key(BlogEntity entity)
        {
            var md5Str = string.Empty;
            var str    = $"{entity.Auther}-{entity.Content}-{entity.Status}-{entity.Title}";

            using (var md5 = MD5.Create())
            {
                var           data    = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < data.Length; i++)
                {
                    builder.Append(data[i].ToString("X2"));
                }
                md5Str = builder.ToString();
            }
            return(md5Str);
        }
示例#25
0
        public BlogEntity GetBlogById(long Id)
        {
            BlogEntity Blog = new BlogEntity();

            Blog = db.tblBlogs.Where(x => x.BlogId == Id).Select(x => new BlogEntity()
            {
                TopicId     = x.TopicId,
                BlogName    = x.BlogName,
                BlogHeading = x.BlogHeading,
                CreatedBy   = x.CreatedBy,
                CreatedDate = x.CreatedDate,
                UpdatedBy   = x.UpdatedBy,
                UpdatedDate = x.UpdatedDate,
                IsActive    = x.IsActive
            }).FirstOrDefault();
            return(Blog);
        }
示例#26
0
        public BlogEntity MapDataEntity(BlogDTO blogDTO)
        {
            if (blogDTO == null)
            {
                return(null);
            }
            BlogEntity blogEntity = new BlogEntity()
            {
                BlogId      = blogDTO.BlogId,
                Title       = blogDTO.Title,
                Content     = blogDTO.Content,
                Author      = blogDTO.Author,
                CreatedDate = blogDTO.CreatedDate
            };

            return(blogEntity);
        }
示例#27
0
        public BlogDTO MapDataDTO(BlogEntity blogEntity)
        {
            if (blogEntity == null)
            {
                return(null);
            }
            BlogDTO blogDTO = new BlogDTO()
            {
                BlogId      = blogEntity.BlogId,
                Title       = blogEntity.Title,
                Content     = blogEntity.Content,
                Author      = blogEntity.Author,
                CreatedDate = blogEntity.CreatedDate
            };

            return(blogDTO);
        }
示例#28
0
 public ActionResult EditBlog(int id, BlogEntity Blog)
 {
     try
     {
         if (ModelState.IsValid)
         {
             BlogFactory       EditBlog = new BlogFactory();
             DataLayer.tblBlog NewBlog  = new DataLayer.tblBlog();
             ValidationFactory VF       = new ValidationFactory();
             string            Message  = VF.BlogValidity(Blog.BlogName, id);
             if (Message != "Success")
             {
                 ModelState.AddModelError("BlogName", Message);
                 GetTopic();
                 return(View(Blog));
             }
             else
             {
                 NewBlog.BlogId      = id;
                 NewBlog.TopicId     = Blog.TopicId;
                 NewBlog.BlogName    = Blog.BlogName;
                 NewBlog.BlogHeading = Blog.BlogHeading;
                 NewBlog.CreatedDate = Blog.CreatedDate;
                 NewBlog.CreatedBy   = null;
                 NewBlog.UpdatedDate = DateTime.Now;
                 NewBlog.UpdatedBy   = null;
                 NewBlog.IsActive    = Blog.IsActive;
                 EditBlog.SaveBlog(NewBlog);
                 return(RedirectToAction("Blog"));
             }
         }
         else
         {
             return(View(Blog));
         }
     }
     catch
     {
         return(View());
     }
     finally
     {
         GetTopic();
     }
 }
示例#29
0
        public long Create(BlogInputModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var blog = new BlogEntity
            {
                Title   = model.Title,
                Content = model.Content,
                Created = DateTime.Now
            };

            _dbContext.Blogs.Add(blog);
            _dbContext.SaveChanges();
            return(blog.Id);
        }
示例#30
0
 // GET: Blog/Edit/5
 public ActionResult EditBlog(long id)
 {
     try
     {
         BlogFactory EditBlog = new BlogFactory();
         BlogEntity  Blog     = new BlogEntity();
         Blog = EditBlog.GetBlogById(id);
         return(View(Blog));
     }
     catch
     {
         return(View());
     }
     finally
     {
         GetTopic();
     }
 }
示例#31
0
 public ActionResult CreateBlog(BlogEntity Blog)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ValidationFactory    VF         = new ValidationFactory();
             BlogFactory          AddBlog    = new BlogFactory();
             DataLayer.tblBlog    NewBlog    = new DataLayer.tblBlog();
             DataLayer.tblChannel NewChannel = new DataLayer.tblChannel();
             string Message = VF.BlogValidity(Blog.BlogName, null);
             if (Message != "Success")
             {
                 ModelState.AddModelError("BlogName", Message);
                 GetTopic();
                 return(View(Blog));
             }
             else
             {
                 NewBlog.BlogName    = Blog.BlogName;
                 NewBlog.BlogHeading = Blog.BlogHeading;
                 NewBlog.TopicId     = Blog.TopicId;
                 NewBlog.CreatedDate = DateTime.Now;
                 NewBlog.CreatedBy   = null;
                 NewBlog.UpdatedDate = null;
                 NewBlog.UpdatedBy   = null;
                 NewBlog.IsActive    = true;
                 AddBlog.SaveBlog(NewBlog);
                 return(RedirectToAction("Blog"));
             }
         }
         else
         {
             GetTopic();
             return(View(Blog));
         }
     }
     catch (Exception Ex)
     {
         GetTopic();
         return(View());
     }
     finally { GetTopic(); }
 }
示例#32
0
        public (JsonResult result, bool Succeeded) DeleteBlog(Guid id)
        {
            try
            {
                BlogEntity blog = _context.BlogEntitys.Find(id);
                if (blog == null)
                {
                    return(new JsonResult("Blog Not Found."), true);
                }

                blog.StatusID = false;
                _context.SaveChanges();
                return(new JsonResult("Blog Deleted Successfully."), true);
            }
            catch (Exception ex)
            {
                return(new JsonResult("Some server error occured"), false);
            }
        }
示例#33
0
        public override void Under_These_Conditions()
        {
            repository = IoC.Resolve<IPostRepository>();

            blog = new BlogEntity {Host = "localhost"};

            Repository<BlogEntity>.SaveOrUpdate(blog);

            UnitOfWork.Current.Flush();

            post = new PostEntity
                       {
                           Blog = blog,
                           DatePublished = DateTime.Today,
                           Title = "Test",
                           Text = "This is a test",
                           Slug = "This-is-a-clean-url"
                       };
        }
 public override void Under_These_Conditions()
 {
     testBlog = new BlogEntity() { Host = "localhost"};
     mockSession.Add("blog", testBlog);
     mockRequest.Expect(x => x.Url).Return(new Uri("http://localhost/")).Repeat.Any();
 }
 public override void When()
 {
     currentBlog = context.CurrentBlog;
 }
示例#36
0
 public CreateBlogModel()
 {
     Blog = new BlogEntity();
 }
示例#37
0
 public override void Under_These_Conditions()
 {
     repository = IoC.Resolve<IBlogRepository>();
     blog = new BlogEntity {Host = "localhost"};
     blog.Options.NumberOfPostsToShowOnHomePage = 5;
 }
示例#38
0
 public void Can_Create_Blog()
 {
     var blog = new BlogEntity();
     blog.ShouldNotBeNull();
 }
示例#39
0
 public void Can_Get_And_Set_Host()
 {
     var blog = new BlogEntity();
     blog.Host = "localhost";
     blog.Host.ShouldBe("localhost");
 }
示例#40
0
 public void Can_Get_Set_Options_NumberOfPostsToShowOnHomePage()
 {
     var blog = new BlogEntity();
     blog.Options.NumberOfPostsToShowOnHomePage = 2;
     blog.Options.NumberOfPostsToShowOnHomePage.ShouldBe(2);
 }
示例#41
0
 public void Creating_A_Blog_Creates_Options()
 {
     var blog = new BlogEntity();
     blog.Options.ShouldNotBeNull();
 }
示例#42
0
 public void Save(BlogEntity blog)
 {
     repository.SaveOrUpdate(blog);
 }
 public override void When()
 {
     fetchedBlog = repository.Fetch("localhost");
 }