public IActionResult GetListUser() { if (User.Identity.Name == null) { return(RedirectToAction("Index", "NotFound")); } else { return(View(userService.GetUsers())); } }
public IActionResult Cart(Order order) { var newOrder = new Order(); newOrder.OrderDetails = new List <OrderDetail>(); Random random = new Random(); foreach (var orderDetail in order.OrderDetails) { newOrder.OrderDetails.Add(new OrderDetail { PartId = orderDetail.Part.PartId, Price = orderDetail.Part.Pricee, Quantity = orderDetail.Quantity, Part = null }); } newOrder.Number = random.Next(1000, 100000).ToString(); newOrder.Date = DateTime.Now; newOrder.Amount = order.OrderDetails.Sum(a => a.Price * a.Quantity); newOrder.PartnerId = order.PartnerId; newOrder.Address = order.Address; newOrder.StatusId = statusService.GetStatuss().FirstOrDefault().StatusId; newOrder.UserId = userService.GetUsers().FirstOrDefault(u => u.UserName == User.Identity.Name).Id; newOrder.Partner = null; newOrder.Status = null; newOrder.User = null; ordersService.AddOrder(newOrder); HttpContext.Session.SetString("itemsToCart", string.Empty); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new User { UserName = Input.Email, Email = Input.Email }; user.EmailConfirmed = true; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { if (userDatabaseService.GetUsers().Count() == 1) { await _userManager.AddToRoleAsync(user, "Admin"); } _logger.LogInformation("Потребителя създаде нов акаунт с парола."); //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); //var callbackUrl = Url.Page( // "/Account/ConfirmEmail", // pageHandler: null, // values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl }, // protocol: Request.Scheme); //await _emailSender.SendEmailAsync(Input.Email, "Потвърди своя имейл", // $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); //if (_userManager.Options.SignIn.RequireConfirmedAccount) //{ // return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }); //} //else //{ _userManager.AddToRoleAsync(user, "User").Wait(); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); //} } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }