public async Task <IActionResult> Index() { User user = await _userIdentity.GetCurrentAsync(); if (user == null) { return(NotFound()); } ProfileVM model = new ProfileVM() { EditProfileVM = new ProfileVM.EditProfileSubVM() { FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, CurrentEmail = user.EmailAddress, PhoneNumber = user.PhoneNumber }, EditPasswordVM = new ProfileVM.EditPasswordSubVM(), EditPreferencesVM = new ProfileVM.EditPreferencesSubVM() { Currency = user.Currency, Theme = user.Theme } }; ViewData["SupportedCurrencies"] = new SelectList(_clientCurrency.Options.SupportedCurrencies, nameof(Currency.Code), nameof(Currency.Code)); ViewData["SupportedThemes"] = new SelectList(_clientTheme.Options.SupportedThemes, nameof(Theme.ID), nameof(Theme.DisplayName)); ViewData["UserFullName"] = $"{user.FirstName} {user.LastName}"; return(View(model)); }
/// <summary> /// Gets the theme of the user by the database (for an authenticated user). /// </summary> /// <returns>Returns the theme of the user by the database if found and supported, otherwise null.</returns> private async Task <Theme> GetUserThemeByDatabase() { User user = await _userIdentity.GetCurrentAsync(); if (user != null) { return(this.GetSupportedThemeOrNull(user.Theme)); } return(null); }
public async Task <IActionResult> Index() { User user = await _userIdentity.GetCurrentAsync(); if (user == null) { return(NotFound()); } List <Order> orders = await _users.GetOrdersAsync(user.Id); ViewData["UserFullName"] = $"{user.FirstName} {user.LastName}"; return(View(orders)); }
public async Task <IActionResult> Index() { User user = await _userIdentity.GetCurrentAsync(); if (user == null) { return(NotFound()); } List <UserWishlistProduct> wishlist = await _users.GetWishlistAsync(user.Id); ViewData["UserFullName"] = $"{user.FirstName} {user.LastName}"; return(View(wishlist)); }
public async Task <IActionResult> Contact(string subject) { ContactVM model = new ContactVM() { Subject = subject }; User user = await _userIdentity.GetCurrentAsync(); if (user != null) { model.FirstName = user.FirstName; model.LastName = user.LastName; model.EmailAddress = user.EmailAddress; } return(View(model)); }
/// <summary> /// Sets (adds or updates) the specified product and quantity in the cart. /// </summary> /// <param name="productId">The id of the product to set.</param> /// <param name="quantity">The quantity to set.</param> public async Task SetProductAsync(int productId, int quantity) { if (quantity < 1) { throw new ArgumentException($"{nameof(quantity)} cannot be less than 1.", nameof(quantity)); } // First, checks the product exists and valid in the database: if (!await _dbContext.Products.AnyAsync(p => p.Id == productId && p.IsAvailable)) { return; } // Creates/Updates the cart: // Now, checks if it's the first item in the cart: if (this.IsEmpty()) { // So creates a new cart: this.Cart = new ClientCart(); this.Cart.Products = new List <ClientCartProduct>(); ClientCartProduct cartProduct = new ClientCartProduct() { ClientCart = Cart, ProductId = productId, Quantity = quantity }; this.Cart.Products.Add(cartProduct); _dbContext.ClientCarts.Add(this.Cart); } // Otherwise, it's not the first item: else { // Checks if the product already exists in the cart: ClientCartProduct cartProduct = this.Cart.Products.FirstOrDefault(p => p.ProductId == productId); if (cartProduct != null) { // Updates the item: cartProduct.Quantity = quantity; _dbContext.ClientCartProducts.Update(cartProduct); } else { // Adds the item: cartProduct = new ClientCartProduct() { ClientCartId = this.Cart.Id, ProductId = productId, Quantity = quantity }; _dbContext.ClientCartProducts.Add(cartProduct); } } // If the user is authenticated - connects the cart to him: User user = await _userIdentity.GetCurrentAsync(); if (user != null && user.ClientCartId == null) { user.ClientCart = this.Cart; _dbContext.Users.Update(user); } await _dbContext.SaveChangesAsync(); // Gets the cart back from the database: ClientCart clientCartBack = null; if (user != null) { clientCartBack = Task.Run(() => GetAuthUserCartByDatabase()).Result; user.ClientCartId = clientCartBack.Id; _userCache.Set(user); this.CacheAuthUserCart(user.Id, clientCartBack); } else { clientCartBack = Task.Run(() => GetClientCartByDatabase(this.Cart.Id)).Result; this.CacheClientCart(clientCartBack); } // If user is anonymous - sets his cart id to the cookie: if (_httpContextAccessor.HttpContext.User.Identity.IsAuthenticated == false) { this.SetUserCartIdToCookie(this.Cart.Id); } }
public async Task <IActionResult> Checkout() { if (_clientCart.IsEmpty()) { return(NotFound()); } CheckoutVM model = new CheckoutVM() { ShippingDetails = new CheckoutVM.ShippingDetailsModel() { ShippingSameAsBilling = true } }; if (_userIdentity.IsAuthenticated()) { // Checks to set already known information about the user in the checkout: User user = await _userIdentity.GetCurrentAsync(); model.BillingDetails = new CheckoutVM.BillingDetailsModel() { Name = $"{user.FirstName} {user.LastName}", Phone = user.PhoneNumber }; if (user.Address != null) { model.BillingDetails.Street = user.Address.Street; model.BillingDetails.PostalCode = user.Address.PostalCode; model.BillingDetails.City = user.Address.City; model.BillingDetails.Country = user.Address.Country; } } else { model.SignMethod = SignMethod.Login; model.LoginVM = new CheckoutVM.ConditionalLoginVM() { RememberMe = true }; model.RegisterVM = new CheckoutVM.ConditionalRegisterVM(); } // TODO: for testing: //model.BillingDetails = new CheckoutVM.BillingDetailsModel() //{ // Name = "A B", // Phone = "0541234567", // Street = "ABC", // PostalCode = "12345", // City = "New York", // Country = "USA" //}; //model.CreditCard = new CheckoutVM.CreditCardInfo() //{ // CardNumber = "123456789", // CardExpiryDate = "04/23", // CardHolderName = "A B", // CardSecurityCode = "444" //}; //model.DeliveryMethodId = 4; ViewData["DeliveryMethods"] = await _dbContext.DeliveryMethods.OrderBy(dm => dm.Price).ToListAsync(); return(View(model)); }