Beispiel #1
0
        public ActionResult Index(int page = 1)
        {
            int pageSize = 10;
            var writings = _workBL.GetWorks().Join(_userBL.GetUsers(),
                                                   w => w.UserId,
                                                   u => u.Id, (w, u) => new { Id = w.Id, Name = w.Title, DateOfPublication = w.DateOfPublication, Content = w.Content, IsDelete = u.IsDelete, Username = u.Login, GenreId = w.GenreId }).Join(_genreBL.GetGenres(),
                                                                                                                                                                                                                                              w => w.GenreId,
                                                                                                                                                                                                                                              g => g.Id, (w, g) => new UserWithWorkVM {
                Id = w.Id, Name = w.Name, DateOfPublication = w.DateOfPublication.Date, Content = w.Content, UserName = w.Username, GenreName = g.Name, IsDelete = w.IsDelete
            }).ToList();

            IEnumerable <UserWithWorkVM> writingsPerPages = writings
                                                            .Skip((page - 1) * pageSize).Take(pageSize);
            PageInfo pageInfo = new PageInfo
            {
                PageNumber = page,
                PageSize   = pageSize,
                TotalItems = writings.Count
            };
            WritingsVM wvm = new WritingsVM()
            {
                PageInfo = pageInfo,
                Writings = writingsPerPages
            };

            return(View(wvm));
        }
        public ActionResult GetWorks(string filter = null)
        {
            var workList = workBL.GetWorks().Join(userBL.GetUsers(),
                                                  w => w.UserId,
                                                  u => u.Id, (w, u) => new { Id = w.Id, Name = w.Title, DateOfPublication = w.DateOfPublication, Content = w.Content, IsDelete = u.IsDelete, Username = u.Login, GenreId = w.GenreId }).Join(genreBL.GetGenres(),
                                                                                                                                                                                                                                             w => w.GenreId,
                                                                                                                                                                                                                                             g => g.Id, (w, g) => new UserWithWorkVM {
                Id = w.Id, Name = w.Name, DateOfPublication = w.DateOfPublication.Date, Content = w.Content, UserName = w.Username, GenreName = g.Name, IsDelete = w.IsDelete
            }).ToList();

            foreach (var item in workList)
            {
                if (item.IsDelete == true)
                {
                    item.UserName = "******";
                }
            }


            ViewBag.WorksList = filter == null ? workList : workList.Where(x => x.Name.Contains(filter) || x.GenreName.Contains(filter) || x.UserName.Contains(filter));

            return(View("_WorksTable", filter == null ? AutoMapperBL <IEnumerable <WorkBL>, List <WorkVM> > .Map(workBL.GetWorks()) : AutoMapperBL <IEnumerable <WorkBL>, List <WorkVM> > .Map(workBL.GetWorks().Where(x => x.Title.Contains(filter)).ToList())));
        }
        public ActionResult PersonalProfile()
        {
            HttpCookie cookieReq = Request.Cookies["Localhost cookie"];

            int ids = 0;

            if (cookieReq != null)
            {
                ids = Convert.ToInt32(cookieReq["ids"]);
            }

            var item = AutoMapperBL <UserBL, UserVM> .Map(_userBL.GetUser, ids);

            ViewBag.UserWorksList = _workBL.GetWorks().Where(x => x.UserId == ids).ToList();
            return(View(item));
        }