예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        // 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);
        }
예제 #6
0
        public async Task <ProducerDto> GetAsync(Guid id)
        {
            var @producer = await _producerRepository.GetAsync(id);

            return(_mapper.Map <ProducerDto>(@producer));
        }