Пример #1
0
        public async Task EditMovieTheaterAsync(EditMovieTheaterModel editMovieTheaterModel)
        {
            var city = await Context.City.Where(a => a.Name == editMovieTheaterModel.CityName && a.State == editMovieTheaterModel.State).FirstOrDefaultAsync();

            if (city == null)
            {
                city = new City
                {
                    Name  = editMovieTheaterModel.CityName,
                    State = editMovieTheaterModel.State
                };
                await Context.City.AddAsync(city);

                await Context.SaveChangesAsync();
            }

            var movieTheater = await Context.MovieTheater.FindAsync(editMovieTheaterModel.Id);

            movieTheater.Name          = editMovieTheaterModel.Name;
            movieTheater.NumberAddress = editMovieTheaterModel.NumberAddress;
            movieTheater.StreetName    = editMovieTheaterModel.StreetName;
            movieTheater.ZipCode       = editMovieTheaterModel.ZipCode;
            movieTheater.City          = city.Id;
            await Context.SaveChangesAsync();
        }
Пример #2
0
        public async Task <ActionResult> Edit(EditMovieTheaterModel editMovieTheater)
        {
            var errorMessage = String.Empty;

            if (!editMovieTheater.ValidateEditModel(out errorMessage))
            {
                ModelState.AddModelError(string.Empty, errorMessage);
                return(View());
            }
            await MovieTheaterService.EditMovieTheaterAsync(editMovieTheater);

            return(RedirectToAction(nameof(Index)));
        }