public async Task <bool> addMovie(AddMovieDTO movie)
        {
            Movies Movie = _mapper.Map <Movies>(movie);

            _db.Movies.Add(Movie);
            return(await _db.SaveChangesAsync() > 0);
        }
Example #2
0
 public static async Task <Movie> AddMovieDTOToMovie(AddMovieDTO addMovieDTO)
 {
     return(new Movie()
     {
         Title = addMovieDTO.Title.Trim(),
         Description = addMovieDTO.Description.Trim(),
         Genre = addMovieDTO.Genre,
         Cover = await FileToByteArray.ImageToByteArray(addMovieDTO.Cover)
     });
 }
Example #3
0
        public async Task <DataRespone <string> > Add(AddMovieDTO movie)
        {
            bool result = await _movieService.addMovie(movie);

            if (result)
            {
                return new DataRespone <string>()
                       {
                           Ok = true, data = "The movie was added.", error = ""
                       }
            }
            ;
            return(new DataRespone <string>()
            {
                Ok = false, data = "Something went wrong", error = "The movie was not added."
            });
        }
    }
        public async Task <IActionResult> Add(AddMovieDTO addMovieDTO)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _movieService.AddMovieAsync(addMovieDTO);

                    return(RedirectToAction("Add"));
                }

                return(View(addMovieDTO));
            }
            catch (FlowException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);

                return(View(addMovieDTO));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Example #5
0
        public async Task <IActionResult> AddMovie([Bind("Title,ReleaseDate,Genre,Length")] AddMovieDTO dto)
        {
            var movies = await _context.Movies.SingleOrDefaultAsync(u => u.Title == dto.Title);

            if (movies != null)
            {
                ModelState.AddModelError("", "This movie already exists.");
                dto.Title = "";
                return(View());
            }

            var movie = new Movies
            {
                Title       = dto.Title,
                ReleaseDate = dto.ReleaseDate,
                Genre       = dto.Genre,
                Length      = int.Parse(dto.Length)
            };

            _context.Add(movie);
            await _context.SaveChangesAsync();

            return(View("MovieProfile", movie));
        }