public async Task <IActionResult> GetProducersById([FromRoute] int producerId) { var producer = await _producerRepository.GetAsync(producerId); if (producer == null) { return(NotFound()); } var movies = await _movieRepository.Query().ToListAsync(); if (movies.FirstOrDefault(c => c.ProducerId == producerId) == null) //if for particular aticle if we don't have any comment it returns not found { return(NotFound()); } var result = new MovieListModel { Movies = movies.Select(c => new MovieModel { ProducerId = (int)c.ProducerId, //article id is used to use where clause to shown the result which is of particular article id Id = c.Id, Name = c.Name, YearOfReleased = c.YearOfReleased, Plot = c.Plot }).Where(a => a.ProducerId == producerId) //use where clause to show the filtered result }; return(Ok(result)); }
public static async Task <Producer> GetOrFailAsync(this IProducerRepository repository, string name) { var producer = await repository.GetAsync(name); if (producer == null) { throw new Exception($"Producer with name: '{name}' does not exist."); } return(producer); }
public static async Task <Producer> GetOrFailAsync(this IProducerRepository repository, Guid id) { var producer = await repository.GetAsync(id); if (producer == null) { throw new Exception($"Producer with id: '{id}' does not exist."); } return(producer); }
public async Task <IActionResult> Get(int id) { var producer = await _producerRepository.GetAsync(id); if (producer == null) { return(NotFound()); } var result = new ProducerModel { Id = producer.Id, Name = producer.Name, Sex = producer.Sex, DOB = producer.DOB, BIO = producer.BIO }; return(Ok(result)); }
// TODO: Delete public static async Task <Producer> SetOrGetExistingAsync(this IProducerRepository repository, string name) { var @producer = await repository.GetAsync(name); if (@producer == null) { var id = Guid.NewGuid(); @producer = new Producer(id, name); await repository.AddAsync(@producer); } return(@producer); }
public async Task <ProducerDto> GetAsync(Guid id) { var @producer = await _producerRepository.GetAsync(id); return(_mapper.Map <ProducerDto>(@producer)); }