Ejemplo n.º 1
0
        public ActionResult Index(ProfileModel model)
        {
            string          userId = User.Identity.GetUserId();
            CinemaStoreUser user   = UserManager.FindById(userId);

            if (user == null)
            {
                AuthManager.SignOut();
            }
            else
            {
                model = new ProfileModel {
                    Email = user.Email
                };
            }

            model.Films = filmSrv.GetFilms(model, x => x.UserId == userId);

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetFilmsAjaxAsync()
        {
            var draw = HttpContext.Request.Form["draw"].FirstOrDefault();
            // Skiping number of Rows count
            var start = Request.Form["start"].FirstOrDefault();
            // Paging Length 10,20
            var length = Request.Form["length"].FirstOrDefault();
            // Sort Column Name
            var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();
            // Sort Column Direction ( asc, desc)
            var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();

            var searchValue = Request.Form["search[value]"].FirstOrDefault();

            //Paging Size (10,20,50,100)
            int pageSize = length != null?Convert.ToInt32(length) : 0;

            int skip = start != null?Convert.ToInt32(start) : 0;

            int recordsTotal = 0;

            var films = await _film.GetFilms();

            var customerData = films.Select(x => new
            {
                id   = x.Id,
                name = x.Name,
                year = x.Year
            });

            if (!string.IsNullOrEmpty(searchValue))
            {
                customerData = customerData.Where(x => x.name.ToLower().Contains(searchValue.ToLower()));
            }

            // сортивка по столбцу(sortColumn) и порядок сортировки (sortColumnDirection)
            if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection)))
            {
                if (sortColumnDirection == "desc")
                {
                    switch (sortColumn)
                    {
                    case "":
                        customerData = customerData.OrderBy(x => x.name);
                        break;

                    case "Year":
                        customerData = customerData.OrderBy(x => x.year);
                        break;
                    }
                }
                else if (sortColumnDirection == "asc")
                {
                    switch (sortColumn)
                    {
                    case "":
                        customerData = customerData.OrderByDescending(x => x.name);
                        break;

                    case "Year":
                        customerData = customerData.OrderByDescending(x => x.year);
                        break;
                    }
                }
            }

            //total number of rows count
            recordsTotal = customerData.Count();
            //Paging
            var data = customerData.Skip(skip).Take(pageSize).ToList();

            //Returning Json Data
            return(new JsonResult(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }));
        }