public static void SeedGenres(IGenreRepository genrerepo) { using (FileStream fs = File.Open("DataInit\\genres.csv", FileMode.Open, FileAccess.Read, FileShare.None)) { var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(fs); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { "," }); //genrerepo.Clear(); genrerepo.SetIdentityInsert(true); bool first = true; while (!parser.EndOfData) { // 0: genreId, 1: genre string[] row = parser.ReadFields(); if (first) { first = false; continue; } var genre = new Genre { //GenreId = Int32.Parse(row[0]), Name = row[1] }; genrerepo.Create(genre); } genrerepo.SetIdentityInsert(false); } }
public async Task <IActionResult> Create([FromBody] GenreCreateDTO genreDTO) { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Started Create Genre"); if (genreDTO == null) { _logger.LogError($"{location}: Empty request"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { _logger.LogError($"{location}: Wrong model state"); return(BadRequest(ModelState)); } var genre = _mapper.Map <Genre>(genreDTO); var IsSuccess = await _genreRepository.Create(genre); if (!IsSuccess) { return(InternalError($"{location} : Creation failed")); } return(Created("Create", new { genre })); } catch (Exception ex) { return(InternalError($"{location} : Something wrong {ex.Message}")); } }
public ActionResult <Genre> PostGenre(Genre genre) { _genreRepository.Create(genre); _genreRepository.Save(); return(CreatedAtAction("GetPublisher", new { id = genre.Id }, genre)); }
public async Task CreateGenre(string name, string description) { Genre genre = new Genre { Title = name, Description = description }; await genreRepository.Create(genre); }
public ActionResult Create([Bind(Include = "Id,Type")] Genre genre) { if (ModelState.IsValid) { _genreRepository.Create(genre); return(RedirectToAction("Index")); } return(View(genre)); }
public int Create(CreateGenreRequest request) { var genreEntity = new GenreEntity() { Description = request.Description }; genreRepository.Create(genreEntity); return(genreEntity.Id); }
public async Task <GenreResponse> Create(GenreCreateRequest request) { if (await _genreRepository.IsGenreExists(request.Name)) { throw new GenreAlreadyExists("Genre already exists!"); } var genre = await _genreRepository.Create(_mapper.Map <Genre>(request)); return(_mapper.Map <GenreResponse>(genre)); }
public IActionResult Create(CategoryViewModel genre) { if (ModelState.IsValid) { var Genre = new Genre() { GenreName = genre.GenreName }; var newGenre = genreRepository.Create(Genre); return(RedirectToAction("Index")); } return(View()); }
public void CreateGenre(Genre newGenre) { if (Genres.FirstOrDefault(u => u.Name.Equals(newGenre.Name, StringComparison.CurrentCultureIgnoreCase)) == null) { _genreRepository.Create(newGenre); Genres.Add(newGenre); } else { MessageBox.Show("Такой жанр уже добавлен!", "Ошибка!"); return; } }
public IActionResult NewGenre(Genre genre) { if (genreRepository.Find(g => g.Id.ToLower() == genre.Id.ToLower()).Any()) { ModelState.AddModelError("Id", "This genre has already been created"); } if (ModelState.IsValid) { genreRepository.Create(genre); return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public IActionResult Create(GenreVM model) { if (!ModelState.IsValid) { return(View(model)); } Genre genre = _mapper.Map <Genre>(model); _genrerepo.Create(genre); return(RedirectToAction(nameof(Index))); }
public ActionResult Create(Genre genre) { if (!ModelState.IsValid) { return(View(genre)); } if (genreRepo.Create(genre)) { return(RedirectToAction("Index")); } return(View("Error")); }
public void Initialize() { var defaultData = CreateDefaultGenre(); foreach (var genre in defaultData) { var getGenre = _genreRepository.Get(genre.Id); if (getGenre.IsSuccess) { _genreRepository.Update(genre); } else { _genreRepository.Create(genre); } } }
public CreateGenreResponse CreateGenre(CreateGenreRequest request) { CreateGenreResponse response = new CreateGenreResponse(); try { Genre genre = request.ConvertToGenre(); _genreRepository.Create(genre); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public bool Save(Genre genre) { genre.Save(); if (!_notification.HasNotifications()) { if (genre.Id == 0) { _genreRepository.Create(genre); } else { _genreRepository.Update(genre); } } return(_notification.HasNotifications()); }
public bool Insert(Genre genre) { _repository.Create(genre); return(_repository.SaveChanges()); }
public IActionResult AddGenre(Genre genre) { genreRepository.Create(genre); return(RedirectToAction("Index")); }
public void CreateGenre(string name) { GenreRepository.Create(name); }
public void Create(GenreWithoutIdModel model) { repository.Create(model); }
public MappingProfile( IMovieRepository movieRepository, IGenreRepository genreRepository, ILanguageRepository languageRepository, IStyleRepository styleRepository, IReviewRepository reviewRepository, IMovieDataRepository movieDataRepository, IMovieDataGenreRepository movieDataGenreRepository, IMovieDataLanguageRepository movieDataLanguageRepository, IUnitOfWork unitOfWork) { string host = Environment.GetEnvironmentVariable("URL"); CreateMap <Models.Review, Resources.Review>(); #region Domain to Resource CreateMap <Models.User, Resources.User>(); CreateMap <Models.Genre, Resources.KeyValuePair>() .ForMember(g => g.Id, opt => opt.MapFrom(gr => gr.IdGenre)) .ForMember(g => g.Name, opt => opt.MapFrom(gr => gr.Name)); CreateMap <Models.Language, Resources.KeyValuePair>() .ForMember(g => g.Id, opt => opt.MapFrom(gr => gr.IdLanguage)) .ForMember(g => g.Name, opt => opt.MapFrom(gr => gr.Name)); CreateMap <Models.Style, Resources.KeyValuePair>() .ForMember(g => g.Id, opt => opt.MapFrom(gr => gr.IdStyle)) .ForMember(g => g.Name, opt => opt.MapFrom(gr => gr.Name)); CreateMap <Models.Image, Resources.Image>() .ForMember(img => img.Url, opt => opt.MapFrom(img => $"{host}image/{img.Id}")); CreateMap <Models.Movie, Resources.Movie>() .ForMember(m => m.IdUser, opt => opt.MapFrom(m => m.IdUser)) .ForMember(m => m.IdMovie, opt => opt.MapFrom(m => m.IdMovie)) .AfterMap((movieModel, movie) => { var data = movieDataRepository.GetByMovieId(movieModel.IdMovie).Result; var genres = new List <Resources.KeyValuePair>(); var languages = new List <Resources.KeyValuePair>(); movie.IdMovieData = data.IdMovieData; movie.RegisterDate = data.RegisterDate; movie.Name = data.Title; movie.Year = data.Year; movieDataGenreRepository.GetAll().Result.Where(genre => genre.IdMovieData == data.IdMovieData) .Join(genreRepository.GetAll().Result, mdg => mdg.IdGenre, g => g.IdGenre, (mdg, g) => g) .ToList().ForEach(genre => { genres.Add(new Resources.KeyValuePair { Id = genre.IdGenre, Name = genre.Name }); }); movieDataLanguageRepository.GetAll().Result.Where(language => language.IdMovieData == data.IdMovieData) .Join(languageRepository.GetAll().Result, mdl => mdl.IdLanguage, l => l.IdLanguage, (mdg, l) => l) .ToList().ForEach(language => { languages.Add(new Resources.KeyValuePair { Id = language.IdLanguage, Name = language.Name }); }); movie.PlatFav = data.PlatFav; movie.Image = new Resources.Image { Id = data.ImageMongoId, Url = $"{host}image/{data.ImageMongoId}" }; movie.Styles = new Resources.KeyValuePair[1] { new Resources.KeyValuePair { Id = data.IdStyle, Name = styleRepository.Get(data.IdStyle).Result.Name } }; movie.MetaScore = data.MetaScore; movie.Imdb = data.Imdb; movie.Director = data.Director; movie.Popularity = ScoreHelper.GetMoviePopularity(movie.IdMovie.Value, movieDataRepository, reviewRepository); movie.CommunityScore = ScoreHelper.GetMovieCommunityScore(movie.IdMovie.Value, reviewRepository); movie.Genres = genres.ToArray(); movie.Languages = languages.ToArray(); }); CreateMap <Models.MovieData, Resources.Movie>() .ForMember(m => m.Name, opt => opt.MapFrom(md => md.Title)) .ForMember(m => m.Styles, opt => opt.MapFrom(md => new Resources.KeyValuePair[1] { new Resources.KeyValuePair { Id = md.IdStyle, Name = styleRepository.GetAll().Result .FirstOrDefault(s => s.IdStyle == md.IdStyle).Name } })) .ForMember(m => m.Image, opt => opt.MapFrom(md => new Resources.Image { Id = md.ImageMongoId, Url = $"{host}image/{md.ImageMongoId}" })) .ForMember(m => m.CommunityScore, opt => opt.MapFrom(md => ScoreHelper.GetMovieCommunityScore(md.IdMovie, reviewRepository))) .ForMember(m => m.CommunityScore, opt => opt.MapFrom(md => ScoreHelper.GetMoviePopularity(md.IdMovie, movieDataRepository, reviewRepository))) .AfterMap((movieData, movie) => { var genres = new List <Resources.KeyValuePair>(); var languages = new List <Resources.KeyValuePair>(); movie.IdUser = movieRepository.Get(movieData.IdMovie).Result.IdUser; movieDataGenreRepository.GetAll().Result.Where(genre => genre.IdMovieData == movieData.IdMovieData) .Join(genreRepository.GetAll().Result, mdg => mdg.IdGenre, g => g.IdGenre, (mdg, g) => g) .ToList().ForEach(genre => { genres.Add(new Resources.KeyValuePair { Id = genre.IdGenre, Name = genre.Name }); }); movieDataLanguageRepository.GetAll().Result.Where(language => language.IdMovieData == movieData.IdMovieData) .Join(languageRepository.GetAll().Result, mdl => mdl.IdLanguage, l => l.IdLanguage, (mdg, l) => l) .ToList().ForEach(language => { languages.Add(new Resources.KeyValuePair { Id = language.IdLanguage, Name = language.Name }); }); movie.Genres = genres.ToArray(); movie.Languages = languages.ToArray(); }); #endregion #region Resource to Domain CreateMap <Resources.Movie, Models.Movie>() .ForMember(m => m.IdMovie, opt => opt.MapFrom(m => m.IdMovie)) .ForMember(m => m.IdUser, opt => opt.MapFrom(m => m.IdUser)); CreateMap <Resources.Movie, Models.MovieData>().BeforeMap((movie, movieData) => { foreach (Resources.KeyValuePair genre in movie.Genres) { if (genre.Id.Equals(null)) { genreRepository.Create(new Models.Genre(genre.Name)); unitOfWork.CompleteAsync().Wait(); } } foreach (Resources.KeyValuePair language in movie.Languages) { if (language.Id.Equals(null)) { languageRepository.Create(new Models.Language(language.Name)); unitOfWork.CompleteAsync().Wait(); } } }).ForMember(m => m.ImageMongoId, opt => opt.MapFrom(m => m.Image.Id)) .ForMember(m => m.Title, opt => opt.MapFrom(m => m.Name)) .ForMember(m => m.IdStyle, opt => opt.MapFrom(m => m.Styles[0].Id)); CreateMap <Resources.Image, Models.Image>() .ForMember(img => img.ObjectImage, opt => opt.Ignore()) .ForMember(img => img.Id, opt => opt.MapFrom(img => img.Id)); CreateMap <Resources.Review, Models.Review>(); #endregion }
public void Create(GenreModel entity) { _genreRepository.Create(GenreMapper.ToEntity(entity)); }
public void CreateGenre(Genre entity) { _genreRepository.Create(entity); }
public void Create(GenreModel entity) { var book = _mapper.Map <Genre>(entity); _genreRepository.Create(book); }