Exemplo n.º 1
0
        public async Task <IActionResult> CreateSecondStep(HallCreateViewModel model, CancellationToken token, string returnUrl = null)
        {
            AddBreadcrumb("Halls", "/Hall/All");
            AddBreadcrumb("Create", "/Hall/Create");

            model.ActiveTab = 2;
            if (ModelState.IsValid)
            {
                var array = JsonConvert.DeserializeObject <bool[, ]>(model.HallTableJson);

                var seats = array.Cast <bool>().Count(seat => seat);
                var hall  = new Hall
                {
                    Name          = model.Name,
                    Rows          = array.GetLength(0),
                    Columns       = array.GetLength(1),
                    Is3D          = model.Is3D,
                    IsImax        = model.IsIMAX,
                    Seats         = seats,
                    HallTableJson = model.HallTableJson,
                    Cinema        = await _cinemaRepository.FindByIdAsync(long.Parse(model.SelectedCinema), token)
                };

                await _hallRepository.AddAsync(hall, token);

                return(RedirectToAction(nameof(All), "Hall"));
            }

            return(View("Create", model));
        }
Exemplo n.º 2
0
        public IActionResult Create()
        {
            HallCreateViewModel model = new HallCreateViewModel {
                Halls = _hallService.GetActiveHalls()
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Delete(HallCreateViewModel model)
        {
            if (model.ID != null)
            {
                _hallService.DeleteHall(model.ID);
            }

            return(RedirectToAction(nameof(Create), "Hall"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateFirstStep(HallCreateViewModel model, CancellationToken token, string returnUrl = null)
        {
            AddBreadcrumb("Halls", "/Hall/All");
            AddBreadcrumb("Create", "/Hall/Create");

            model.ActiveTab = 1;
            if (ModelState.IsValid)
            {
                model.ActiveTab = 2;
                return(View("Create", model));
            }

            return(View("Create", model));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(CancellationToken token)
        {
            AddBreadcrumb("Halls", "/Hall/All");
            AddBreadcrumb("Create", "/Hall/Create");

            var cinemas = await GetCinemas(token);

            var viewModel = new HallCreateViewModel
            {
                Cinemas = cinemas
            };

            return(View(viewModel));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create(HallCreateViewModel model)
        {
            // Checks if string is empty and checks if RouteType is less or equal to the max value of the enum RouteType
            if (!string.IsNullOrEmpty(model.Name) &&
                ((int)model.Type <= Enum.GetValues(typeof(RouteType))
                 .Cast <RouteType>()
                 .Distinct()
                 .Count()))
            {
                _hallService.AddHall(model.Name, model.Type);
            }

            return(RedirectToAction(nameof(Create), "Hall"));
        }
Exemplo n.º 7
0
        public async Task Create_RouteTypeInvalidInput_RedirectToActionCreateHall()
        {
            // Arrange
            var            mockService = new Mock <IHallService>();
            HallController controller  = new HallController(mockService.Object);

            var hallListViewModel = new HallCreateViewModel {
                Name = "boulder", Type = (RouteType)4
            };

            // Act
            var result = await controller.Create(hallListViewModel);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Hall", redirectToActionResult.ControllerName);
            Assert.Equal("Create", redirectToActionResult.ActionName);
            mockService.Verify(service => service.AddHall(It.IsAny <string>(), It.IsAny <RouteType>()), Times.Never);
        }
Exemplo n.º 8
0
        public async Task Delete_InvalidNullAsId_RedirectToActionCreateHall()
        {
            // Arrange
            var            mockService = new Mock <IHallService>();
            HallController controller  = new HallController(mockService.Object);

            var hallCreateViewModel = new HallCreateViewModel {
                ID = null
            };

            // Act
            var result = await controller.Delete(hallCreateViewModel);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Hall", redirectToActionResult.ControllerName);
            Assert.Equal("Create", redirectToActionResult.ActionName);
            mockService.Verify(service => service.DeleteHall(It.IsAny <int?>()), Times.Never);
        }