Exemple #1
0
 public static WeatherForecastGetModel ToGetModel(this WeatherForecastEntity entity)
 {
     return(new()
     {
         Date = entity.Date,
         TemperatureC = entity.TemperatureC,
         Summary = entity.Summary
     });
 }
        private void AddLog(string logData, string zipCode)
        {
            JObject json = JObject.Parse(logData);

            var dto = new WeatherForecastEntity
            {
                Timestamp   = DateTime.Now,
                ZipCode     = zipCode,
                Temperature = (int)json["temperature"]
            };

            _weatherForecastRepository.Add(dto);
        }
Exemple #3
0
        public async Task SaveWeatherForecast(WeatherForecastEntity entity)
        {
            var existing = _context.WeatherForecasts.FirstOrDefault(x => x.Id == entity.Id);

            if (existing != null)
            {
                _context.WeatherForecasts.Update(entity);
                await _context.SaveChangesAsync();

                return;
            }

            _context.WeatherForecasts.Add(entity);
            await _context.SaveChangesAsync();
        }
Exemple #4
0
        public async Task <Guid> Execute(AddWeatherForecastRequest input, string username)
        {
            var correlationId = CorrelationIdAccessor.CorrelationId;

            var weatherForecast = new WeatherForecastEntity(correlationId)
            {
                Temperature = input.TemperatureInCelsius, Summary = input.Summary, Date = input.Date
            };

            var command = new CreateWeatherForecastCommand(weatherForecast, username);
            await _commandDispatcher.Execute(command);

            var evt = _mapper.Map <WeatherForecastEntity, WeatherForecastCreatedEvent>(weatherForecast);

            _backgroundTaskQueue.Queue($"Publishing WeatherForecastCreatedEvent for {evt.Id}",
                                       (cancelationToken) => _eventDispatcher.Raise(evt));

            return(weatherForecast.Id);
        }
Exemple #5
0
        public static WeatherForecastViewModel MapToViewModel(WeatherForecastEntity entity)
        {
            var dateTimeNow = DateTime.Now;

            return(new WeatherForecastViewModel
            {
                CityName = entity.CityName,
                WeatherCondition = entity.WeatherCondition,
                WeatherConditionDetails = entity.WeatherConditionDetails,
                WeatherConditionIcon = entity.WeatherConditionIcon,
                Humidity = entity.Humidity,
                Pressure = entity.Pressure,
                Temperature = entity.Temperature,
                Day = dateTimeNow.DayOfWeek.ToString(),
                Month = dateTimeNow.ToString("MMM", CultureInfo.InvariantCulture),
                Year = dateTimeNow.Year.ToString(),
                Time = dateTimeNow.ToShortTimeString(),
                WindSpeed = entity.WindSpeed,
                Country = entity.Country,
                Sunrise = entity.Sunrise,
                Sunset = entity.Sunset
            });
        }
        public void Test_Mapping_Functional()
        {
            Db.Recreate();

            using WeatherDbContext ctx1 = Db.GetAppContext();
            var entity = new WeatherForecastEntity
            {
                Id           = Guid.NewGuid(),
                Date         = DateTime.UtcNow,
                Summary      = "some summary",
                TemperatureC = 10
            };

            ctx1.Set <WeatherForecastEntity>().Add(entity);
            ctx1.SaveChanges();

            using WeatherDbContext ctx2 = Db.GetAppContext();
            WeatherForecastEntity saved = ctx2.Set <WeatherForecastEntity>().Find(entity.Id);

            Assert.NotNull(saved);
            Assert.AreEqual(entity.Date, saved.Date);
            Assert.AreEqual(entity.Summary, saved.Summary);
            Assert.AreEqual(entity.TemperatureC, saved.TemperatureC);
        }
Exemple #7
0
 public CreateWeatherForecastCommand(WeatherForecastEntity weatherForecast, string username)
 {
     WeatherForecast = weatherForecast;
     Username        = username;
 }
Exemple #8
0
 public WeatherForecastViewModel(WeatherForecastEntity weatherForecastEntity)
 {
     _weatherForecastEntity = weatherForecastEntity;
     TemperatureC           = _weatherForecastEntity.TemperatureC;
     TemperatureF           = _weatherForecastEntity.TemperatureF;
 }
 public void Add(WeatherForecastEntity entity)
 {
     _weatherForecastContext.WeatherForecastLog.Add(entity);
     _weatherForecastContext.SaveChanges();
 }