public RedirectToActionResult Delete(int Id) { var order = _context.ExactOrders .Include(nameof(ExactOrder.Lines) + "." + nameof(ExactOrderLine.Item)) .FirstOrDefault(x => x.Id == Id); if (order == null) { return(RedirectToAction(nameof(Index), new { sm = StateMessage.FailedOrderDoesNotExist })); } _context.ExactOrders .Remove(order); _context.SaveChanges(); return(RedirectToAction(nameof(Index), new { sm = StateMessage.SuccessRemovedOrder })); }
public async Task <IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (remoteError != null) { ErrorMessage = $"Error from external provider: {remoteError}"; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { ErrorMessage = "Error loading external login information."; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } // Sign in the user with this external login provider if the user already has a login. var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent : false, bypassTwoFactor : true); if (result.Succeeded) { // Store new retrieved token // Check if already exists var user = _context.Users .Include(nameof(VERPS.WebApp.Database.Models.User.ExactToken)) .FirstOrDefault(x => x.UserName == info.ProviderKey); if (user != null) { var token = _context.ExactTokens .FirstOrDefault(x => x.Id == user.ExactToken.Id); token.Token = info.AuthenticationTokens.FirstOrDefault(x => x.Name == "access_token").Value; token.RefreshToken = info.AuthenticationTokens.FirstOrDefault(x => x.Name == "refresh_token").Value; token.RefreshTime = DateTime.Parse(info.AuthenticationTokens.FirstOrDefault(x => x.Name == "expires_at").Value); _context.SaveChanges(); } else { await _signInManager.SignOutAsync(); } _logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider); return(LocalRedirect(returnUrl)); } if (result.IsLockedOut) { return(RedirectToPage("./Lockout")); } else { _logger.LogInformation($"Not existing account, will create new account of user {info.Principal.Identity.Name} on provider {info.LoginProvider} "); // If the user does not have an account, then ask the user to create an account. ReturnUrl = returnUrl; LoginProvider = info.LoginProvider; // Set Exact things var exactHelper = new ExactHelper(); ExactOnlineConnect.data.AccessToken = info.AuthenticationTokens.FirstOrDefault(x => x.Name == "access_token").Value; ExactOnlineConnect.data.Context = _context; var me = await ExactOnlineConnect.data.GetMe(); ExactOnlineConnect.data.CurrentDivision = me.CurrentDivision; // Data var suppliers = await ExactOnlineConnect.data.GetSuppliers(me.CurrentDivision); var divisions = await ExactOnlineConnect.data.GetDivisions(me.CurrentDivision); var paymentConditions = await ExactOnlineConnect.data.GetPaymentConditions(me.CurrentDivision); // SelectLists var sups = exactHelper.SuppliersToSelectList(suppliers); var divs = divisions != null?exactHelper.DivisionsToSelectList(divisions) : new List <SelectListItem>(); var paycs = exactHelper.PaymentConditionsToSelectList(paymentConditions); // Model Input = new InputModel { Suppliers = sups, Divisions = divs, DivisionId = me.CurrentDivision, PaymentConditions = paycs, ProviderName = info.LoginProvider, UserId = me.UserID, Username = me.UserName, }; return(Page()); } }
public async Task <T> Get <T>(string urlModification, bool needToken = true, bool isSingle = true) { var tokenContext = _context.ExactTokens .FirstOrDefault(x => x.Token == _accessToken); if (tokenContext != null) { var refResults = await _service.TokenCheck(tokenContext.Token, tokenContext.RefreshToken, tokenContext.RefreshTime.ToString()); if (refResults != null) { _accessToken = refResults.AccessToken; _refreshToken = refResults.RefreshToken; tokenContext.Token = _accessToken; tokenContext.RefreshToken = _refreshToken; tokenContext.RefreshTime = refResults.ExpireryTime; _context.SaveChanges(); } } using (var client = new HttpClient()) { using (var request = new HttpRequestMessage(HttpMethod.Get, _baseURL + _latestVersion + urlModification)) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); if (needToken) { if (_accessToken == "") { return(default(T)); } request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken); } using (HttpResponseMessage response = await client.SendAsync(request)) { var output = response.Content.ReadAsStringAsync(); // TODO: REFRESHtOKEN CHECK string json = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK) { var res = JsonConvert.DeserializeObject <dynamic>(json); var check = Convert.ToString(res.d["results"]); if (check != "[]") // TEMP CHECK { if (!isSingle) { var result = Convert.ToString(res.d["results"]); return(JsonConvert.DeserializeObject <T>(result)); } var ok = Convert.ToString(res.d["results"][0]); return(JsonConvert.DeserializeObject <T>(ok)); } return(default(T)); } } return(default(T)); } } }