public async Task <BusinessDTO> Index([FromRoute] int id)
        {
            var result = await _businessRepository.FindById(id);

            BusinessDTO businessDto = new BusinessDTO();

            businessDto.Name    = result.Name;
            businessDto.Type    = result.Type;
            businessDto.Address = result.Address;
            List <EventDTO> eventDtos = new List <EventDTO>();

            foreach (var eventDto in result.Events)
            {
                eventDtos.Add(new EventDTO
                {
                    Id          = eventDto.Id, Name = eventDto.Name, Creation = eventDto.Creation,
                    Description = eventDto.Description, Type = eventDto.Type
                });
            }

            List <PromotionDTO> promotionsDtos = new List <PromotionDTO>();

            foreach (var promotionDto in result.Promotions)
            {
                promotionsDtos.Add(new PromotionDTO
                {
                    Id            = promotionDto.Id, Name = promotionDto.Name, Creation = promotionDto.Creation,
                    PromotionType = promotionDto.PromotionType, Description = promotionDto.Description,
                    EndDate       = promotionDto.EndDate,
                    StartDate     = promotionDto.StartDate
                });
            }

            businessDto.Events     = eventDtos;
            businessDto.Promotions = promotionsDtos;
            return(businessDto);
        }
Beispiel #2
0
 public async Task <BusinessViewModel> GetByIdAsync(string id)
 {
     return(new BusinessViewModel().Map(await _repository.FindById(id)));
 }