public async Task <IActionResult> Movie(int cityId) { this.ViewData["ReturnUrl"] = "/BuyTicket/Movie/?cityId=" + cityId; //Този Url е за User-a Използва се при вписване и отписване string userId = ""; this.ViewBag.DefaultImage = defaultImage; const int pageSize = 3; int maxPages = 0; DayOfWeek day = DateTime.Now.DayOfWeek; if (this.User.Identity.IsAuthenticated) { userId = this.userManager.GetUserAsync(this.User).Result.Id; } this.ViewBag.CityName = await this.cityService.GetCityName(cityId); var projections = await projectionsService.GetByTownId(cityId, userId); projections = projections.OrderBy(p => p.Movie.Name); maxPages = (int)Math.Ceiling(projections.Count() / (decimal)pageSize); var projectionsModel = new ProjectionListViewModel(1, maxPages, "title_desc", "hour", "title", cityId, userId, day, projections.Take(pageSize).Select(p => new ProjectionViewModel(p, defaultImage))); return(View(projectionsModel)); }
public async Task ThrowInvalidClientInputException_WhenModelStateIsNotValid() { //Act var viewModel = new ProjectionListViewModel(); controller.ModelState.AddModelError("error", "error"); //Assert await Assert.ThrowsExceptionAsync <InvalidClientInputException>(async() => await controller.UpdateMovie(viewModel)); }
public async Task <IActionResult> UpdateMovie(ProjectionListViewModel model) { if (!this.ModelState.IsValid) { throw new InvalidClientInputException("Something went wrong when received UpdateMovie parameters"); } this.ViewBag.DefaultImage = defaultImage; if (!this.User.Identity.IsAuthenticated) { model.UserId = ""; } const int pageSize = 3; var projections = await projectionsService.GetByTownId(model.CityId, model.UserId, model.Day); model.TitleSort = model.SortOrder == "title" ? "title_desc" : "title"; //Тук нагласяме какво да се подаде от view-то следващия път като кликнем на сорт-линка //Винаги когато подадем нещо друго, различно от title следващото сортиране по име ще е в нарастващ ред model.HourSort = model.SortOrder == "hour" ? "hour_desc" : "hour"; //Винаги когато подадем нещо друго, различно от hour следващото сортиране по час ще е в нарастващ ред int cityId = model.CityId; int currentPage = model.CurrentPage ?? 1; int maxPages = (int)Math.Ceiling(projections.Count() / (decimal)pageSize); switch (model.SortOrder) { case "title_desc": projections = projections.OrderByDescending(p => p.Movie.Name); break; case "hour": projections = projections.OrderBy(p => p.OpenHour.Hours + p.OpenHour.Minutes / 60.0); break; case "hour_desc": projections = projections.OrderByDescending(p => p.OpenHour.Hours + p.OpenHour.Minutes / 60.0); break; default: projections = projections.OrderBy(p => p.Movie.Name); break; } projections = projections.Skip((currentPage - 1) * pageSize).Take(pageSize); var projectionsModel = new ProjectionListViewModel(currentPage, maxPages, model.TitleSort, model.HourSort, model.SortOrder, cityId, model.UserId, model.Day, projections.Select(p => new ProjectionViewModel(p, defaultImage))); return(PartialView("../BuyTicket/_ProjectionsPartial", projectionsModel)); }