Ejemplo n.º 1
0
 public static int AmountOfLike(this HtmlHelper help, Guid objectId)
 {
     using (BestPlaceEntities db = new BestPlaceEntities())
     {
         return(db.bp_Like_GetByObject(objectId).Count());
     }
 }
Ejemplo n.º 2
0
 public static List <bp_Photo> Photos(this HtmlHelper help, Guid placeId)
 {
     using (BestPlaceEntities db = new BestPlaceEntities())
     {
         return(db.bp_Photo_GetByPlace(placeId).ToList());
     }
 }
Ejemplo n.º 3
0
 public static int AmountOfArrived(this HtmlHelper help, Guid placeId)
 {
     using (BestPlaceEntities db = new BestPlaceEntities())
     {
         return(db.bp_Arrived_GetByPlaceId(placeId).Count());
     }
 }
Ejemplo n.º 4
0
 public static bp_Category GetCategory(this HtmlHelper help, int categoryId)
 {
     using (BestPlaceEntities db = new BestPlaceEntities())
     {
         return(db.bp_Category_GetById(categoryId).Single());
     }
 }
Ejemplo n.º 5
0
        public static bp_Profile GetProfile(this HtmlHelper help, Guid?userId)
        {
            if (!userId.HasValue)
            {
                userId = (Guid)Membership.GetUser().ProviderUserKey;
            }

            using (BestPlaceEntities db = new BestPlaceEntities())
            {
                return(db.bp_Profile_GetById(userId).Single());
            }
        }
Ejemplo n.º 6
0
 public static bool HasArrived(this HtmlHelper help, Guid userId, Guid placeId)
 {
     using (BestPlaceEntities db = new BestPlaceEntities())
     {
         if (db.bp_Arrived_GetByUserPlace(userId, placeId).Count() > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 7
0
 public static bool IsLike(this HtmlHelper help, Guid userId, Guid objectId)
 {
     using (BestPlaceEntities db = new BestPlaceEntities())
     {
         if (db.bp_Like_GetByUserAndObject(objectId, userId).Count() > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 8
0
        public static bp_Profile GetProfile(this HtmlHelper help, Guid?userId)
        {
            if (!userId.HasValue)
            {
                userId = (Guid)Membership.GetUser().ProviderUserKey;
            }

            using (BestPlaceEntities db = new BestPlaceEntities())
            {
                var profile = db.bp_Profile_GetById(userId).Single();
                if (profile.ThirdPartyId != "bp")
                {
                    profile.Avatar = String.Format("https://graph.facebook.com/{0}/picture", profile.ThirdPartyId);
                }
                else
                {
                    profile.Avatar = String.Format("/Content/CoverImages/{0}", profile.Avatar);
                }

                return(profile);
            }
        }
Ejemplo n.º 9
0
        //
        // GET: /Account/OAuth/

        public ActionResult OAuth(string code, string state)
        {
            FacebookOAuthResult oauthResult;

            if (FacebookOAuthResult.TryParse(Request.Url, out oauthResult))
            {
                if (oauthResult.IsSuccess)
                {
                    var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
                    oAuthClient.RedirectUri = new Uri(redirectUrl);

                    dynamic tokenResult = oAuthClient.ExchangeCodeForAccessToken(code);
                    string  accessToken = tokenResult.access_token;

                    DateTime expiresOn = DateTime.MaxValue;

                    if (tokenResult.ContainsKey("expires"))
                    {
                        DateTimeConvertor.FromUnixTime(tokenResult.expires);
                    }

                    FacebookClient fbClient   = new FacebookClient(accessToken);
                    dynamic        me         = fbClient.Get("me?fields=id,name,email,birthday,gender");
                    long           facebookId = Convert.ToInt64(me.id);

                    InMemoryUserStore.Add(new FacebookUser
                    {
                        AccessToken = accessToken,
                        Expires     = expiresOn,
                        FacebookId  = facebookId,
                        Name        = (string)me.name,
                    });

                    var user = Membership.GetUser(facebookId.ToString());

                    FormsAuthentication.SetAuthCookie(facebookId.ToString(), false);

                    string      format   = "d";
                    CultureInfo provider = CultureInfo.InvariantCulture;
                    DateTime    birthday = new DateTime();
                    try
                    {
                        birthday = DateTime.ParseExact(me.birthday, format, provider);
                    }
                    catch
                    {
                    }

                    if (user == null)
                    {
                        var u = Membership.CreateUser(facebookId.ToString(), Guid.NewGuid().ToString());
                        using (BestPlaceEntities db = new BestPlaceEntities())
                        {
                            db.bp_Profile_Create((Guid)u.ProviderUserKey,
                                                 facebookId.ToString(),
                                                 (string)me.name,
                                                 Transfer.GetPictureUrl(facebookId.ToString()),
                                                 (string)me.email,
                                                 null,
                                                 birthday,
                                                 ((string)me.gender == "male") ? true : false,
                                                 null, null);
                        }
                    }
                    else
                    {
                        using (BestPlaceEntities db = new BestPlaceEntities())
                        {
                            db.bp_Profile_Update((Guid)user.ProviderUserKey,
                                                 (string)me.name,
                                                 (string)me.email,
                                                 null,
                                                 birthday,
                                                 ((string)me.gender == "male") ? true : false,
                                                 null, null);
                        }
                    }

                    // prevent open redirection attack by checking if the url is local.
                    if (Url.IsLocalUrl(state))
                    {
                        return(Redirect(state));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }