Ejemplo n.º 1
0
        public static async void __NavigateToProfile(LinkedInResponse profile)
        {
            if (profile == null)
            {
                Application.Current.MainPage = new NavigationPage(new LoginPage());
                return;
            }

            var apiService  = new ApiService();
            var dataService = new DataService();

            var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            var token       = await apiService.LoginLinkedIn(
                apiSecurity,
                "/api",
                "/Users/LoginLinkedIn",
                profile);

            if (token == null)
            {
                Application.Current.MainPage = new NavigationPage(new LoginPage());
                return;
            }
            toProcessUser(token);
        }
Ejemplo n.º 2
0
        public async Task <TokenResponse> LoginLinkedIn(
            string urlBase,
            string servicePrefix,
            string controller,
            LinkedInResponse profile)
        {
            try
            {
                var request = JsonConvert.SerializeObject(profile);
                var content = new StringContent(
                    request,
                    Encoding.UTF8,
                    "application/json");
                var client = new HttpClient();
                client.BaseAddress = new Uri(urlBase);
                var url      = string.Format("{0}{1}", servicePrefix, controller);
                var response = await client.PostAsync(url, content);

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }

                var tokenResponse = await GetToken(
                    urlBase,
                    profile.Id,
                    profile.Id);

                return(tokenResponse);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Load synchronously.  Call with a await Task.Run(()=>LoadAllGroups()); to run async.
 /// </summary>
 protected void LoadAllGroups()
 {
     if (haveAccessToken)
     {
         LinkedInGetGroupOptions options = new LinkedInGetGroupOptions();
         options.GroupOptions.SelectAll();
         LinkedInResponse <IEnumerable <LinkedInGroup> > groupResult = linkedInClient.GetMemberGroups(options);
         groupResult.Result.ForEach(g => groups[g.Id] = g);
     }
 }
Ejemplo n.º 4
0
        protected void ShowMemberGroups(LinkedInResponse <IEnumerable <LinkedInGroup> > result)
        {
            tvGroups.Nodes.Clear();

            foreach (LinkedInGroup group in result.Result)
            {
                TreeNode node = tvGroups.Nodes.Add(group.Name);
                node.Tag = group;
            }
        }
Ejemplo n.º 5
0
        public async Task <IHttpActionResult> LoginLinkedIn(LinkedInResponse profile)
        {
            try
            {
                var user = await db.Users.Where(u => u.Email == profile.Id).FirstOrDefaultAsync();

                if (user == null)
                {
                    user = new User
                    {
                        Email      = profile.Id,
                        FirstName  = profile.FirstName,
                        LastName   = profile.LastName,
                        ImagePath  = profile.PictureUrl,
                        UserTypeId = 6,
                        Telephone  = "...",
                    };

                    db.Users.Add(user);
                    UsersHelper.CreateUserASP(profile.Id, "User", profile.Id);
                }
                else
                {
                    user.FirstName       = profile.FirstName;
                    user.LastName        = profile.LastName;
                    user.ImagePath       = profile.PictureUrl;
                    db.Entry(user).State = EntityState.Modified;
                }

                await db.SaveChangesAsync();

                return(Ok(true));
            }
            catch (DbEntityValidationException e)
            {
                var message = string.Empty;
                foreach (var eve in e.EntityValidationErrors)
                {
                    message = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        message += string.Format("\n- Property: \"{0}\", Error: \"{1}\"",
                                                 ve.PropertyName, ve.ErrorMessage);
                    }
                }

                return(BadRequest(message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public void LKI_LoadGroups()
        {
            if (haveAccessToken)
            {
                LinkedInGetGroupOptions options = new LinkedInGetGroupOptions();
                options.GroupOptions.SelectAll();

                LinkedInResponse <IEnumerable <LinkedInGroup> > result = linkedInClient.GetMemberGroups(options);

                if (result.Result != null && result.Status == LinkedInResponseStatus.OK)
                {
                    //ShowMemberGroups(result);
                }
            }
        }
Ejemplo n.º 7
0
        protected async void LoadGroups()
        {
            if (haveAccessToken)
            {
                tvGroups.Nodes.Clear();
                tvGroups.Nodes.Add("Loading...");
                LinkedInGetGroupOptions options = new LinkedInGetGroupOptions();
                options.GroupOptions.SelectAll();

                LinkedInResponse <IEnumerable <LinkedInGroup> > result = await Task.Run(() => linkedInClient.GetMemberGroups(options));

                if (result.Result != null && result.Status == LinkedInResponseStatus.OK)
                {
                    ShowMemberGroups(result);
                }
                else
                {
                    ReRun(result.Status, result.Message);
                }
            }
        }