Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            DarkSkyLocation darkSkyLocations = db.DarkSkyLocations.Find(id);

            db.DarkSkyLocations.Remove(darkSkyLocations);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public ActionResult Edit(DarkSkyLocation darkSkyLocations)
 {
     if (ModelState.IsValid)
     {
         db.Entry(darkSkyLocations).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(darkSkyLocations));
 }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,Name,StreetAddress,City,State,ZipCode")] DarkSkyLocation darkSkyLocations)
        {
            if (ModelState.IsValid)
            {
                db.DarkSkyLocations.Add(darkSkyLocations);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(darkSkyLocations));
        }
Beispiel #4
0
        // GET: DarkSkyLocations/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DarkSkyLocation darkSkyLocations = db.DarkSkyLocations.Find(id);

            if (darkSkyLocations == null)
            {
                return(HttpNotFound());
            }
            return(View(darkSkyLocations));
        }
Beispiel #5
0
        // GET: DarkSkyLocations/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DarkSkyLocation darkSkyLocations = db.DarkSkyLocations.Find(id);

            darkSkyLocations.AverageRating = AverageRating(darkSkyLocations);
            db.SaveChanges();
            if (darkSkyLocations == null)
            {
                return(HttpNotFound());
            }
            return(View(darkSkyLocations));
        }
Beispiel #6
0
        public double AverageRating(DarkSkyLocation darkSkyLocation)
        {
            List <RatingsCheckIn> ratingsObj = new List <RatingsCheckIn>();
            List <string>         ratings    = new List <string>();
            List <int>            integers   = new List <int>();

            ratingsObj = db.RatingsCheckIns.Where(r => r.Rating > 0).Where(l => l.LocationId == darkSkyLocation.LocationId).ToList();
            foreach (RatingsCheckIn rating in ratingsObj)
            {
                Convert.ToInt32(rating.Rating);
                integers.Add(rating.Rating);
            }
            double averageRating = integers.Average();

            return(averageRating);
        }
Beispiel #7
0
        public async Task <int> GetDuration(Observer observer, DarkSkyLocation darkSkyLocation)
        {
            string              userLatLong     = observer.ObserverLatLong;
            string              locationLatLong = darkSkyLocation.LatLong;
            var                 key             = URLVariables.DirectionsKey;
            string              url             = $"https://maps.googleapis.com/maps/api/directions/json?origin={userLatLong}&destination={locationLatLong}&key={key}";
            HttpClient          client          = new HttpClient();
            HttpResponseMessage response        = await client.GetAsync(url);

            string jsonresult = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                LocationJsonInfo locationJsonInfo = JsonConvert.DeserializeObject <LocationJsonInfo>(jsonresult);
                int duration = locationJsonInfo.routes[0].legs[0].duration.value;
                return(duration);
            }
            else
            {
                return(0);
            }
        }
 public ActionResult Create([Bind(Include = "Rating")] RatingsCheckIn ratingsCheckIn, Observer observer, DarkSkyLocation darkSkyLocation)
 {
     if (ModelState.IsValid)
     {
         RatingsCheckIn ratings = new RatingsCheckIn();
         ratings.LocationId = darkSkyLocation.LocationId;
         ratings.UserId     = observer.UserId;
         ratings.Rating     = ratingsCheckIn.Rating;
         db.RatingsCheckIns.Add(ratings);
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     ViewBag.LocationId = new SelectList(db.DarkSkyLocations, "LocationId", "Name", ratingsCheckIn.LocationId);
     ViewBag.UserId     = new SelectList(db.Observers, "UserId", "FirstName", ratingsCheckIn.UserId);
     return(View(ratingsCheckIn));
 }