private async Task LoadEdit() { var resultGenres = await _genresApi.Get <PagedList <GenreDto> >(null); _movie = await _moviesApi.GetById <MovieDto>(_id); SetReadonly(false); LoadPropertyValues(_movie); List <GenreDto> movieGenres = resultGenres.Data.Where(x => _movie.GenreMovies.Select(y => y.GenreId).Contains(x.Id)).ToList(); chlGenres.DataSource = resultGenres.Data; chlGenres.DisplayMember = nameof(GenreDto.Name); for (int i = 0; i < chlGenres.Items.Count; i++) { GenreDto genre = chlGenres.Items[i] as GenreDto; if (_movie.GenreMovies.Select(x => x.GenreId).Contains(genre.Id)) { chlGenres.SetItemChecked(i, true); } } }
public bool Save(GenreDto genreDto) { Genre genre = new Genre { Id = genreDto.Id, Name = genreDto.Name }; try { using (UnitOfWork unitOfWork = new UnitOfWork()) { if (genreDto.Id == 0) { unitOfWork.GenreReposiotry.Insert(genre); } else { unitOfWork.GenreReposiotry.Update(genre); } unitOfWork.Save(); } return(true); } catch { return(false); } }
public async Task <IActionResult> UpdateGenre(GenreDto genre) { Logger.Here().Info("{UpdateGenre} - {genre}", nameof(UpdateGenre)); var result = await _service.CreateMovieService().UpdateGenreAsync(genre); return(GetUpdatedStatus(result, "Given genre is not updateable.")); }
public async Task <ActionResult <GenreDto> > Put([FromRoute] int id, [FromBody] GenreDto genreDto) { genreDto.Id = id; await _genreService.EditAsync(_mapper.Map <Genre>(genreDto)); return(Ok(new { message = MessagesResource.SUCCESS_MESSAGE })); }
public ResultDto AddGenre([FromBody] GenreDto dto) { try { Genre genre = new Genre() { Name = dto.Name }; ctx.Genres.Add(genre); ctx.SaveChangesAsync(); return(new ResultDto { IsSuccessful = true, Message = "Successfully created" }); } catch (Exception) { return(new ResultDto { IsSuccessful = false, Message = "Something goes wrong!" }); throw; } }
public void AddGenre_WithTestData_ThenOk_Test(GenreDto genreInfo) { var result = genreController.AddGenre(genreInfo) as OkObjectResult; Assert.Equal(200, result.StatusCode); Assert.Equal(JsonConvert.SerializeObject(genreInfo), JsonConvert.SerializeObject(result.Value)); }
private void SourceOnSelectedRow(object sender, GenreDto genreDto) { var storyboard = Ui.Storyboards.Storyboard.Main; var searchViewController = (SearchTableViewController)storyboard.InstantiateViewController(SearchTableViewController.StoryboardIdentifier); searchViewController.Genre = genreDto; this.NavigationController.PushViewController(searchViewController, true); }
public async Task <ActionResult <GenreDto> > Post([FromBody] GenreCreateDto genreCreateDto) { GenreDto newGenre = _mapper.Map <GenreDto>( await _genreService.AddAsync(_mapper.Map <Genre>(genreCreateDto)) ); return(CreatedAtAction("Get", new { id = newGenre.Id }, newGenre)); }
public void Create(GenreDto genreDto) { _logger.Info($"Creating new genre: name = {genreDto.Name}, body = {genreDto.ParentGenre.Name}"); _unitOfWork.GenreGenericRepository.Create(_mapper.Map <Genre>(genreDto)); _unitOfWork.Commit(); }
public void Execute(GenreDto request) { _validator.ValidateAndThrow(request); var genre = _mapper.Map <Genre>(request); _context.Genres.Add(genre); _context.SaveChanges(); }
public void Execute(GenreDto request) { _validator.ValidateAndThrow(request); var genre = _context.Genres.Find(request.Id); _mapper.Map(request, genre); _context.SaveChanges(); }
public static Genre Convert(GenreDto genre) { return(new Genre { Id = genre.Id, Title = genre.Title, }); }
public void AddGenre(GenreDto dto) { Genre entity = new Genre(); entity.Name = dto.Name; _genreRepository.Add(entity); _genreRepository.Save(); }
public IActionResult Put(int id, [FromBody] GenreDto dto, [FromServices] IUpdateGenreCommand command) { dto.Id = id; _executor.ExecuteCommand(command, dto); return(StatusCode(StatusCodes.Status204NoContent)); }
public async Task <GenreDto> CreatAsync(GenreDto item) { var result = _context.Genres.Add( GenreConverter.Convert(item)); await _context.SaveChangesAsync(); return(GenreConverter.Convert(result.Entity)); }
public static Genre Convert(GenreDto genre) { return(new Genre { Id = genre.Id, Name = genre.Name }); }
public void Create_ExistsGenre_ShouldThrownGenreDublicateException() { var dto = new GenreDto() { Name = DefaultData.Genres.CSharp.Name }; Assert.Throws <GenreDublicateException>(async() => await GenresService.Create(dto)); }
public async Task <GenreDto> UpdateGenre(GenreDto genre) { var entityGenre = await _unitOfWork.Movies.GetByIdAsync(genre.Id); entityGenre = ObjectMapper.Mapper.Map(genre, entityGenre); await _unitOfWork.CommitAsync(); return(ObjectMapper.Mapper.Map <GenreDto>(entityGenre)); }
public IActionResult Create([FromBody] GenreDto genre) { if (genreService.Create(genre)) { return(NoContent()); } return(BadRequest()); }
public async Task <bool> Update(GenreDto genreDto) { var genre = _mapper.Map <Genre>(genreDto); _genreRepository.Update(genre); var affectedRows = await _genreRepository.SaveChangesAsync(); return(affectedRows > 0); }
public async Task <GenreDto> Add(GenreDto genreDto) { var genre = _mapper.Map <Genre>(genreDto); _genreRepository.Add(genre); await _genreRepository.SaveChangesAsync(); return(_mapper.Map <GenreDto>(genre)); }
public async Task <GenreDto> CreateGenre(GenreDto genre) { var entityGenre = ObjectMapper.Mapper.Map <Genre>(genre); await _unitOfWork.Genres.AddAsync(entityGenre); await _unitOfWork.CommitAsync(); return(ObjectMapper.Mapper.Map <GenreDto>(entityGenre)); }
public string PostGenre(GenreDto genreDto) { if (!service.Save(genreDto)) { return("Genre is not inserted"); } return("Genre is inserted"); }
public static DeleteGenreViewModel ToDeleteGenreViewModel(this GenreDto genre, IEnumerable <string> subGenres) { return(new DeleteGenreViewModel { Id = genre.Id, Name = genre.Name, SubGenres = subGenres }); }
public void ShouldMap_GenreDto_To_GenreViewModel() { var genre = new GenreDto(1, "name", null); GenreViewModel result = genre.ToViewModel(); Assert.AreEqual(genre.Id, result.Id); Assert.AreEqual(genre.Name, result.Name); Assert.IsNull(result.ParentGenreId); }
public void Update(GenreDto genreDto) { _logger.Info($"Updating the genre: id = {genreDto.Id}, name = {genreDto.Name}"); var genre = _mapper.Map <Genre>(genreDto); _unitOfWork.GenreGenericRepository.Update(genre); _unitOfWork.Commit(); }
private static GenreDto CreateTestGenreDto(string name, string id = "1") { var genreDto = new GenreDto { Id = id, Name = name }; return(genreDto); }
// PUT: api/Genre/5 public IHttpActionResult Put(GenreDto genre) { var updatedGenre = _genreServices.UpdateGenre(genre); if (updatedGenre == null) { return(NotFound()); } return(Ok(genre)); }
public void Execute(GenreDto request) { var genreFromDb = context.Genres.Find(request.Id); mapper.Map(request, genreFromDb); validator.ValidateAndThrow(request); context.SaveChanges(); }
public async Task <bool> UpdateAsync(GenreDto item) { if (item == null) { return(false); } _context.Genres.Update(GenreConverter.Convert(item)); await _context.SaveChangesAsync(); return(true); }