Example #1
0
        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"));
        }
Example #2
0
 public JsonResult Put(WeatherAuditory auditory)
 {
     using (WeatherAppDbContext db = new WeatherAppDbContext())
     {
         db.Entry(auditory).State = EntityState.Modified();
         db.SaveChanges();
     }
     return(new JsonResult("Updated Succefuly"));
 }