Пример #1
0
        public async Task <ActionResult> Edit(int id)
        {
            ApiTransactions apiTransactions       = new ApiTransactions();
            IEnumerable <SirketViewModel> sirkets = await apiTransactions.tumSirketleriGetir();

            IEnumerable <GorevViewModel> gorevs = await apiTransactions.tumGorevleriGetir();

            KullaniciViewModel kullanici = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiBaseAddress);

                var httpResponse = await client.GetAsync($"Kullanici/{id}");

                if (httpResponse.IsSuccessStatusCode)
                {
                    kullanici = await httpResponse.Content.ReadAsAsync <KullaniciViewModel>();

                    kullanici.SirketViewModel = sirkets;
                    kullanici.GorevViewModel  = gorevs;
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Server error.");
                }
            }
            if (kullanici == null)
            {
                return(HttpNotFound());
            }
            return(View(kullanici));
        }
Пример #2
0
        public async Task <ActionResult> Index()
        {
            ApiTransactions apiTransactions = new ApiTransactions();

            IEnumerable <GorevViewModel> gorevs = await apiTransactions.tumGorevleriGetir();

            return(View(gorevs));
        }
Пример #3
0
        public async Task <ActionResult> Create()
        {
            ApiTransactions apiTransactions       = new ApiTransactions();
            IEnumerable <SirketViewModel> sirkets = await apiTransactions.tumSirketleriGetir();

            IEnumerable <GorevViewModel> gorevs = await apiTransactions.tumGorevleriGetir();

            var model = new CreateKullaniciViewModel();

            model.GorevViewModel  = gorevs;
            model.SirketViewModel = sirkets;
            return(View(model));
        }
Пример #4
0
        private bool InitializeUserProfileInfo(ExternalLoginInfo loginInfo, string userId, string provider = null)
        {
            bool        result    = false;
            Claim       claim     = null;
            dynamic     response  = null;
            UserProfile profile   = null;
            string      targetUrl = "";

            try
            {
                if (string.IsNullOrEmpty(provider))
                {
                    provider = loginInfo.Login.LoginProvider;
                }

                if (provider.ToLower() == SysConstants.LoginProvider_Google)
                {
                    claim = GetClaim(loginInfo, SysConstants.AccessToken_Google);
                    var dict = new Dictionary <string, object>();

                    dict.Add("access_token", claim.Value);
                    targetUrl = $"https://www.googleapis.com/oauth2/v2/userinfo?access_token={claim.Value}";
                    response  = ApiTransactions.GetExtraAuthData(targetUrl);

                    if (response.error != null)
                    {
                        //TODO error
                        return(false);
                    }

                    profile = new UserProfile();

                    profile.GivenName   = response.given_name;
                    profile.FamilyName  = response.family_name;
                    profile.PicturePath = response.picture;
                    profile.UserId      = userId;
                    profile.IsActive    = true;

                    // profileService.Edit(profile);

                    result = true;
                }

                if (provider.ToLower() == SysConstants.LoginProvider_Facebook)
                {
                    result = true;

                    //TODO init facebook
                }

                if (provider.ToLower() == SysConstants.LoginProvider_Vk)
                {
                    var accessToken = GetClaim(loginInfo, SysConstants.AccessToken_Vk);
                    var vk_userId   = GetClaim(loginInfo, "user_id");

                    targetUrl = $"https://api.vk.com/method/users.get?id={vk_userId}&access_token={accessToken.Value}&fields=photo_200";
                    response  = ApiTransactions.GetExtraAuthData(targetUrl);

                    if (response.error_code != null)
                    {
                        //TODO response user about error
                        return(false);
                    }

                    profile = new UserProfile();

                    //TODO init vk user profile

                    result = true;
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }