public ActionResult EditProfile(EditViewModel model) { if (ModelState.IsValid) { string Email = User.Identity.Name; if (Email.ToLower().Equals(model.Email.ToLower())) { var admin = _db.Admins.Where(a => a.Email.ToLower().Equals(model.Email.ToLower())).FirstOrDefault(); admin.Name = model.Name; _db.SaveChanges(); TempData["Success"] = "Changes Saved Successfully!"; return(View(model)); } bool isValid = _db.Admins.Any(x => x.Email == model.Email); if (isValid) { ModelState.AddModelError("", "Email already exists"); return(View(model)); } var admin1 = _db.Admins.Where(a => a.Email.Equals(Email)).FirstOrDefault(); admin1.Email = model.Email; admin1.Name = model.Name; TempData["Success"] = "Changes Saved Successfully!"; _db.SaveChanges(); return(RedirectToAction("Logout", "Admin")); } return(View(model)); }
public async Task Update() { var city = db.city.Include(c => c.currentWeather).ToList(); foreach (var c in city) { WeatherRoot w = await getCityWeather(c); CurrentWeather currentWeather = new CurrentWeather { clouds = w.current.clouds, sunrise = w.current.sunrise, sunset = w.current.sunset, temp = w.current.temp, humidity = w.current.humidity, feels_like = w.current.feels_like, pressure = w.current.pressure, uvi = w.current.uvi, dew_point = w.current.dew_point, dt = w.current.dt, wind_deg = w.current.wind_deg, wind_speed = w.current.wind_speed, weather_main = w.current.weather[0].main, weather_description = w.current.weather[0].description, weather_icon = w.current.weather[0].icon, weather_id = w.current.weather[0].id, visibility = w.current.visibility }; if (c.currentWeather == null) { c.currentWeather = currentWeather; db.SaveChanges(); } else { db.Entry(c.currentWeather).State = EntityState.Modified; c.currentWeather = currentWeather; db.SaveChanges(); } foreach (var dailyForecast in w.daily) { DailyForecast dailyForecast1 = new DailyForecast { dt = dailyForecast.dt, sunrise = dailyForecast.sunrise, sunset = dailyForecast.sunset, temp_day = dailyForecast.temp.day, temp_min = dailyForecast.temp.min, temp_max = dailyForecast.temp.max, temp_night = dailyForecast.temp.night, temp_eve = dailyForecast.temp.eve, morn = dailyForecast.temp.morn, feels_like_day = dailyForecast.feels_like.day, feels_like_night = dailyForecast.feels_like.night, feels_like_eve = dailyForecast.feels_like.eve, feels_like_morn = dailyForecast.feels_like.morn, pressure = dailyForecast.pressure, humidity = dailyForecast.humidity, dew_point = dailyForecast.dew_point, wind_speed = dailyForecast.wind_speed, wind_deg = dailyForecast.wind_deg, weather_id = dailyForecast.weather[0].id, weather_main = dailyForecast.weather[0].main, weather_description = dailyForecast.weather[0].description, weather_icon = dailyForecast.weather[0].icon, clouds = dailyForecast.clouds, uvi = dailyForecast.uvi }; c.dailyForcasts.Add(dailyForecast1); db.SaveChanges(); } } }