From 7e168ca261d08acd16ec8b22e17022a616f9536e Mon Sep 17 00:00:00 2001 From: Jamie Duke Date: Mon, 5 Dec 2016 11:58:42 -0600 Subject: [PATCH 1/2] fixed navbar, redirect on logout, landing page, can add pmt type, log in validation --- .../Controllers/AccountController.cs | 4 +- .../Controllers/CustomersController.cs | 33 +++++++++- .../BangazonWebViewModels/BaseViewModel.cs | 61 ++++++++++--------- .../PaymentTypeViewModel.cs | 31 +++++----- .../ShoppingCartViewModel.cs | 14 +---- .../Views/Customers/Payment.cshtml | 2 +- .../Views/Shared/_Layout.cshtml | 8 +-- .../Views/Shared/_LoginPartial.cshtml | 8 +++ 8 files changed, 94 insertions(+), 67 deletions(-) diff --git a/src/BangazonUserAuth/Controllers/AccountController.cs b/src/BangazonUserAuth/Controllers/AccountController.cs index 7cc2e38..99762d1 100644 --- a/src/BangazonUserAuth/Controllers/AccountController.cs +++ b/src/BangazonUserAuth/Controllers/AccountController.cs @@ -159,7 +159,7 @@ public async Task LogOff() { await _signInManager.SignOutAsync(); _logger.LogInformation(4, "User logged out."); - return RedirectToAction(nameof(ProductsController.Index), "Home"); + return RedirectToAction(nameof(ProductsController.Index), ""); } // @@ -484,7 +484,7 @@ private IActionResult RedirectToLocal(string returnUrl) } else { - return RedirectToAction(nameof(ProductsController.Index), "Home"); + return RedirectToAction(nameof(ProductsController.Index), ""); } } diff --git a/src/BangazonUserAuth/Controllers/CustomersController.cs b/src/BangazonUserAuth/Controllers/CustomersController.cs index 5211b94..6d23c6d 100644 --- a/src/BangazonUserAuth/Controllers/CustomersController.cs +++ b/src/BangazonUserAuth/Controllers/CustomersController.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc.Rendering; namespace BangazonUserAuth.Controllers { @@ -77,6 +78,20 @@ public async Task ShoppingCart() model.Products = new List(); model.Products.Add(product); model.ActiveCustomerId = CustomerId; + model.ListOfPaymentTypes = context.PaymentType + .Where(pt => pt.CustomerId == CustomerId) + .AsEnumerable() + .Select(pt => new SelectListItem + { + Text = $"{pt.FirstName} {pt.LastName} {pt.Processor} {pt.ExpirationDate}", + Value = pt.PaymentTypeId.ToString() + }).ToList(); + + model.ListOfPaymentTypes.Insert(0, new SelectListItem + + { + Text = "Choose Payment Type" + }); return View(model); } @@ -92,6 +107,20 @@ public async Task ShoppingCart() CartTotal += context.Product.Where(p => p.ProductId == LineItemsOnActiveOrder[i].ProductId).SingleOrDefault().Price; } + model.ListOfPaymentTypes = context.PaymentType + .Where(pt => pt.CustomerId == CustomerId) + .AsEnumerable() + .Select(pt => new SelectListItem + { + Text = $"{pt.FirstName} {pt.LastName} {pt.Processor} {pt.ExpirationDate}", + Value = pt.PaymentTypeId.ToString() + }).ToList(); + + model.ListOfPaymentTypes.Insert(0, new SelectListItem + + { + Text = "Choose Payment Type" + }); model.CartTotal = CartTotal; model.Products = ListOfProducts; @@ -103,10 +132,12 @@ public async Task ShoppingCart() //Purpose of the Method: Method should take you to the Payment view with form to add Payment. //Arguments in Method: None. [HttpGet] - public IActionResult Payment() + public async Task Payment() { + var user = await GetCurrentUserAsync(); PaymentTypeViewModel model = new PaymentTypeViewModel(_userManager, newContext, context); + model.ActiveCustomerId = user.CustomerId; return View(model); } diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs index ea51ab1..e4b873e 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs @@ -25,36 +25,37 @@ public BaseViewModel(UserManager userManager, ApplicationDbCont } public BaseViewModel() { } - //private Task GetCurrentUserAsync() => _userManager.GetUserAsync(HttpContext.User); - //public string ShoppingCartItems { - // get { - // var user = GetCurrentUserAsync(); - // var ActiveCustomerId = user.CustomerId; - // Customer customer = context.Customer.Single(c => c.CustomerId == ActiveCustomerId) - + + //private Task GetCurrentUserAsync() => _userManager.GetUserAsync(HttpContext.User); + //public string ShoppingCartItems { + // get { + // var user = GetCurrentUserAsync(); + // var ActiveCustomerId = user.CustomerId; + // Customer customer = context.Customer.Single(c => c.CustomerId == ActiveCustomerId) - // if (customer == null) - // { - // // Return null because there should not be a number next to the link if a customer has not been chosen. - // return ""; - // } - // if (customer != null){ - // //If there is a customer but the customer does not have an active order then the shopping cart should have 0 items in it. - // Order order = context.Order.Where(o => o.CustomerId == customer.CustomerId && o.IsCompleted == false).SingleOrDefault(); - // if (order == null){ - // return " (0)"; - // } - // //If the user has an active order then the number of products in that order will be returned - // if (order != null){ - // List lineItems = context.LineItem.Where(l => l.OrderId == order.OrderId).ToList(); - // string shoppingCartCount = lineItems.Count.ToString(); - // return " ("+shoppingCartCount+")"; - // } - // } - // return ""; - // } - //} - - } + + // if (customer == null) + // { + // // Return null because there should not be a number next to the link if a customer has not been chosen. + // return ""; + // } + // if (customer != null){ + // //If there is a customer but the customer does not have an active order then the shopping cart should have 0 items in it. + // Order order = context.Order.Where(o => o.CustomerId == customer.CustomerId && o.IsCompleted == false).SingleOrDefault(); + // if (order == null){ + // return " (0)"; + // } + // //If the user has an active order then the number of products in that order will be returned + // if (order != null){ + // List lineItems = context.LineItem.Where(l => l.OrderId == order.OrderId).ToList(); + // string shoppingCartCount = lineItems.Count.ToString(); + // return " ("+shoppingCartCount+")"; + // } + // } + // return ""; + // } + //} + + } } diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/PaymentTypeViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/PaymentTypeViewModel.cs index 51e8d0c..b082662 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/PaymentTypeViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/PaymentTypeViewModel.cs @@ -1,17 +1,18 @@ -using BangazonUserAuth.Models; -using BangazonUserAuth.Data; +using BangazonUserAuth.Models; +using BangazonUserAuth.Data; using Microsoft.AspNetCore.Identity; -namespace BangazonUserAuth.ViewModels -{ - //Class Name: PaymentTypeViewModel - //Author: Grant Regnier - //Purpose of the class: The purpose of this class is to pass the type of PaymentType to the view for our payment form to model from. - //Methods in Class: None. - public class PaymentTypeViewModel : BaseViewModel - { - public PaymentType PaymentType { get; set; } - - public PaymentTypeViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) { } - } -} +namespace BangazonUserAuth.ViewModels +{ + //Class Name: PaymentTypeViewModel + //Author: Grant Regnier + //Purpose of the class: The purpose of this class is to pass the type of PaymentType to the view for our payment form to model from. + //Methods in Class: None. + public class PaymentTypeViewModel : BaseViewModel + { + public PaymentType PaymentType { get; set; } + public int ActiveCustomerId { get; set; } + + public PaymentTypeViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) { } + } +} diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs index baa6e4c..114b409 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs @@ -31,19 +31,7 @@ public ShoppingCartViewModel(UserManager userManager, Applicati _userManager = userManager; newContext = ctx1; context = ctx2; - this.ListOfPaymentTypes = context.PaymentType - .Where(pt => pt.CustomerId == ActiveCustomerId) - .AsEnumerable() - .Select(pt => new SelectListItem - { - Text = $"{pt.FirstName} {pt.LastName} {pt.Processor} {pt.ExpirationDate}", - Value = pt.PaymentTypeId.ToString() - }).ToList(); - - this.ListOfPaymentTypes.Insert(0, new SelectListItem - { - Text = "Choose Payment Type" - }); + } } } \ No newline at end of file diff --git a/src/BangazonUserAuth/Views/Customers/Payment.cshtml b/src/BangazonUserAuth/Views/Customers/Payment.cshtml index 47e40c5..82f1882 100644 --- a/src/BangazonUserAuth/Views/Customers/Payment.cshtml +++ b/src/BangazonUserAuth/Views/Customers/Payment.cshtml @@ -11,7 +11,7 @@
- +
diff --git a/src/BangazonUserAuth/Views/Shared/_Layout.cshtml b/src/BangazonUserAuth/Views/Shared/_Layout.cshtml index 26685c2..d5527c3 100644 --- a/src/BangazonUserAuth/Views/Shared/_Layout.cshtml +++ b/src/BangazonUserAuth/Views/Shared/_Layout.cshtml @@ -29,11 +29,7 @@ BangazonWeb
@@ -50,6 +46,8 @@ + +