Пример #1
0
        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);
            }
        }
Пример #3
0
        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."));
        }
Пример #4
0
        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 }));
        }
Пример #5
0
        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;
            }
        }
Пример #6
0
        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));
        }
Пример #7
0
        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);
        }
Пример #8
0
        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));
        }
Пример #9
0
        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();
        }
Пример #10
0
        public void Execute(GenreDto request)
        {
            _validator.ValidateAndThrow(request);
            var genre = _mapper.Map <Genre>(request);

            _context.Genres.Add(genre);
            _context.SaveChanges();
        }
Пример #11
0
        public void Execute(GenreDto request)
        {
            _validator.ValidateAndThrow(request);
            var genre = _context.Genres.Find(request.Id);

            _mapper.Map(request, genre);
            _context.SaveChanges();
        }
Пример #12
0
 public static Genre Convert(GenreDto genre)
 {
     return(new Genre
     {
         Id = genre.Id,
         Title = genre.Title,
     });
 }
Пример #13
0
        public void AddGenre(GenreDto dto)
        {
            Genre entity = new Genre();

            entity.Name = dto.Name;
            _genreRepository.Add(entity);
            _genreRepository.Save();
        }
Пример #14
0
 public IActionResult Put(int id,
                          [FromBody] GenreDto dto,
                          [FromServices] IUpdateGenreCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status204NoContent));
 }
Пример #15
0
        public async Task <GenreDto> CreatAsync(GenreDto item)
        {
            var result = _context.Genres.Add(
                GenreConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(GenreConverter.Convert(result.Entity));
        }
Пример #16
0
 public static Genre Convert(GenreDto genre)
 {
     return(new Genre
     {
         Id = genre.Id,
         Name = genre.Name
     });
 }
Пример #17
0
        public void Create_ExistsGenre_ShouldThrownGenreDublicateException()
        {
            var dto = new GenreDto()
            {
                Name = DefaultData.Genres.CSharp.Name
            };

            Assert.Throws <GenreDublicateException>(async() => await GenresService.Create(dto));
        }
Пример #18
0
        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));
        }
Пример #22
0
        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));
        }
Пример #23
0
        public string PostGenre(GenreDto genreDto)
        {
            if (!service.Save(genreDto))
            {
                return("Genre is not inserted");
            }

            return("Genre is inserted");
        }
Пример #24
0
 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);
        }
Пример #26
0
        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();
        }
Пример #27
0
        private static GenreDto CreateTestGenreDto(string name, string id = "1")
        {
            var genreDto = new GenreDto
            {
                Id   = id,
                Name = name
            };

            return(genreDto);
        }
Пример #28
0
        // PUT: api/Genre/5
        public IHttpActionResult Put(GenreDto genre)
        {
            var updatedGenre = _genreServices.UpdateGenre(genre);

            if (updatedGenre == null)
            {
                return(NotFound());
            }
            return(Ok(genre));
        }
Пример #29
0
        public void Execute(GenreDto request)
        {
            var genreFromDb = context.Genres.Find(request.Id);

            mapper.Map(request, genreFromDb);

            validator.ValidateAndThrow(request);

            context.SaveChanges();
        }
Пример #30
0
        public async Task <bool> UpdateAsync(GenreDto item)
        {
            if (item == null)
            {
                return(false);
            }
            _context.Genres.Update(GenreConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(true);
        }