public JsonResult Login(UserAuthViewModel user) { using (WeatherAppDbContext db = new WeatherAppDbContext()) { var model = db.User.Find(user.Email); var result = new object(); if (model != null) { if (model.Password == user.Password) { result = new JsonResult(model); } else { result = new JsonResult("Usuario o contraseña invalidos."); } } else { result = new JsonResult("Invalid"); } return(new JsonResult(result)); } }
public JsonResult Post(WeatherAuditoryViewModel auditory) { if (!String.IsNullOrEmpty(auditory.Email)) { try { if (ModelState.IsValid) { using (WeatherAppDbContext db = new WeatherAppDbContext()) { var model = new WeatherAuditory() { Email = auditory.Email, CityCode = auditory.CityCode, CountryCode = auditory.CountryCode, Day = DateTime.Now.ToString(), Temperature = auditory.Temperature }; db.WeatherAuditory.Add(model); db.SaveChanges(); } } } catch (Exception ex) { throw new Exception(ex.Message); } return(new JsonResult("Added Succefuly")); } return(new JsonResult("continue")); }
public JsonResult Post(User user) { try { if (ModelState.IsValid) { using (WeatherAppDbContext db = new WeatherAppDbContext()) { var model = new User() { Nombre = user.Nombre, Apellido = user.Apellido, Email = user.Email, Password = user.Password }; db.User.Add(model); db.SaveChanges(); } } } catch (Exception ex) { throw new Exception(ex.Message); } return(new JsonResult("Added Succefuly")); }
public JsonResult Get() { using (WeatherAppDbContext db = new WeatherAppDbContext()) { var auditory = db.WeatherAuditory.ToList(); return(new JsonResult(auditory)); } }
public JsonResult Get() { using (WeatherAppDbContext db = new WeatherAppDbContext()) { var users = db.User.ToList(); return(new JsonResult(users)); } }
public WeatherService(HttpClient httpClient, IOptions <WeatherAppConfig> config, IMemoryCache memoryCache, WeatherAppDbContext dbContext, ILogger <WeatherService> logger) { _httpClient = httpClient; _config = config; _logger = logger; _cache = memoryCache; _dbContext = dbContext; }
public JsonResult Put(WeatherAuditory auditory) { using (WeatherAppDbContext db = new WeatherAppDbContext()) { db.Entry(auditory).State = EntityState.Modified(); db.SaveChanges(); } return(new JsonResult("Updated Succefuly")); }
public JsonResult Delete(string id) { using (WeatherAppDbContext db = new WeatherAppDbContext()) { var user = db.User.Find(id); db.Entry(user).State = EntityState.Delete(); db.SaveChanges(); } return(new JsonResult("The user was deleted.")); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, WeatherAppDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); DatabaseInitializer.Initialize(dbContext); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public WeatherService(WeatherAppDbContext dbContext, IHttpClientFactory httpClientFactory) { _dbContext = dbContext; _httpClientFactory = httpClientFactory; }
public CitiesService(WeatherAppDbContext dbContext, ILogger <CitiesService> logger) { _dbContext = dbContext; _logger = logger; }
public LocationController(WeatherAppDbContext context, IWeatherService weatherService) { _context = context; _weatherService = weatherService; }