Exemplo n.º 1
0
        public async Task <IActionResult> Create(CinemaCreateViewModel model, CancellationToken token, string returnUrl = null)
        {
            AddBreadcrumb("Cinemas", "/Cinema/All");
            AddBreadcrumb("Create", "/Cinema/Create");
            ViewData["ReturnUrl"] = returnUrl;

            if (ModelState.IsValid)
            {
                var company = await GetCompany(token);

                var cinema = new Cinema
                {
                    Name    = model.Name,
                    Address = model.Address,
                    Phone   = model.Phone,
                    Company = company
                };

                await _cinemaRepository.AddAsync(cinema, token);

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

            return(View(model));
        }
Exemplo n.º 2
0
        public IActionResult CreateCinema(CinemaCreateViewModel model)
        {
            List <Room> newRooms = new();

            Cinema cinema = new();

            cinema.Name      = model.Name;
            cinema.TimeClose = model.TimeClose;
            cinema.Adress    = model.Adress;
            Room room = new();

            for (int i = 0; i < model.RoomCount; i++)
            {
                room.Name   = $"{i}:{cinema.Name}";
                room.Cinema = cinema;

                _sqlRoomService.CreateRoom(room);

                newRooms.Add(room);

                room = new();
            }

            cinema.Rooms = newRooms;

            _sqlCinemaService.CreateCinema(cinema);

            return(RedirectToAction(nameof(CreateCinema)));
        }
Exemplo n.º 3
0
        #pragma warning disable CS1998
        public async Task <IActionResult> Create()
        #pragma warning restore CS1998
        {
            var dto = new CinemaCreateViewModel();

            return(View(dto));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create(CancellationToken token)
        {
            AddBreadcrumb("Cinemas", "/Cinema/All");
            AddBreadcrumb("Create", "/Cinema/Create");

            var viewModel = new CinemaCreateViewModel();

            return(View(viewModel));
        }
Exemplo n.º 5
0
        public void CreateCinema_ShouldHaveModelCinemaCreateViewModel()
        {
            ViewResult result = _cinemaController.CreateCinema() as ViewResult;

            CinemaCreateViewModel model = result.Model as CinemaCreateViewModel;

            var str = result.ViewName;

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create(CinemaCreateViewModel dto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(dto));
                }

                var cinema = mapper.Map <Cinema>(dto);
                await cinemaService.CreateAsync(cinema);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(dto));
            }
        }