public async Task <IEnumerable <NosterDto> > FindAllWithIncludes()
        {
            var Noster = await this._nostradamusContext.Set <Noster>().AsNoTracking()
                         .Include(n => n.NosterScore)
                         .Include(n => n.GenericEvents)
                         .Include(n => n.GenericPredictions)
                         .ToListAsync();

            GenericEventDto[] GenericEventDtos = new GenericEventDto[50];
            NosterScoreDto    nosterScoreDto   = new NosterScoreDto();

            GenericPredictionDto[] genericPredictionDtos = new GenericPredictionDto[50];

            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <GenericEvent, GenericEventDto>();
                cfg.CreateMap <NosterScore, NosterScoreDto>();
                cfg.CreateMap <GenericPrediction, GenericPredictionDto>();
            });
            IMapper iMapper = config.CreateMapper();

            var NosterDtoList = Noster.Select(n => new NosterDto
            {
                UserName              = n.UserName,
                Email                 = n.Email,
                PhoneNumber           = n.PhoneNumber,
                PhoneNumberConfirmed  = n.PhoneNumberConfirmed,
                TwoFactorEnabled      = n.TwoFactorEnabled,
                CreationDate          = n.CreationDate,
                NosterScoreDto        = iMapper.Map(n.NosterScore, nosterScoreDto),
                GenericEventDtos      = iMapper.Map(n.GenericEvents, GenericEventDtos),
                GenericPredictionDtos = iMapper.Map(n.GenericPredictions, genericPredictionDtos)
            });

            return(NosterDtoList);
        }
        public async Task <GenericEventDto> GetGenericEvent(int id)
        {
            //return await _unitofWork.GenericEvent.FindById(id);

            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <GenericEvent, GenericEventDto>();
            });
            IMapper iMapper = config.CreateMapper();

            var genericEvent = await _unitofWork.GenericEvent.FindById(id);

            GenericEventDto dto = new GenericEventDto();

            var genericEventDto = iMapper.Map(genericEvent, dto);

            return(genericEventDto);
        }
        public new async Task <GenericEventDto> Create(GenericEvent genericEvent)
        {
            genericEvent.CreationDate = DateTime.Now;
            _nostradamusContext.Set <GenericEvent>().Add(genericEvent);
            await _nostradamusContext.SaveChangesAsync();

            //GetGenericPrediction

            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <GenericEvent, GenericEventDto>();
            });
            IMapper iMapper = config.CreateMapper();

            GenericEventDto dto             = new GenericEventDto();
            var             genericEventDto = iMapper.Map(genericEvent, dto);

            return(genericEventDto);
        }
Exemple #4
0
        public async Task <ActionResult <GenericEventDto> > GetGenericEvent(int id)
        {
            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <GenericEvent, GenericEventDto>();
            });
            IMapper iMapper = config.CreateMapper();

            var genericEvent = await _context.GenericEvent.FindAsync(id);

            GenericEventDto dto = new GenericEventDto();

            var genericEventDto = iMapper.Map(genericEvent, dto);

            if (genericEvent == null)
            {
                return(NotFound());
            }

            return(genericEventDto);
        }