// GET: Weather public ActionResult Index() { IEnumerable <User> users; using (var dbContext = new WeatherEntities()) { users = ( from u in dbContext.Users select u ).ToList(); } var selectItems = new List <SelectListItem>(); foreach (User user in users) { SelectListItem itemToAdd = new SelectListItem(); itemToAdd.Text = string.Concat(user.FirstName, " ", user.LastName); itemToAdd.Value = user.CityID; selectItems.Add(itemToAdd); } ViewBag.Users = selectItems; ViewBag.Message = "Weather Page"; return(View()); }
public BizBase() { if (this.weatherEntities == null) { weatherEntities = new WeatherEntities(); } }
public DayWeatherEfRepository() { _context = new WeatherEntities(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <DayWeather, DAL.WeatherForecast.Entity.DayWeather>().ReverseMap(); }); _mapper = config.CreateMapper(); }
public ActionResult AddUser(User userToAdd) { if (userToAdd == null) { throw new ArgumentNullException(nameof(userToAdd), "No user was provided to add to the database."); } using (var dbContext = new WeatherEntities()) { dbContext.Users.Add(userToAdd); dbContext.SaveChanges(); } return(RedirectToRoute("Default", new { controller = "Admin", action = "Index" })); }
// GET: Admin public ActionResult Index() { ViewBag.Message = "Admin Page"; IEnumerable <User> users; using (var dbContext = new WeatherEntities()) { users = ( from u in dbContext.Users select u ).ToList(); } ViewBag.Users = users; return(View()); }
public async Task <string> GetWeatherData(string filename) { HttpClient httpclient = null; try { //call to validate file first ValidateFile(filename); //get the data from CSV filr into datatable DataTable dtData = GetDataFromCsvFile(filename); if (dtData != null && dtData.Rows.Count > 0) { //Use http client to make a http request to open weather API using (httpclient = new HttpClient()) { foreach (DataRow dr in dtData.Rows) { // make http call for each city id using (Stream stream = await httpclient.GetStreamAsync($"{ConfigurationManager.AppSettings["WeatherApiUrl"].ToString()}?id={Convert.ToString(dr["City_ID"]).Trim()}&appid={ConfigurationManager.AppSettings["AppKey"].ToString()}&units={ConfigurationManager.AppSettings["unit"].ToString()}")) { using (StreamReader streamReader = new StreamReader(stream)) { //logic to save each city file with today's date and time into CSV file type string city = Convert.ToString(dr["City_Name"].ToString()).Trim(); WeatherEntities WE = JsonConvert.DeserializeObject <WeatherEntities>(streamReader.ReadToEnd()); string saveFileName = WE.name + "_" + DateTime.Now.ToString("MMMM-dd-yyyy_Hmmssfff") + ".csv"; using (var writer = new StreamWriter($@"{ConfigurationManager.AppSettings["Outfolder"].ToString()}\{saveFileName}")) { using (var csv = new CsvWriter(writer)) { //saving only Main info like temp,pressure,humidty,temp_min,temp_max List <Main> lsMain = new List <Main>(); lsMain.Add(WE.main); csv.WriteRecords(lsMain); } } } } } } } else { throw new InvalidDataException(); } return("File Processed!"); } catch (CsvHelperException ex) { log.Error("Error ocurred in GetWeather Data Method", ex); throw new CsvHelperException(ex.ReadingContext, "file validation failed!! Invalid file"); } catch (InvalidDataException ex) { log.Error("Error ocurred in GetWeather Data Method", ex); throw new InvalidDataException("File has no data"); } catch (FileNotFoundException ex) { log.Error("Error ocurred in GetWeather Data Method", ex); throw new FileNotFoundException("File not found"); } catch (Exception ex) { log.Error("Error ocurred in GetWeather Data Method", ex); throw new Exception("Error occurred while processing file"); } }