Esempio n. 1
0
        public static SlinkUser Create()
        {
            var returnUser = new SlinkUser();

            var userid = ServiceLocator.Instance.Resolve <IPersistantStorage>().GetUserId();

            returnUser.ID = userid;

            var realm = RealmManager.SharedInstance.GetRealm(null);

            realm.Write(() =>
            {
                realm.Add(returnUser);
            });
            return(returnUser);
        }
Esempio n. 2
0
        public static SlinkUser GetMe(bool shouldCreateNewUserIfNull)
        {
            if (User.Current == null)
            {
                return(null);
            }

            var userid = ServiceLocator.Instance.Resolve <IPersistantStorage>().GetUserId();

            if (String.IsNullOrEmpty(userid))
            {
                return(null);
            }

            var realm = RealmManager.SharedInstance.GetRealm(null);
            var me    = realm.All <SlinkUser>().Where(d => d.ID.Equals(userid, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (me == null && shouldCreateNewUserIfNull)
            {
                me = SlinkUser.Create();
            }

            return(me);
        }
Esempio n. 3
0
            static ExchangeTransaction ParseTransaction(JToken token, List <Card> itemsToIgnore)
            {
                if (token == null)
                {
                    return(null);
                }
                if (token["id"] == null)
                {
                    return(null);
                }
                if (token["card"] == null)
                {
                    return(null);
                }
                if (token["lat"] == null)
                {
                    return(null);
                }
                if (token["lng"] == null)
                {
                    return(null);
                }

                var cardToken = token["card"];

                if (cardToken == null)
                {
                    return(null);
                }

                //check if we should ignore it
                var uuid = (string)cardToken["uuid"];

                if (itemsToIgnore.Any(c => c.UUID.Equals(uuid, StringComparison.OrdinalIgnoreCase)))
                {
                    return(null);
                }


                string id = (string)token["id"];

                if (String.IsNullOrEmpty(id))
                {
                    return(null);
                }

                ExchangeTransaction transaction = new ExchangeTransaction();

                transaction.UUID        = id;
                transaction.Latitidue   = (double)token["lat"];
                transaction.Longitude   = (double)token["lng"];
                transaction.AccessToken = (string)cardToken["accessKey"];

                var realm = RealmManager.SharedInstance.GetRealm(null);

                realm.Write(() =>
                {
                    var user        = new SlinkUser();
                    user.ID         = (string)token["facebookId"];
                    user.FacebookID = (string)token["facebookId"];
                    user.Name       = (string)cardToken["name"];
                    realm.Add(user, true);

                    //fetch fresh copy
                    //this is needed in case you get a user already with one card in in Connections
                    user       = realm.All <SlinkUser>().Where(c => c.ID.Equals(user.ID, StringComparison.OrdinalIgnoreCase)).First();
                    var before = user.Cards.Count();

                    var card                  = new Card();
                    card.UUID                 = uuid;
                    card.Name                 = (string)cardToken["name"];
                    card.UserDisplayName      = (string)cardToken["userDisplayName"];
                    card.Title                = (string)cardToken["title"];
                    card.BorderColor          = (string)cardToken["borderColor"];
                    card.BackgroundColor      = (string)cardToken["backgroundColor"];
                    card.CompanyName          = (string)cardToken["companyName"];
                    card.CompanyNameTextColor = (string)cardToken["companyNameTextColor"];
                    card.AccessToken          = (string)cardToken["accessKey"];
                    card.Owner                = user;

                    var after = user.Cards.Count();

                    var outlets = cardToken["outlets"] as JArray;
                    if (outlets != null)
                    {
                        foreach (var outlet in outlets)
                        {
                            var o    = new Outlet();
                            o.Name   = (string)outlet["name"];
                            o.Type   = (string)outlet["type"];
                            o.Handle = (string)outlet["handle"];
                            o.Card   = card;
                            card.Outlets.Add(o);
                        }
                    }
                    realm.Add(card, true);

                    transaction.Card   = card;
                    transaction.Person = user;
                });

                return(transaction);
            }