public ActionResult Index(int?size, int?page, string searchString) { ViewBag.CurrentFilter = searchString; var roleStaff = RoleManager.Roles.FirstOrDefault(x => x.Name == "Staff"); var lstUserId = _repoUser.FindAll(x => x.RoleId == roleStaff.Id).Select(x => x.UserId).ToList(); var lstUser = UserManager.Users.Where(x => lstUserId.Any(p => p.Contains(x.Id))).ToList(); var roleStudent = RoleManager.Roles.FirstOrDefault(x => x.Name == "Student"); //total staff ViewBag.CountStaff = lstUserId.Count(); //total student ViewBag.CountStudent = _repoUser.FindAll(x => x.RoleId == roleStudent.Id).Count(); //total competition ViewBag.CountCompetition = _repoCompetition.Count(); //total post ViewBag.CountPost = _repoPost.Count(); ViewBag.stt = 1; ViewBag.currentSize = size; // tạo biến kích thước trang hiện tại ViewBag.total = lstUser.Count; page = page ?? 1; int pageSize = (size ?? 8); int pageNumber = (page ?? 1); return(View(lstUser.ToPagedList(pageNumber, pageSize))); }
public void RepositoryCascadeDelete_BlogPosts_Null() { var blog = BlogObjectMother .aDefaultBlogWithPost() .ToRepository(); BlogRepository.Insert(blog); db.SaveChanges(); var insertResult = BlogRepository.GetFirstOrDefault(predicate: x => x.Title == BlogObjectMother.aDefaultBlogWithPost().Title, include: i => i.Include(x => x.Posts)); Assert.That(insertResult.Title, Is.EqualTo(BlogObjectMother.aDefaultBlogWithPost().Title)); Assert.That(insertResult.Posts, Is.Not.Null); var postCount = PostRepository.Count(); Assert.That(postCount, Is.GreaterThan(0)); BlogRepository.Delete(blog); db.SaveChanges(); var deleteResult = BlogRepository.Find(blog.Id); var postResult = PostRepository.Find(blog.Posts.FirstOrDefault().Id); Assert.That(deleteResult, Is.Null); //Only the parent was marked for deletion not the child //As the delete operation is set to soft Delete by default Assert.That(postResult, Is.Null); }
public void Modify_Post() { InitializeInMemoryDbContext(options => { using (var uowManager = new EfCoreUnitOfWorkManager()) { var repository = new PostRepository(new BloggingDbContext(options)); repository.Count().ShouldBe(2); var uow = new EfCoreUnitOfWork( ((IRepositoryWithDbContext)repository).GetDbContext() ); uowManager.Register(uow); var post = repository.All().First(); post.ShouldNotBeNull(); var postId = post.Id; post.Title = "已修改"; repository.Modify(post); uowManager.Commit(); repository.Single(s => s.Id.Equals(postId)) .Title .ShouldBe("已修改"); } }); }
public void Count_Starts_At_Zero() { var db = new PostContext(); var underTest = new PostRepository(db); var count = underTest.Count(); Assert.Equal(0, count); }
public void AddPageData(string pageName, PageData pageData) { if (PostRepository.Count(e => e.Name == pageData.Name && e.Page.Name == pageName) > 0) { throw new UserFriendlyException("文章名称已重复"); } var page = PageRepository.GetAll().OfType <ContentPage>().FirstOrDefault(e => e.Name == pageName); if (page == null) { throw new UserFriendlyException("找不到要添加的文章页面"); } pageData.Page = page; PostRepository.Insert(pageData); }
/// <summary> /// 得到统计信息 /// </summary> /// <returns></returns> public IDictionary <string, string> GetRefstatInfo() { double totalDayCount = (DateTime.Now - Convert.ToDateTime("2009-01-01")).Days; int todayVisitorCount = _logRepository.SiteVisitCountOnToday(); int totalVisitorCount = _logRepository.SiteVisitCount(); int PostCount = _postRepository.Count(); int commentCount = _commentRepository.Count(); int boardCount = _boardRepository.Count(); Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("今日访问量", todayVisitorCount.ToString()); data.Add("总访问人数", totalVisitorCount.ToString()); data.Add("文章总数", PostCount.ToString()); data.Add("评论总数", commentCount.ToString()); data.Add("留言总数", boardCount.ToString()); data.Add("平均日访问量", (totalVisitorCount / totalDayCount).ToString("#0.00")); data.Add("平均日新增文章数", (PostCount / totalDayCount).ToString("#0.00")); data.Add("平均日新增评论数", (commentCount / totalDayCount).ToString("#0.00")); data.Add("平均日新增留言数", (boardCount / totalDayCount).ToString("#0.00")); return(data); }
public void CountOfPostsIsThree() { var count = postRepository.Count(); Assert.Equal(3, count); }
public void Count_Starts_At_Zero() { var count = underTest.Count(); Assert.Equal(0, count); }
public static void InitializeInMemoryDbContext(Action <DbContextOptions <BloggingDbContext> > action) { UseInMemoryDbContext(options => { using (var uowManager = new EfCoreUnitOfWorkManager()) { var repository = new EfCoreRepositoryBase <BloggingDbContext, Blog>(new BloggingDbContext(options)); var uow = new EfCoreUnitOfWork( ((IRepositoryWithDbContext)repository).GetDbContext() ); uowManager.Register(uow); var blog = new Blog { Name = "R's blog", Url = "https://www.cnblogs.com/rajesh", CreationTime = DateTime.Now, Posts = new List <Post> { new Post { Title = "Libs 仓储设计", Summary = "", Content = "", Comments = new List <Comment> { new Comment { Content = "先马后看" }, new Comment { Content = "先马后看 +1" }, } }, new Post { Title = "Libs 工作单元设计", Summary = "", Content = "", Comments = new List <Comment> { new Comment { Content = "先马后看" }, new Comment { Content = "先马后看 +1" }, } } } }; var entity = repository.Create(blog); uowManager.Commit(); entity.Id.ShouldBeGreaterThan(0); var postRepository = new PostRepository(new BloggingDbContext(options)); postRepository.Count().ShouldBe(2); var commentRepository = new EfCoreRepositoryBase <BloggingDbContext, Comment>(new BloggingDbContext(options)); commentRepository.Count().ShouldBe(4); action(options); } }); }
public void Count_Starts_At_Four() { var count = underTest.Count(); Assert.Equal(3, count); }