Esempio n. 1
0
        public List <string> ReadExelArchives(List <HttpPostedFileBase> archives)
        {
            List <string> result = new List <string>();

            foreach (var archive in archives)
            {
                if (archive.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
                {
                    ExelParseResultModel archiveWeatherData = exelParseService.ReadExelArchive(archive);

                    if (archiveWeatherData.WeatherData.Count != 0)
                    {
                        db.WeatherData.AddRange(archiveWeatherData.WeatherData);
                        db.SaveChangesAsync();
                    }

                    if (archiveWeatherData.ErrorMessages.Count == 0)
                    {
                        result.Add(string.Format(ErrorTextTemplates.SUCCESS, archive.FileName));
                    }
                    else
                    {
                        foreach (var error in archiveWeatherData.ErrorMessages)
                        {
                            result.Add(error);
                        }
                    }
                }
                else
                {
                    result.Add(string.Format(ErrorTextTemplates.FILE_TYPE_ERROR, archive.FileName));
                }
            }
            return(result);
        }
Esempio n. 2
0
        public async Task CreateAsync(WeatherMeasures weatherMeasure)
        {
            var city = _dbContext.Cities.FirstOrDefault(i => i.CityId == weatherMeasure.CityId);

            if (city == null)
            {
                throw new Exception("City doesn't exist.");
            }

            //  _dbContext.Attach(weatherMeasure);
            //   city.WeatherMeasures.Add(weatherMeasure);

            await _dbContext.WeatherMeasures.AddAsync(weatherMeasure);

            await _dbContext.SaveChangesAsync();
        }
Esempio n. 3
0
        public async Task CreateAsync(Cities city)
        {
            await _dbContext.Cities.AddAsync(city);

            await _dbContext.SaveChangesAsync();
        }