Example #1
0
 public ActionResult Create(RestaurantReview review)
 {
     if (ModelState.IsValid)
     {
         _db.Reviews.Add(review);
         _db.SaveChanges();
         return(RedirectToAction("Index", new { id = review.RestaurantId }));
     }
     return(View(review));
 }
Example #2
0
        public ActionResult Create(Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                db.Restaurants.Add(restaurant);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(restaurant));
        }
Example #3
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (var db = new GameAppDb())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Example #4
0
        public ActionResult Result(int Id)
        {
            double lat = Convert.ToDouble((Request.Form["lat"]).Replace('.', ','));
            double lng = Convert.ToDouble((Request.Form["lng"]).Replace('.', ','));

            Photo photo = _db.Photos.Find(Id);

            if (photo == null)
            {
                return(HttpNotFound());
            }
            if (PhotoPlayed(Id))
            {
                return(RedirectToAction("index", "Photo"));
            }

            double distance = CalcDistance(lat, lng, photo.Latitude, photo.Longitude);
            int    points   = CalcPoints(distance);

            _db.Scores.Add(new Score
            {
                UserId      = WebSecurity.CurrentUserId,
                ImgId       = Id,
                ScorePoints = points
            });

            UserProfile User = _db.UserProfiles.Find(WebSecurity.CurrentUserId);

            User.UserPoints += points;
            _db.SaveChanges();

            ViewBag.lat1     = lat;
            ViewBag.lon1     = lng;
            ViewBag.lat2     = photo.Latitude;
            ViewBag.lon2     = photo.Longitude;
            ViewBag.Distance = distance;
            ViewBag.Points   = points;

            return(View());
        }
Example #5
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var      Photo       = _db.Photos.OrderByDescending(p => p.Id).FirstOrDefault();
                string   oldFileName = Path.GetFileName(file.FileName);
                string[] name        = oldFileName.Split('.');
                int      id          = (Photo == null) ? 0 : Photo.Id;
                string   newFileName = (Convert.ToInt16(id) + 1).ToString() + "." + name[1];
                string   tempPath    = Path.Combine(Server.MapPath("~/Images/uploads/temp"), newFileName);
                string   path        = Path.Combine(Server.MapPath("~/Images/uploads"), newFileName);
                file.SaveAs(tempPath);

                try
                {
                    using (ExifReader reader = new ExifReader(tempPath))
                    {
                        Double[] GpsLongArray;
                        Double[] GpsLatArray;
                        UInt16   Orientation;
                        Double   GpsLongDouble;
                        Double   GpsLatDouble;
                        DateTime datePictureTaken;

                        if (reader.GetTagValue <Double[]>(ExifTags.GPSLongitude, out GpsLongArray) &&
                            reader.GetTagValue <Double[]>(ExifTags.GPSLatitude, out GpsLatArray) &&
                            reader.GetTagValue <DateTime>(ExifTags.DateTimeDigitized, out datePictureTaken) &&
                            reader.GetTagValue <UInt16>(ExifTags.Orientation, out Orientation))
                        {
                            GpsLongDouble = GpsLongArray[0] + GpsLongArray[1] / 60 + GpsLongArray[2] / 3600;
                            GpsLatDouble  = GpsLatArray[0] + GpsLatArray[1] / 60 + GpsLatArray[2] / 3600;

                            var record = from r in _db.Photos
                                         where r.Longitude == GpsLongDouble &&
                                         r.Latitude == GpsLatDouble &&
                                         r.PictureTaken == datePictureTaken
                                         orderby r.Id
                                         select r.Id;

                            if (record.Count() == 0)
                            {
                                _db.Photos.Add(new Photo {
                                    UserId       = WebSecurity.CurrentUserId,
                                    imgName      = newFileName,
                                    imgPath      = path,
                                    Longitude    = GpsLongDouble,
                                    Latitude     = GpsLatDouble,
                                    Orientation  = Orientation,
                                    PictureTaken = datePictureTaken
                                });

                                reader.Dispose();
                                System.IO.File.Move(tempPath, path);
                                Photo.Rotate(path);
                                _db.SaveChanges();
                                ViewBag.Message = "Photo uploaded successfully";
                            }
                            else
                            {
                                reader.Dispose();
                                System.IO.File.Delete(tempPath);
                                ViewBag.Message = "Photo already exists!";
                            }
                        }
                        else
                        {
                            reader.Dispose();
                            System.IO.File.Delete(tempPath);
                            ViewBag.Message = "The Photo does not contain GPS info!";
                        }
                    }
                }
                catch (Exception ex) {
                    System.IO.File.Delete(tempPath);
                    ViewBag.Message = ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }
            return(RedirectToAction("Index", "Photo", new { error = ViewBag.Message }));
        }