Exemplo n.º 1
0
        //public IActionResult Login(LoginDto model)
        //{
        public async Task <IActionResult> OnPostAsync()
        {
            LoginResponse logResponse = new LoginResponse();

            using (var client = new HttpClient())
            {
                //Passing service base url
                client.BaseAddress = new Uri(Baseurl);

                client.DefaultRequestHeaders.Clear();
                //Define request data format
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                string stringData  = JsonConvert.SerializeObject(item);
                var    contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json");

                //Sending request to find web api REST service resource GetAllEmployees using HttpClient
                HttpResponseMessage Res = client.PostAsync("api/Account/Login", contentData).Result;

                //Checking the response is successful or not which is sent using HttpClient
                if (Res.IsSuccessStatusCode)
                {
                    //Storing the response details recieved from web api
                    var loginRes = Res.Content.ReadAsStringAsync().Result;
                    logResponse.token = loginRes.ToString().Replace('"', ' ');

                    Tokenn.UserId = item.Email;

                    Tokenn.token = logResponse.token.ToString();
                    HttpContext.Session.Clear();
                    HttpContext.Session.SetString("token", Tokenn.token);
                    //save sql
                    _context.Token.Add(Tokenn);
                    await _context.SaveChangesAsync();

                    //save couchbase
                    _context.Token.Add(Tokenn);
                    //await _context.SaveChangesAsync();
                    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + logResponse.token);
                    HttpResponseMessage response = await client.PostAsJsonAsync("http://localhost:55226/api/AddToken", Tokenn);

                    response.EnsureSuccessStatusCode();


                    //Deserializing the response recieved from web api and storing into the Employee list
                    //logResponse.token =JsonConvert.DeserializeObject<LoginResponse>(loginRes);
                    //TempData["token"] = logResponse.token;
                    return(RedirectToPage("./Index"));
                }
                //returning the employee list to view
                //return View(logResponse);
                //return logResponse.token;
                return(RedirectToPage("./Login"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Movie.Add(Movie);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        //public async Task OnGetAsync()
        //{
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                //
                WishlistItem product = null;
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                HttpResponseMessage response = await client.GetAsync("http://localhost:55226/api/getall");

                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    //string unauth=  "Unauthorized" ;
                    //return unauth;
                    Console.Write("Unauthorized");
                }
                if (response.IsSuccessStatusCode)
                {
                    //var product1 = JsonConvert.DeserializeObject<WishlistItem>();
                    // product = await response.Content.ReadAsAsync <WishlistItem>();
                    var jsonString = await response.Content.ReadAsStringAsync();

                    var _Data = JsonConvert.DeserializeObject <List <WishlistItem> >(jsonString);
                    Movie = _Data.ToList();
                    //return _Data;

                    //IQueryable<string> genreQuery = from m in _context.WishlistItem orderby m.name select m.name;
                    var item = from m in _context.WishlistItem orderby m.name select m;

                    //var wishlist= _context.WishlistItem.AsEnumerable().SelectMany(row => row.ItemArray);
                    var item1 = Movie.Where(x => !(item.Select(z => z.id).Contains(x.id))).ToList().ConvertAll(z => new WishlistItem {
                        id = z.id, country = z.country, name = z.name, type = z.type
                    });

                    foreach (var i in item1)
                    {
                        _context.WishlistItem.Add(i);
                    }

                    await _context.SaveChangesAsync();

                    //return NotFound("UnAuthenticated");
                }
                return(RedirectToPage("./Index"));
                ////return NotFound("Successfully Synk Completed");
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                return(NotFound("Synk issue" + ex.Message));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Movie = await _context.Movie.FindAsync(id);

            if (Movie != null)
            {
                _context.Movie.Remove(Movie);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Movie).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(RedirectToPage("./Index"));
        }
        //public async Task OnGetAsync()
        //{
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                //
                WishlistItem product = null;
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                HttpResponseMessage response = await client.GetAsync("http://localhost:55226/api/getall");

                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    //string unauth=  "Unauthorized" ;
                    //return unauth;
                    Console.Write("Unauthorized");
                }
                if (response.IsSuccessStatusCode)
                {
                    //var product1 = JsonConvert.DeserializeObject<WishlistItem>();
                    // product = await response.Content.ReadAsAsync <WishlistItem>();
                    var jsonString = await response.Content.ReadAsStringAsync();

                    var _Data = JsonConvert.DeserializeObject <List <WishlistItem> >(jsonString);
                    Movie = _Data.ToList();
                    //return _Data;

                    _context.WishlistItem.Add(item);
                    await _context.SaveChangesAsync();
                }
                return(null);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                return(null);
            }
        }