コード例 #1
0
        public IActionResult FilmOverview(int id)
        {
            var viewModel = new FilmViewModel()
            {
                Film = _filmsService.GetFilmById(id)
            };

            return(View("Film", viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, FilmViewModel item)
        {
            if (id != item.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var filmDto = await _filmsService.GetFilmById(id);

                    if (!GetIsEditingAllowed(filmDto.CreatedByUserId))
                    {
                        return(NotFound());
                    }

                    var dto = _mapper.Map <FilmDto>(item);
                    dto.CreatedByUserId    = filmDto.CreatedByUserId;
                    dto.LastModifiedUserId = CommonHelper.GetUserId(User);
                    dto.IsEditingAllowed   = true;
                    dto.Directors          = await FilterDirectorsByIds(item.Directors);

                    dto.Poster = item.NewPoster?.Length > 0 ? CommonHelper.ConvertFileToBinary(item.NewPoster) : filmDto.Poster;

                    await _filmsService.InsertOrUpdateFilm(dto);
                }
                catch
                {
                    return(BadRequest());
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(await PrepareView(id)));
        }