diff --git a/src/BangazonUserAuth/Migrations/ApplicationDbContextModelSnapshot.cs b/src/BangazonUserAuth/BangazonUserAuth/Data/Migrations/ApplicationDbContextModelSnapshot.cs similarity index 50% rename from src/BangazonUserAuth/Migrations/ApplicationDbContextModelSnapshot.cs rename to src/BangazonUserAuth/BangazonUserAuth/Data/Migrations/ApplicationDbContextModelSnapshot.cs index b776541..9263f98 100644 --- a/src/BangazonUserAuth/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/BangazonUserAuth/BangazonUserAuth/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,215 +1,425 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using BangazonUserAuth.Data; - -namespace BangazonUserAuth.Data.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - partial class ApplicationDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.1") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("BangazonUserAuth.Models.ApplicationUser", b => - { - b.Property("Id"); - - b.Property("AccessFailedCount"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("CustomerId"); - - b.Property("Email") - .HasAnnotation("MaxLength", 256); - - b.Property("EmailConfirmed"); - - b.Property("LockoutEnabled"); - - b.Property("LockoutEnd"); - - b.Property("NormalizedEmail") - .HasAnnotation("MaxLength", 256); - - b.Property("NormalizedUserName") - .HasAnnotation("MaxLength", 256); - - b.Property("PasswordHash"); - - b.Property("PhoneNumber"); - - b.Property("PhoneNumberConfirmed"); - - b.Property("SecurityStamp"); - - b.Property("TwoFactorEnabled"); - - b.Property("UserName") - .HasAnnotation("MaxLength", 256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasName("UserNameIndex"); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole", b => - { - b.Property("Id"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("Name") - .HasAnnotation("MaxLength", 256); - - b.Property("NormalizedName") - .HasAnnotation("MaxLength", 256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .HasName("RoleNameIndex"); - - b.ToTable("AspNetRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("RoleId") - .IsRequired(); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("UserId") - .IsRequired(); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => - { - b.Property("LoginProvider"); - - b.Property("ProviderKey"); - - b.Property("ProviderDisplayName"); - - b.Property("UserId") - .IsRequired(); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => - { - b.Property("UserId"); - - b.Property("RoleId"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken", b => - { - b.Property("UserId"); - - b.Property("LoginProvider"); - - b.Property("Name"); - - b.Property("Value"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") - .WithMany("Claims") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => - { - b.HasOne("BangazonUserAuth.Models.ApplicationUser") - .WithMany("Claims") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => - { - b.HasOne("BangazonUserAuth.Models.ApplicationUser") - .WithMany("Logins") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") - .WithMany("Users") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("BangazonUserAuth.Models.ApplicationUser") - .WithMany("Roles") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using BangazonUserAuth.Data; + +namespace BangazonUserAuth.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.1") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("BangazonUserAuth.Models.ApplicationUser", b => + { + b.Property("Id"); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasAnnotation("MaxLength", 256); + + b.Property("EmailConfirmed"); + + b.Property("FirstName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("LastName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedUserName") + .HasAnnotation("MaxLength", 256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.LineItem", b => + { + b.Property("LineItemId") + .ValueGeneratedOnAdd(); + + b.Property("OrderId"); + + b.Property("ProductId"); + + b.HasKey("LineItemId"); + + b.HasIndex("OrderId"); + + b.HasIndex("ProductId"); + + b.ToTable("LineItem"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Order", b => + { + b.Property("OrderId") + .ValueGeneratedOnAdd(); + + b.Property("DateCompleted"); + + b.Property("DateCreated") + .ValueGeneratedOnAddOrUpdate() + .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); + + b.Property("IsCompleted"); + + b.Property("PaymentTypeId"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("OrderId"); + + b.HasIndex("PaymentTypeId"); + + b.HasIndex("UserId"); + + b.ToTable("Order"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.PaymentType", b => + { + b.Property("PaymentTypeId") + .ValueGeneratedOnAdd(); + + b.Property("CardNumber") + .IsRequired(); + + b.Property("City") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("ExpirationDate") + .IsRequired(); + + b.Property("FirstName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("LastName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("Processor") + .IsRequired() + .HasAnnotation("MaxLength", 25); + + b.Property("State") + .IsRequired() + .HasAnnotation("MaxLength", 2); + + b.Property("StreetAddress") + .IsRequired() + .HasAnnotation("MaxLength", 80); + + b.Property("UserId") + .IsRequired(); + + b.Property("ZipCode"); + + b.HasKey("PaymentTypeId"); + + b.HasIndex("UserId"); + + b.ToTable("PaymentType"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Product", b => + { + b.Property("ProductId") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated") + .ValueGeneratedOnAddOrUpdate() + .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); + + b.Property("Description") + .IsRequired() + .HasAnnotation("MaxLength", 255); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.Property("Price"); + + b.Property("SubProductTypeId"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("ProductId"); + + b.HasIndex("SubProductTypeId"); + + b.HasIndex("UserId"); + + b.ToTable("Product"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.ProductType", b => + { + b.Property("ProductTypeId") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired(); + + b.HasKey("ProductTypeId"); + + b.ToTable("ProductType"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.SubProductType", b => + { + b.Property("SubProductTypeId") + .ValueGeneratedOnAdd(); + + b.Property("Description") + .IsRequired() + .HasAnnotation("MaxLength", 255); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.Property("ProductTypeId"); + + b.HasKey("SubProductTypeId"); + + b.ToTable("SubProductType"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole", b => + { + b.Property("Id"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.LineItem", b => + { + b.HasOne("BangazonUserAuth.Models.Order", "Order") + .WithMany() + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BangazonUserAuth.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Order", b => + { + b.HasOne("BangazonUserAuth.Models.PaymentType", "PaymentType") + .WithMany() + .HasForeignKey("PaymentTypeId"); + + b.HasOne("BangazonUserAuth.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.PaymentType", b => + { + b.HasOne("BangazonUserAuth.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Product", b => + { + b.HasOne("BangazonUserAuth.Models.SubProductType", "SubProductType") + .WithMany() + .HasForeignKey("SubProductTypeId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BangazonUserAuth.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.HasOne("BangazonUserAuth.Models.ApplicationUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.HasOne("BangazonUserAuth.Models.ApplicationUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Users") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BangazonUserAuth.Models.ApplicationUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/BangazonUserAuth/Controllers/AccountController.cs b/src/BangazonUserAuth/Controllers/AccountController.cs index 7cc2e38..ad56edc 100644 --- a/src/BangazonUserAuth/Controllers/AccountController.cs +++ b/src/BangazonUserAuth/Controllers/AccountController.cs @@ -24,7 +24,6 @@ public class AccountController : Controller private readonly ISmsSender _smsSender; private readonly ILogger _logger; private ApplicationDbContext newContext; - private BangazonWebContext context; public AccountController( UserManager userManager, @@ -32,8 +31,7 @@ public AccountController( IEmailSender emailSender, ISmsSender smsSender, ILoggerFactory loggerFactory, - ApplicationDbContext ctx1, - BangazonWebContext ctx2) + ApplicationDbContext ctx1) { _userManager = userManager; _signInManager = signInManager; @@ -41,7 +39,6 @@ public AccountController( _smsSender = smsSender; _logger = loggerFactory.CreateLogger(); newContext = ctx1; - context = ctx2; } @@ -113,22 +110,14 @@ public async Task Register(RegisterViewModel model, string return ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { - //Create a new customer with first and last name properties - Customer customer = new Customer(); - customer.FirstName = model.FirstName; - customer.LastName = model.LastName; - //Create a new Customer Controller instance - //Use the new Customer method to post the Customer instance to the old database - //Get the Customer Id back - CustomersController customersController = new CustomersController(_userManager, newContext, context); - int ActiveCustomerId = customersController.New(customer); //Set the customer Id on the new Application User //Resume logic that's already written var user = new ApplicationUser { - CustomerId = ActiveCustomerId, UserName = model.Email, - Email = model.Email + Email = model.Email, + FirstName = model.FirstName, + LastName = model.LastName }; var result = await _userManager.CreateAsync(user, model.Password); @@ -159,7 +148,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 +473,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..f6a4b3f 100644 --- a/src/BangazonUserAuth/Controllers/CustomersController.cs +++ b/src/BangazonUserAuth/Controllers/CustomersController.cs @@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Authorization; namespace BangazonUserAuth.Controllers { @@ -20,42 +22,15 @@ public class CustomersController : Controller private readonly UserManager _userManager; private ApplicationDbContext newContext; - private BangazonWebContext context; - public CustomersController(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) + public CustomersController(UserManager userManager, ApplicationDbContext ctx1) { _userManager = userManager; newContext = ctx1; - context = ctx2; } // This task retrieves the currently authenticated user private Task GetCurrentUserAsync() => _userManager.GetUserAsync(HttpContext.User); - //Method Name: Overloaded New - //Purpose of the Method: Will take an optional parameter of the type "customer." Takes form data then checks its validity. Post to customer table in database then redirects to home page. - //Arguments in Method: A new customer object taken from the form of Customer/New.cshtml. - [HttpPost] - [ValidateAntiForgeryTokenAttribute] - public int New(Customer customer) - { - if (ModelState.IsValid) - { - context.Add(customer); - context.SaveChangesAsync(); - Customer activeCustomer = context.Customer.Single(c => c.FirstName == customer.FirstName && c.LastName == customer.LastName); - if (activeCustomer != null) - { - return activeCustomer.CustomerId; - - } else - { - return 0; - } - } - return 0; - } - - //Method Name: ShoppingCart //Purpose of the Method: //Gets all LineItems on active order and give data to the returned View. @@ -63,24 +38,37 @@ public int New(Customer customer) //This method returns the Customer/ShoppingCart view. //Arguments in Method: None. [HttpGet] + [Authorize] public async Task ShoppingCart() { var user = await GetCurrentUserAsync(); - var CustomerId = user.CustomerId; - var activeOrder = await context.Order.Where(o => o.IsCompleted == false && o.CustomerId==CustomerId).SingleOrDefaultAsync(); + var activeOrder = await newContext.Order.Where(o => o.IsCompleted == false && o.User==user).SingleOrDefaultAsync(); - ShoppingCartViewModel model = new ShoppingCartViewModel(_userManager, newContext, context); + ShoppingCartViewModel model = new ShoppingCartViewModel(_userManager, newContext); if (activeOrder == null) { var product = new Product(){Description="You have no products in your cart!", Name=""}; model.Products = new List(); model.Products.Add(product); - model.ActiveCustomerId = CustomerId; + model.ListOfPaymentTypes = newContext.PaymentType + .Where(pt => pt.User == user) + .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); } - List LineItemsOnActiveOrder = context.LineItem.Where(li => li.OrderId == activeOrder.OrderId).ToList(); + List LineItemsOnActiveOrder = newContext.LineItem.Where(li => li.OrderId == activeOrder.OrderId).ToList(); List ListOfProducts = new List(); @@ -88,10 +76,24 @@ public async Task ShoppingCart() for(var i = 0; i < LineItemsOnActiveOrder.Count(); i++) { - ListOfProducts.Add(context.Product.Where(p => p.ProductId == LineItemsOnActiveOrder[i].ProductId).SingleOrDefault()); - CartTotal += context.Product.Where(p => p.ProductId == LineItemsOnActiveOrder[i].ProductId).SingleOrDefault().Price; + ListOfProducts.Add(newContext.Product.Where(p => p.ProductId == LineItemsOnActiveOrder[i].ProductId).SingleOrDefault()); + CartTotal += newContext.Product.Where(p => p.ProductId == LineItemsOnActiveOrder[i].ProductId).SingleOrDefault().Price; } + model.ListOfPaymentTypes = newContext.PaymentType + .Where(pt => pt.User == user) + .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 +105,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() + [Authorize] + public async Task Payment() { + var user = await GetCurrentUserAsync(); - PaymentTypeViewModel model = new PaymentTypeViewModel(_userManager, newContext, context); + PaymentTypeViewModel model = new PaymentTypeViewModel(_userManager, newContext); return View(model); } @@ -115,14 +119,27 @@ public IActionResult Payment() //Purpose of the Method: This is the Overloaded method that actually adds the payments to the Db. //Arguments in Method: Takes a new PaymentType object from the form provided and posts it to the database. [HttpPost] + [Authorize] public async Task Payment([FromForm]PaymentType paymentType) { - if (ModelState.IsValid) - { - context.Add(paymentType); - await context.SaveChangesAsync(); - return RedirectToAction("ShoppingCart"); + ModelState.Remove("paymentType.User"); + + if (ModelState.IsValid) + { + /* + If all other properties validation, then grab the + currently authenticated user and assign it to the + product before adding it to the db context + */ + var user = await GetCurrentUserAsync(); + paymentType.User = user; + + newContext.Add(paymentType); + + await newContext.SaveChangesAsync(); + return RedirectToAction("ShoppingCart"); } + return BadRequest(); } @@ -130,10 +147,11 @@ public async Task Payment([FromForm]PaymentType paymentType) //Purpose of the Method: To change the isCompleted bool from false to true on the active order for this customer and direct the user to the OrderCompleted view. //Arguments in Method: None. [HttpGet] + [Authorize] public IActionResult OrderCompleted() { - BaseViewModel model = new BaseViewModel(_userManager, newContext, context); + BaseViewModel model = new BaseViewModel(_userManager, newContext); return View(model); } @@ -141,17 +159,21 @@ public IActionResult OrderCompleted() //Purpose of the Method: To change the isCompleted bool from false to true on the active order for this customer and direct the user to the OrderCompleted view. //Arguments in Method: None. [HttpPatch] + [Authorize] public async Task SubmitOrder([FromRoute]int id) { + if (id == 0) + { + return NotFound(); + } var user = await GetCurrentUserAsync(); - var CustomerId = user.CustomerId; - var activeOrder = await context.Order.Where(o => o.IsCompleted == false && o.CustomerId==CustomerId) + var activeOrder = await newContext.Order.Where(o => o.IsCompleted == false && o.User==user) .SingleOrDefaultAsync(); - activeOrder.PaymentType = context.PaymentType.Where(pt => pt.PaymentTypeId == id).SingleOrDefault(); + activeOrder.PaymentType = newContext.PaymentType.Where(pt => pt.PaymentTypeId == id).SingleOrDefault(); activeOrder.DateCompleted = DateTime.Today; activeOrder.IsCompleted = true; - context.Update(activeOrder); - await context.SaveChangesAsync(); + newContext.Update(activeOrder); + await newContext.SaveChangesAsync(); return Json(id); } diff --git a/src/BangazonUserAuth/Controllers/ProductsController.cs b/src/BangazonUserAuth/Controllers/ProductsController.cs index 92f726f..80706a7 100644 --- a/src/BangazonUserAuth/Controllers/ProductsController.cs +++ b/src/BangazonUserAuth/Controllers/ProductsController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Authorization; namespace BangazonUserAuth.Controllers { @@ -19,12 +20,10 @@ public class ProductsController : Controller private readonly UserManager _userManager; private ApplicationDbContext newContext; - private BangazonWebContext context; - public ProductsController(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) + public ProductsController(UserManager userManager, ApplicationDbContext ctx1) { _userManager = userManager; newContext = ctx1; - context = ctx2; } // This task retrieves the currently authenticated user @@ -35,9 +34,9 @@ public ProductsController(UserManager userManager, ApplicationD //Arguments in Method: None. public async Task Index() { - AllProductsViewModel model = new AllProductsViewModel(_userManager, newContext, context); + AllProductsViewModel model = new AllProductsViewModel(_userManager, newContext); - model.Products = await context.Product.ToListAsync(); + model.Products = await newContext.Product.ToListAsync(); return View(model); } @@ -47,9 +46,9 @@ public async Task Index() //Arguments in Method: None. public async Task Types() { - AllProductTypesViewModel model = new AllProductTypesViewModel(_userManager, newContext, context); + AllProductTypesViewModel model = new AllProductTypesViewModel(_userManager, newContext); - model.ProductTypes = await context.ProductType.ToListAsync(); + model.ProductTypes = await newContext.ProductType.ToListAsync(); return View(model); } @@ -63,10 +62,10 @@ public async Task TypesList([FromRoute] int? id) { return NotFound(); } - AllSubProductTypesViewModel model = new AllSubProductTypesViewModel(_userManager, newContext, context); + AllSubProductTypesViewModel model = new AllSubProductTypesViewModel(_userManager, newContext); - model.SubProductTypes = await context.SubProductType.Where(p => p.ProductTypeId == id).ToListAsync(); - model.ProductType = await context.ProductType.Where(p => p.ProductTypeId == id).SingleOrDefaultAsync(); + model.SubProductTypes = await newContext.SubProductType.Where(p => p.ProductTypeId == id).ToListAsync(); + model.ProductType = await newContext.ProductType.Where(p => p.ProductTypeId == id).SingleOrDefaultAsync(); if (model.SubProductTypes == null) { @@ -80,10 +79,10 @@ public async Task TypesList([FromRoute] int? id) //Arguments in Method: Gets the subtypeId from the route. public async Task ProductsInSubType([FromRoute] int id) { - AllProductsViewModel model = new AllProductsViewModel(_userManager, newContext, context); + AllProductsViewModel model = new AllProductsViewModel(_userManager, newContext); - model.Products = await context.Product.Where(p => p.SubProductTypeId == id).ToListAsync(); - model.SubProductType = await context.SubProductType.Where(p => p.SubProductTypeId == id).SingleOrDefaultAsync(); + model.Products = await newContext.Product.Where(p => p.SubProductTypeId == id).ToListAsync(); + model.SubProductType = await newContext.SubProductType.Where(p => p.SubProductTypeId == id).SingleOrDefaultAsync(); if (model.Products == null) @@ -104,14 +103,12 @@ public async Task Single([FromRoute] int? id) return NotFound(); } - SingleProductViewModel model = new SingleProductViewModel(_userManager, newContext, context); + SingleProductViewModel model = new SingleProductViewModel(_userManager, newContext); - var SingleProduct = await context.Product.SingleOrDefaultAsync(p => p.ProductId == id); - - var SellingCustomer = context.Customer.Where(c => c.CustomerId == SingleProduct.CustomerId).Single(); + var SingleProduct = await newContext.Product.SingleOrDefaultAsync(p => p.ProductId == id); model.Product = SingleProduct; - model.CustomerName = $"{SellingCustomer.FirstName} {SellingCustomer.LastName}"; + model.CustomerName = $"{SingleProduct.User.FirstName} {SingleProduct.User.LastName}"; if (model.Product == null) { @@ -124,12 +121,11 @@ public async Task Single([FromRoute] int? id) //Method Name: New //Purpose of the Method: This method returns the New.cshtml file in the Products folder, which will contain a form to add a new product. //Arguments in Method: None. + [Authorize] public async Task New() { var user = await GetCurrentUserAsync(); - var CustomerId = user.CustomerId; - ProductTypesListViewModel model = new ProductTypesListViewModel(_userManager, newContext, context); - model.ActiveCustomerId = CustomerId; + ProductTypesListViewModel model = new ProductTypesListViewModel(_userManager, newContext); return View(model); } @@ -138,12 +134,13 @@ public async Task New() //Arguments in Method: This method takes in an argument of type Product from the form. [HttpPost] [ValidateAntiForgeryToken] + [Authorize] public async Task New(Product product) { if (ModelState.IsValid) { - context.Add(product); - await context.SaveChangesAsync(); + newContext.Add(product); + await newContext.SaveChangesAsync(); return RedirectToAction("Index"); } //Make sure error messages are present in the view if the view is returned to the customer. @@ -155,27 +152,27 @@ public async Task New(Product product) //Arguments in Method: The ProductId of the product to add to the active order. //Something to note, the methods here must return a json response to the ajax call so the ajax call can redirect the window to index. [HttpPost] + [Authorize] public async Task AddToCart([FromRoute] int id) { var user = await GetCurrentUserAsync(); - var CustomerId = user.CustomerId; //Get the active customer's order - var activeOrder = await context.Order.Where(o => o.IsCompleted == false && o.CustomerId==CustomerId).SingleOrDefaultAsync(); + var activeOrder = await newContext.Order.Where(o => o.IsCompleted == false && o.User==user).SingleOrDefaultAsync(); // If no active order create one and add the product to it. if (activeOrder == null) { var order = new Order(); order.IsCompleted = false; - order.CustomerId = CustomerId; - context.Add(order); - await context.SaveChangesAsync(); - var newOrder = await context.Order.Where(o => o.IsCompleted == false && o.CustomerId==CustomerId).SingleOrDefaultAsync(); + order.User = user; + newContext.Add(order); + await newContext.SaveChangesAsync(); + var newOrder = await newContext.Order.Where(o => o.IsCompleted == false && o.User==user).SingleOrDefaultAsync(); var lineItem = new LineItem(); lineItem.OrderId = newOrder.OrderId; lineItem.ProductId = Convert.ToInt32(id); - context.Add(lineItem); - await context.SaveChangesAsync(); + newContext.Add(lineItem); + await newContext.SaveChangesAsync(); return Json(id); } else @@ -184,8 +181,8 @@ public async Task AddToCart([FromRoute] int id) var lineItem = new LineItem(); lineItem.OrderId = activeOrder.OrderId; lineItem.ProductId = Convert.ToInt32(id); - context.Add(lineItem); - await context.SaveChangesAsync(); + newContext.Add(lineItem); + await newContext.SaveChangesAsync(); return Json(id); } } @@ -197,7 +194,7 @@ public async Task AddToCart([FromRoute] int id) public IActionResult GetSubTypes([FromRoute]int id) { //get sub categories with that product type on them - var subTypes = context.SubProductType.Where(p => p.ProductTypeId == id).ToList(); + var subTypes = newContext.SubProductType.Where(p => p.ProductTypeId == id).ToList(); return Json(subTypes); } //Method Name: Error diff --git a/src/BangazonUserAuth/Data/ApplicationDbContext.cs b/src/BangazonUserAuth/Data/ApplicationDbContext.cs index 4f2fa5a..513c4d6 100644 --- a/src/BangazonUserAuth/Data/ApplicationDbContext.cs +++ b/src/BangazonUserAuth/Data/ApplicationDbContext.cs @@ -14,13 +14,25 @@ public ApplicationDbContext(DbContextOptions options) : base(options) { } + public DbSet LineItem { get; set; } + public DbSet Order { get; set; } + public DbSet PaymentType { get; set; } + public DbSet Product { get; set; } + public DbSet ProductType { get; set; } + public DbSet SubProductType { get; set; } - protected override void OnModelCreating(ModelBuilder builder) + protected override void OnModelCreating(ModelBuilder modelBuilder) { - base.OnModelCreating(builder); - // Customize the ASP.NET Identity model and override the defaults if needed. - // For example, you can rename the ASP.NET Identity table names and more. - // Add your customizations after calling base.OnModelCreating(builder); + base.OnModelCreating(modelBuilder); + // When an Order is being created we are setting a DateCreated property here of current: Year, Month, Day, Hour, Minute, and Second. + modelBuilder.Entity() + .Property(b => b.DateCreated) + .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); + + // When a Product is being created we are setting a DateCreated property here of current: Year, Month, Day, Hour, Minute, and Second. + modelBuilder.Entity() + .Property(b => b.DateCreated) + .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); } } } diff --git a/src/BangazonUserAuth/Data/BangazonWebContext.cs b/src/BangazonUserAuth/Data/BangazonWebContext.cs deleted file mode 100644 index 2608ec4..0000000 --- a/src/BangazonUserAuth/Data/BangazonWebContext.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using BangazonUserAuth.Models; - -namespace BangazonUserAuth.Data -{ - //Class Name: BangazonUserAuthContext - //Author: Grant Regnier - //Purpose of the class: The purpose of this class is to create a context in memory for our Controllers to interact with our Database. - //Methods in Class: No Methods but DBSets of Customer, LineItem, Order, PaymentType, Product, ProductType - public class BangazonWebContext : DbContext - { - public BangazonWebContext(DbContextOptions options) - : base(options) - { } - - public DbSet Customer { get; set; } - public DbSet LineItem { get; set; } - public DbSet Order { get; set; } - public DbSet PaymentType { get; set; } - public DbSet Product { get; set; } - public DbSet ProductType { get; set; } - public DbSet SubProductType { get; set; } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { -// When an Order is being created we are setting a DateCreated property here of current: Year, Month, Day, Hour, Minute, and Second. - modelBuilder.Entity() - .Property(b => b.DateCreated) - .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); - -// When a Product is being created we are setting a DateCreated property here of current: Year, Month, Day, Hour, Minute, and Second. - modelBuilder.Entity() - .Property(b => b.DateCreated) - .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); - } - } -} \ No newline at end of file diff --git a/src/BangazonUserAuth/Data/DBInitializer.cs b/src/BangazonUserAuth/Data/DBInitializer.cs deleted file mode 100644 index 5abdf3c..0000000 --- a/src/BangazonUserAuth/Data/DBInitializer.cs +++ /dev/null @@ -1,205 +0,0 @@ -using System; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using BangazonUserAuth.Models; - -namespace BangazonUserAuth.Data -{ - //Class Name: DbInitializer - //Author: Grant Regnier and Chris Smalley - //Purpose of the class: The purpose of this class is to check if our database is empty, if it is, then this class populates the database with pre-made data. - //Methods in Class: Initialize() - public static class DbInitializer - { - //Method Name: Initialize - //Purpose of the Method: This Method checks if the database has any data in it, if it doesn't it populates it with the data specified in the arrays bellow. - //Arguments in Method: None. - public static void Initialize(IServiceProvider serviceProvider) - { - using (var context = new BangazonWebContext(serviceProvider.GetRequiredService>())) - { - // Look for any products. - if (context.Product.Any()) - { - return; // DB has been seeded - } - - var customers = new Customer[] - { - new Customer { - FirstName = "James", - LastName = "Regnier" - }, - new Customer { - FirstName = "Scott", - LastName = "Promises" - }, - new Customer { - FirstName = "Zaq", - LastName = "Repasse" - } - }; - - foreach (Customer c in customers) - { - context.Customer.Add(c); - } - context.SaveChanges(); - - var productTypes = new ProductType[] - { - new ProductType { - Name = "Electronics and Media" - }, - new ProductType { - Name = "Beauty, Health, and Grocery" - }, - new ProductType { - Name = "Appliances" - }, - new ProductType { - Name = "Everything Else" - }, - }; - - foreach (ProductType i in productTypes) - { - context.ProductType.Add(i); - } - context.SaveChanges(); - - var subProductTypes = new SubProductType[] - { - new SubProductType { - Name = "Refrigerators and Freezers", - Description = "Appliances to keep food and beverages cold", - ProductTypeId = productTypes.Single(s => s.Name == "Appliances").ProductTypeId - }, - new SubProductType { - Name = "Microwaves", - Description = "Appliances to quickly heat food", - ProductTypeId = productTypes.Single(s => s.Name == "Appliances").ProductTypeId - }, - new SubProductType { - Name = "Ranges, Ovens, and Components", - Description = "Appliances to heat food", - ProductTypeId = productTypes.Single(s => s.Name == "Appliances").ProductTypeId - }, - new SubProductType { - Name = "Small Appliances", - Description = "A varity of small household appliances from coffee makers to irons to desk fans", - ProductTypeId = productTypes.Single(s => s.Name == "Appliances").ProductTypeId - }, - new SubProductType { - Name = "Washing Machine, Dryers, and Dishwashers", - Description = "Appliances to clean", - ProductTypeId = productTypes.Single(s => s.Name == "Appliances").ProductTypeId - }, - new SubProductType { - Name = "Portable Audio and Accessories", - Description = "MP3 players, headphones, wearable Accessories, portable bluetooth audio", - ProductTypeId = productTypes.Single(s => s.Name == "Electronics and Media").ProductTypeId - }, - new SubProductType { - Name = "Computers, Hardware, Software, and Components", - Description = "Everything related to computers from printers, modems, Operating Systems, Microsoft Office, etc.", - ProductTypeId = productTypes.Single(s => s.Name == "Electronics and Media").ProductTypeId - }, - new SubProductType { - Name = "Video Games and Gaming Hardware", - Description = "Gaming Consoles, Video Games, and Components", - ProductTypeId = productTypes.Single(s => s.Name == "Electronics and Media").ProductTypeId - }, - new SubProductType { - Name = "Home Theatre and Audio", - Description = "Everything from TVs, Speakers, Bluray Players, and all the Components.", - ProductTypeId = productTypes.Single(s => s.Name == "Electronics and Media").ProductTypeId - }, - new SubProductType { - Name = "Camera, Photo, and Video", - Description = "Everything related to photography and videography", - ProductTypeId = productTypes.Single(s => s.Name == "Electronics and Media").ProductTypeId - }, - new SubProductType { - Name = "Media", - Description = "Digital Media, Books, DVDs, CDs, Records, Betatapes, Videotapes, Bluray. etc", - ProductTypeId = productTypes.Single(s => s.Name == "Electronics and Media").ProductTypeId - }, - new SubProductType { - Name = "Car Electronics", - Description = "Car Audio, GPS, Etc.", - ProductTypeId = productTypes.Single(s => s.Name == "Electronics and Media").ProductTypeId - }, - new SubProductType { - Name = "Food", - Description = "If you can eat it or drink it you will find it here.", - ProductTypeId = productTypes.Single(s => s.Name == "Beauty, Health, and Grocery").ProductTypeId - }, - new SubProductType { - Name = "Beauty", - Description = "Everything from fake eyelashes to makeup remover to cologne.", - ProductTypeId = productTypes.Single(s => s.Name == "Beauty, Health, and Grocery").ProductTypeId - }, - new SubProductType { - Name = "Health, Household, and Baby Care", - Description = "Everything from Tylenol to Detergent to Diapers to Mouse traps", - ProductTypeId = productTypes.Single(s => s.Name == "Beauty, Health, and Grocery").ProductTypeId - }, - new SubProductType { - Name = "Furniture", - Description = "From kitchen tables to sofas to mattresses", - ProductTypeId = productTypes.Single(s => s.Name == "Everything Else").ProductTypeId - }, - new SubProductType { - Name = "Clothing", - Description = "If you can wear it and its made of cloth, you will find here. Yeah we know technically you can wear almost anything but please keep it with stuff you might actually find at a clothing store. ", - ProductTypeId = productTypes.Single(s => s.Name == "Everything Else").ProductTypeId - }, - new SubProductType { - Name = "Misc", - Description = "If you can wear it and its made of cloth, you will find here. Yeah we know technically you can wear almost anything but please keep it with stuff you might actually find at a clothing store. ", - ProductTypeId = productTypes.Single(s => s.Name == "Everything Else").ProductTypeId - }, - }; - - foreach (SubProductType i in subProductTypes) - { - context.SubProductType.Add(i); - } - context.SaveChanges(); - - var products = new Product[] - { - new Product { - Description = "Pampelmouse La Croix which taste real good", - SubProductTypeId = subProductTypes.Single(s => s.Name == "Food").SubProductTypeId, - Name = "Pampelmouse La Croix", - Price = 3.55, - CustomerId = 1 - }, - new Product { - Description = "A 2012 iPod Shuffle. Headphones are included. 16G capacity.", - SubProductTypeId = subProductTypes.Single(s => s.Name == "Portable Audio and Accessories").SubProductTypeId, - Name = "iPod Shuffle", - Price = 18.00, - CustomerId = 1 - }, - new Product { - Description = "Stainless steel refrigerator. Three years old. Minor scratches.", - SubProductTypeId = subProductTypes.Single(s => s.Name == "Refrigerators and Freezers").SubProductTypeId, - Name = "Samsung refrigerator", - Price = 500.00, - CustomerId = 1 - } - }; - - foreach (Product i in products) - { - context.Product.Add(i); - } - context.SaveChanges(); - } - } - } -} diff --git a/src/BangazonUserAuth/Migrations/20161201211203_AddCustomerId.Designer.cs b/src/BangazonUserAuth/Migrations/20161201211203_AddCustomerId.Designer.cs deleted file mode 100644 index 060808f..0000000 --- a/src/BangazonUserAuth/Migrations/20161201211203_AddCustomerId.Designer.cs +++ /dev/null @@ -1,216 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using BangazonUserAuth.Data; - -namespace BangazonUserAuth.Data.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20161201211203_AddCustomerId")] - partial class AddCustomerId - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.1") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("BangazonUserAuth.Models.ApplicationUser", b => - { - b.Property("Id"); - - b.Property("AccessFailedCount"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("CustomerId"); - - b.Property("Email") - .HasAnnotation("MaxLength", 256); - - b.Property("EmailConfirmed"); - - b.Property("LockoutEnabled"); - - b.Property("LockoutEnd"); - - b.Property("NormalizedEmail") - .HasAnnotation("MaxLength", 256); - - b.Property("NormalizedUserName") - .HasAnnotation("MaxLength", 256); - - b.Property("PasswordHash"); - - b.Property("PhoneNumber"); - - b.Property("PhoneNumberConfirmed"); - - b.Property("SecurityStamp"); - - b.Property("TwoFactorEnabled"); - - b.Property("UserName") - .HasAnnotation("MaxLength", 256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasName("UserNameIndex"); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole", b => - { - b.Property("Id"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("Name") - .HasAnnotation("MaxLength", 256); - - b.Property("NormalizedName") - .HasAnnotation("MaxLength", 256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .HasName("RoleNameIndex"); - - b.ToTable("AspNetRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("RoleId") - .IsRequired(); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("UserId") - .IsRequired(); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => - { - b.Property("LoginProvider"); - - b.Property("ProviderKey"); - - b.Property("ProviderDisplayName"); - - b.Property("UserId") - .IsRequired(); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => - { - b.Property("UserId"); - - b.Property("RoleId"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken", b => - { - b.Property("UserId"); - - b.Property("LoginProvider"); - - b.Property("Name"); - - b.Property("Value"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") - .WithMany("Claims") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => - { - b.HasOne("BangazonUserAuth.Models.ApplicationUser") - .WithMany("Claims") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => - { - b.HasOne("BangazonUserAuth.Models.ApplicationUser") - .WithMany("Logins") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") - .WithMany("Users") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("BangazonUserAuth.Models.ApplicationUser") - .WithMany("Roles") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/BangazonUserAuth/Migrations/20161201211203_AddCustomerId.cs b/src/BangazonUserAuth/Migrations/20161201211203_AddCustomerId.cs deleted file mode 100644 index d980fe6..0000000 --- a/src/BangazonUserAuth/Migrations/20161201211203_AddCustomerId.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace BangazonUserAuth.Data.Migrations -{ - public partial class AddCustomerId : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "CustomerId", - table: "AspNetUsers", - nullable: false, - defaultValue: 0); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "CustomerId", - table: "AspNetUsers"); - } - } -} diff --git a/src/BangazonUserAuth/Migrations/20161205220240_InitialCreate.Designer.cs b/src/BangazonUserAuth/Migrations/20161205220240_InitialCreate.Designer.cs new file mode 100644 index 0000000..877a994 --- /dev/null +++ b/src/BangazonUserAuth/Migrations/20161205220240_InitialCreate.Designer.cs @@ -0,0 +1,426 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using BangazonUserAuth.Data; + +namespace BangazonUserAuth.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20161205220240_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.1") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("BangazonUserAuth.Models.ApplicationUser", b => + { + b.Property("Id"); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasAnnotation("MaxLength", 256); + + b.Property("EmailConfirmed"); + + b.Property("FirstName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("LastName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedUserName") + .HasAnnotation("MaxLength", 256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.LineItem", b => + { + b.Property("LineItemId") + .ValueGeneratedOnAdd(); + + b.Property("OrderId"); + + b.Property("ProductId"); + + b.HasKey("LineItemId"); + + b.HasIndex("OrderId"); + + b.HasIndex("ProductId"); + + b.ToTable("LineItem"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Order", b => + { + b.Property("OrderId") + .ValueGeneratedOnAdd(); + + b.Property("DateCompleted"); + + b.Property("DateCreated") + .ValueGeneratedOnAddOrUpdate() + .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); + + b.Property("IsCompleted"); + + b.Property("PaymentTypeId"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("OrderId"); + + b.HasIndex("PaymentTypeId"); + + b.HasIndex("UserId"); + + b.ToTable("Order"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.PaymentType", b => + { + b.Property("PaymentTypeId") + .ValueGeneratedOnAdd(); + + b.Property("CardNumber") + .IsRequired(); + + b.Property("City") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("ExpirationDate") + .IsRequired(); + + b.Property("FirstName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("LastName") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("Processor") + .IsRequired() + .HasAnnotation("MaxLength", 25); + + b.Property("State") + .IsRequired() + .HasAnnotation("MaxLength", 2); + + b.Property("StreetAddress") + .IsRequired() + .HasAnnotation("MaxLength", 80); + + b.Property("UserId") + .IsRequired(); + + b.Property("ZipCode"); + + b.HasKey("PaymentTypeId"); + + b.HasIndex("UserId"); + + b.ToTable("PaymentType"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Product", b => + { + b.Property("ProductId") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated") + .ValueGeneratedOnAddOrUpdate() + .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); + + b.Property("Description") + .IsRequired() + .HasAnnotation("MaxLength", 255); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.Property("Price"); + + b.Property("SubProductTypeId"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("ProductId"); + + b.HasIndex("SubProductTypeId"); + + b.HasIndex("UserId"); + + b.ToTable("Product"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.ProductType", b => + { + b.Property("ProductTypeId") + .ValueGeneratedOnAdd(); + + b.Property("Name") + .IsRequired(); + + b.HasKey("ProductTypeId"); + + b.ToTable("ProductType"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.SubProductType", b => + { + b.Property("SubProductTypeId") + .ValueGeneratedOnAdd(); + + b.Property("Description") + .IsRequired() + .HasAnnotation("MaxLength", 255); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.Property("ProductTypeId"); + + b.HasKey("SubProductTypeId"); + + b.ToTable("SubProductType"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole", b => + { + b.Property("Id"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasAnnotation("MaxLength", 256); + + b.Property("NormalizedName") + .HasAnnotation("MaxLength", 256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.LineItem", b => + { + b.HasOne("BangazonUserAuth.Models.Order", "Order") + .WithMany() + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BangazonUserAuth.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Order", b => + { + b.HasOne("BangazonUserAuth.Models.PaymentType", "PaymentType") + .WithMany() + .HasForeignKey("PaymentTypeId"); + + b.HasOne("BangazonUserAuth.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.PaymentType", b => + { + b.HasOne("BangazonUserAuth.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("BangazonUserAuth.Models.Product", b => + { + b.HasOne("BangazonUserAuth.Models.SubProductType", "SubProductType") + .WithMany() + .HasForeignKey("SubProductTypeId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BangazonUserAuth.Models.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.HasOne("BangazonUserAuth.Models.ApplicationUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.HasOne("BangazonUserAuth.Models.ApplicationUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Users") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("BangazonUserAuth.Models.ApplicationUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/BangazonUserAuth/Migrations/20161205220240_InitialCreate.cs b/src/BangazonUserAuth/Migrations/20161205220240_InitialCreate.cs new file mode 100644 index 0000000..2036774 --- /dev/null +++ b/src/BangazonUserAuth/Migrations/20161205220240_InitialCreate.cs @@ -0,0 +1,413 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace BangazonUserAuth.Data.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false), + ConcurrencyStamp = table.Column(nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + FirstName = table.Column(maxLength: 50, nullable: false), + LastName = table.Column(maxLength: 50, nullable: false), + LockoutEnabled = table.Column(nullable: false), + LockoutEnd = table.Column(nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + PasswordHash = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false), + SecurityStamp = table.Column(nullable: true), + TwoFactorEnabled = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ProductType", + columns: table => new + { + ProductTypeId = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProductType", x => x.ProductTypeId); + }); + + migrationBuilder.CreateTable( + name: "SubProductType", + columns: table => new + { + SubProductTypeId = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Description = table.Column(maxLength: 255, nullable: false), + Name = table.Column(maxLength: 100, nullable: false), + ProductTypeId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SubProductType", x => x.SubProductTypeId); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + ConcurrencyStamp = table.Column(nullable: true), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(nullable: false), + LoginProvider = table.Column(nullable: false), + Name = table.Column(nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + }); + + migrationBuilder.CreateTable( + name: "PaymentType", + columns: table => new + { + PaymentTypeId = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + CardNumber = table.Column(nullable: false), + City = table.Column(maxLength: 50, nullable: false), + ExpirationDate = table.Column(nullable: false), + FirstName = table.Column(maxLength: 50, nullable: false), + LastName = table.Column(maxLength: 50, nullable: false), + Processor = table.Column(maxLength: 25, nullable: false), + State = table.Column(maxLength: 2, nullable: false), + StreetAddress = table.Column(maxLength: 80, nullable: false), + UserId = table.Column(nullable: false), + ZipCode = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PaymentType", x => x.PaymentTypeId); + table.ForeignKey( + name: "FK_PaymentType_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(nullable: false), + ProviderKey = table.Column(nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Product", + columns: table => new + { + ProductId = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + DateCreated = table.Column(nullable: false, defaultValueSql: "strftime('%Y-%m-%d %H:%M:%S')"), + Description = table.Column(maxLength: 255, nullable: false), + Name = table.Column(maxLength: 100, nullable: false), + Price = table.Column(nullable: false), + SubProductTypeId = table.Column(nullable: false), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Product", x => x.ProductId); + table.ForeignKey( + name: "FK_Product_SubProductType_SubProductTypeId", + column: x => x.SubProductTypeId, + principalTable: "SubProductType", + principalColumn: "SubProductTypeId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Product_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(nullable: false), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Order", + columns: table => new + { + OrderId = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + DateCompleted = table.Column(nullable: true), + DateCreated = table.Column(nullable: false, defaultValueSql: "strftime('%Y-%m-%d %H:%M:%S')"), + IsCompleted = table.Column(nullable: false), + PaymentTypeId = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Order", x => x.OrderId); + table.ForeignKey( + name: "FK_Order_PaymentType_PaymentTypeId", + column: x => x.PaymentTypeId, + principalTable: "PaymentType", + principalColumn: "PaymentTypeId", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Order_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "LineItem", + columns: table => new + { + LineItemId = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + OrderId = table.Column(nullable: false), + ProductId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LineItem", x => x.LineItemId); + table.ForeignKey( + name: "FK_LineItem_Order_OrderId", + column: x => x.OrderId, + principalTable: "Order", + principalColumn: "OrderId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_LineItem_Product_ProductId", + column: x => x.ProductId, + principalTable: "Product", + principalColumn: "ProductId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_LineItem_OrderId", + table: "LineItem", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_LineItem_ProductId", + table: "LineItem", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_Order_PaymentTypeId", + table: "Order", + column: "PaymentTypeId"); + + migrationBuilder.CreateIndex( + name: "IX_Order_UserId", + table: "Order", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_PaymentType_UserId", + table: "PaymentType", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Product_SubProductTypeId", + table: "Product", + column: "SubProductTypeId"); + + migrationBuilder.CreateIndex( + name: "IX_Product_UserId", + table: "Product", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_UserId", + table: "AspNetUserRoles", + column: "UserId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "LineItem"); + + migrationBuilder.DropTable( + name: "ProductType"); + + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "Order"); + + migrationBuilder.DropTable( + name: "Product"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "PaymentType"); + + migrationBuilder.DropTable( + name: "SubProductType"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/src/BangazonUserAuth/Migrations/BangazonWebContextModelSnapshot.cs b/src/BangazonUserAuth/Migrations/BangazonWebContextModelSnapshot.cs deleted file mode 100644 index d1ec8f9..0000000 --- a/src/BangazonUserAuth/Migrations/BangazonWebContextModelSnapshot.cs +++ /dev/null @@ -1,238 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using BangazonUserAuth.Data; - -namespace BangazonUserAuth.Migrations -{ - [DbContext(typeof(BangazonWebContext))] - partial class BangazonWebContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.0.1"); - - modelBuilder.Entity("BangazonUserAuth.Models.Customer", b => - { - b.Property("CustomerId") - .ValueGeneratedOnAdd(); - - b.Property("FirstName") - .IsRequired() - .HasAnnotation("MaxLength", 50); - - b.Property("LastName") - .IsRequired() - .HasAnnotation("MaxLength", 50); - - b.HasKey("CustomerId"); - - b.ToTable("Customer"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.LineItem", b => - { - b.Property("LineItemId") - .ValueGeneratedOnAdd(); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.HasKey("LineItemId"); - - b.HasIndex("OrderId"); - - b.HasIndex("ProductId"); - - b.ToTable("LineItem"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.Order", b => - { - b.Property("OrderId") - .ValueGeneratedOnAdd(); - - b.Property("CustomerId"); - - b.Property("DateCompleted"); - - b.Property("DateCreated") - .ValueGeneratedOnAddOrUpdate() - .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); - - b.Property("IsCompleted"); - - b.Property("PaymentTypeId"); - - b.HasKey("OrderId"); - - b.HasIndex("CustomerId"); - - b.HasIndex("PaymentTypeId"); - - b.ToTable("Order"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.PaymentType", b => - { - b.Property("PaymentTypeId") - .ValueGeneratedOnAdd(); - - b.Property("CardNumber") - .IsRequired(); - - b.Property("City") - .IsRequired() - .HasAnnotation("MaxLength", 50); - - b.Property("CustomerId"); - - b.Property("ExpirationDate") - .IsRequired(); - - b.Property("FirstName") - .IsRequired() - .HasAnnotation("MaxLength", 50); - - b.Property("LastName") - .IsRequired() - .HasAnnotation("MaxLength", 50); - - b.Property("Processor") - .IsRequired() - .HasAnnotation("MaxLength", 25); - - b.Property("State") - .IsRequired() - .HasAnnotation("MaxLength", 2); - - b.Property("StreetAddress") - .IsRequired() - .HasAnnotation("MaxLength", 80); - - b.Property("ZipCode"); - - b.HasKey("PaymentTypeId"); - - b.HasIndex("CustomerId"); - - b.ToTable("PaymentType"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.Product", b => - { - b.Property("ProductId") - .ValueGeneratedOnAdd(); - - b.Property("CustomerId"); - - b.Property("DateCreated") - .ValueGeneratedOnAddOrUpdate() - .HasDefaultValueSql("strftime('%Y-%m-%d %H:%M:%S')"); - - b.Property("Description") - .IsRequired() - .HasAnnotation("MaxLength", 255); - - b.Property("Name") - .IsRequired() - .HasAnnotation("MaxLength", 100); - - b.Property("Price"); - - b.Property("SubProductTypeId"); - - b.HasKey("ProductId"); - - b.HasIndex("CustomerId"); - - b.HasIndex("SubProductTypeId"); - - b.ToTable("Product"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.ProductType", b => - { - b.Property("ProductTypeId") - .ValueGeneratedOnAdd(); - - b.Property("Name") - .IsRequired(); - - b.HasKey("ProductTypeId"); - - b.ToTable("ProductType"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.SubProductType", b => - { - b.Property("SubProductTypeId") - .ValueGeneratedOnAdd(); - - b.Property("Description") - .IsRequired() - .HasAnnotation("MaxLength", 255); - - b.Property("Name") - .IsRequired() - .HasAnnotation("MaxLength", 100); - - b.Property("ProductTypeId"); - - b.HasKey("SubProductTypeId"); - - b.ToTable("SubProductType"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.LineItem", b => - { - b.HasOne("BangazonUserAuth.Models.Order", "Order") - .WithMany() - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("BangazonUserAuth.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.Order", b => - { - b.HasOne("BangazonUserAuth.Models.Customer", "Customer") - .WithMany() - .HasForeignKey("CustomerId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("BangazonUserAuth.Models.PaymentType", "PaymentType") - .WithMany() - .HasForeignKey("PaymentTypeId"); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.PaymentType", b => - { - b.HasOne("BangazonUserAuth.Models.Customer", "Customer") - .WithMany() - .HasForeignKey("CustomerId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("BangazonUserAuth.Models.Product", b => - { - b.HasOne("BangazonUserAuth.Models.Customer", "Customer") - .WithMany() - .HasForeignKey("CustomerId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("BangazonUserAuth.Models.SubProductType", "SubProductType") - .WithMany() - .HasForeignKey("SubProductTypeId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/BangazonUserAuth/Models/ApplicationUser.cs b/src/BangazonUserAuth/Models/ApplicationUser.cs index 3deca16..5e79098 100644 --- a/src/BangazonUserAuth/Models/ApplicationUser.cs +++ b/src/BangazonUserAuth/Models/ApplicationUser.cs @@ -1,14 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; namespace BangazonUserAuth.Models { // Add profile data for application users by adding properties to the ApplicationUser class public class ApplicationUser : IdentityUser { - public int CustomerId { get; set; } + [Required] + [StringLength(50)] + public string FirstName { get; set; } + + [Required] + [StringLength(50)] + public string LastName { get; set; } + + public ICollection PaymentTypes; + + public ICollection Orders; } } diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductTypesViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductTypesViewModel.cs index f5d1af5..17e003a 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductTypesViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductTypesViewModel.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; -using BangazonUserAuth.Models; -using BangazonUserAuth.Data; +using System.Collections.Generic; +using BangazonUserAuth.Models; +using BangazonUserAuth.Data; using Microsoft.AspNetCore.Identity; -namespace BangazonUserAuth.ViewModels -{ - //Class Name: AllProductTypesViewModel - //Author: Debbie Bourne - //Purpose of the class: The purpose of this class is to manage the property and method that will produce the data and functionality needed for the view of all of the product types - //Methods in Class: None. - public class AllProductTypesViewModel : BaseViewModel - { - public IEnumerable ProductTypes { get; set; } - - public AllProductTypesViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) { } - } +namespace BangazonUserAuth.ViewModels +{ + //Class Name: AllProductTypesViewModel + //Author: Debbie Bourne + //Purpose of the class: The purpose of this class is to manage the property and method that will produce the data and functionality needed for the view of all of the product types + //Methods in Class: None. + public class AllProductTypesViewModel : BaseViewModel + { + public IEnumerable ProductTypes { get; set; } + + public AllProductTypesViewModel(UserManager userManager, ApplicationDbContext ctx1) : base(userManager, ctx1) { } + } } \ No newline at end of file diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductsViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductsViewModel.cs index 4fac08e..7ac788b 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductsViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/AllProductsViewModel.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; -using BangazonUserAuth.Models; -using BangazonUserAuth.Data; +using System.Collections.Generic; +using BangazonUserAuth.Models; +using BangazonUserAuth.Data; using Microsoft.AspNetCore.Identity; -namespace BangazonUserAuth.ViewModels -{ - //Class Name: AllProductsViewModel - //Author: Debbie Bourne - //Purpose of the class: The purpose of this class is to hold and pass data data to the whichever view this ViewModel is passed. - //Methods in Class: None. - public class AllProductsViewModel : BaseViewModel - { - public IEnumerable Products { get; set; } - public SubProductType SubProductType { get; set; } - public AllProductsViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) { } - } +namespace BangazonUserAuth.ViewModels +{ + //Class Name: AllProductsViewModel + //Author: Debbie Bourne + //Purpose of the class: The purpose of this class is to hold and pass data data to the whichever view this ViewModel is passed. + //Methods in Class: None. + public class AllProductsViewModel : BaseViewModel + { + public IEnumerable Products { get; set; } + public SubProductType SubProductType { get; set; } + public AllProductsViewModel(UserManager userManager, ApplicationDbContext ctx1) : base(userManager, ctx1) { } + } } \ No newline at end of file diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/AllSubProductTypesViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/AllSubProductTypesViewModel.cs index 7ba60d5..9df2845 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/AllSubProductTypesViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/AllSubProductTypesViewModel.cs @@ -1,19 +1,19 @@ -using System.Collections.Generic; -using BangazonUserAuth.Models; -using BangazonUserAuth.Data; +using System.Collections.Generic; +using BangazonUserAuth.Models; +using BangazonUserAuth.Data; using Microsoft.AspNetCore.Identity; -namespace BangazonUserAuth.ViewModels -{ - //Class Name: AllSubProductTypesViewModel - //Author: Jamie Duke - //Purpose of the class: The purpose of this class is to manage the property and method that will produce the data and functionality needed for the view of all of the sub product types - //Methods in Class: None. - public class AllSubProductTypesViewModel : BaseViewModel - { - public IEnumerable SubProductTypes { get; set; } - public ProductType ProductType { get; set; } - - public AllSubProductTypesViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) { } - } +namespace BangazonUserAuth.ViewModels +{ + //Class Name: AllSubProductTypesViewModel + //Author: Jamie Duke + //Purpose of the class: The purpose of this class is to manage the property and method that will produce the data and functionality needed for the view of all of the sub product types + //Methods in Class: None. + public class AllSubProductTypesViewModel : BaseViewModel + { + public IEnumerable SubProductTypes { get; set; } + public ProductType ProductType { get; set; } + + public AllSubProductTypesViewModel(UserManager userManager, ApplicationDbContext ctx1) : base(userManager, ctx1) { } + } } \ No newline at end of file diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs index ea51ab1..e1ab61f 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/BaseViewModel.cs @@ -14,47 +14,46 @@ namespace BangazonUserAuth.ViewModels public class BaseViewModel { private ApplicationDbContext newContext; - private BangazonWebContext context; private readonly UserManager _userManager; - public BaseViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) + public BaseViewModel(UserManager userManager, ApplicationDbContext ctx1) { _userManager = userManager; newContext = ctx1; - context = ctx2; } 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..fb19485 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/PaymentTypeViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/PaymentTypeViewModel.cs @@ -1,17 +1,17 @@ -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 PaymentTypeViewModel(UserManager userManager, ApplicationDbContext ctx1) : base(userManager, ctx1) { } + } +} diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/ProductTypesListViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/ProductTypesListViewModel.cs index 40cec8c..75ceaa5 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/ProductTypesListViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/ProductTypesListViewModel.cs @@ -15,13 +15,12 @@ public class ProductTypesListViewModel : BaseViewModel { public List ProductTypesList { get; set; } public List SubProductTypesList { get; set; } - public int ActiveCustomerId { get; set; } + private ApplicationDbContext newContext { get; set; } public Product Product {get; set;} - private BangazonWebContext context; - public ProductTypesListViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) - { - context = ctx2; - this.ProductTypesList = context.ProductType + public ProductTypesListViewModel(UserManager userManager, ApplicationDbContext ctx1) : base(userManager, ctx1) + { + newContext = ctx1; + this.ProductTypesList = newContext.ProductType .OrderBy(type => type.Name) .AsEnumerable() .Select(li => new SelectListItem{ diff --git a/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs index baa6e4c..10d4f21 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/ShoppingCartViewModel.cs @@ -20,30 +20,16 @@ public class ShoppingCartViewModel : BaseViewModel public double CartTotal {get; set;} public int ActiveCustomerId { get; set; } private ApplicationDbContext newContext; - private BangazonWebContext context; private readonly UserManager _userManager; //Method Name: ShoppingCartViewModel //Purpose of the Method: Upon construction this should take the context and send a list of select items of the type PaymentType to the View. They should be the paymentTypes of the active customer. //Arguments in Method: BangazonUserAuthContext - public ShoppingCartViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) + public ShoppingCartViewModel(UserManager userManager, ApplicationDbContext ctx1) : base(userManager, ctx1) { _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/Models/BangazonWebViewModels/SingleProductViewModel.cs b/src/BangazonUserAuth/Models/BangazonWebViewModels/SingleProductViewModel.cs index bf39695..a1d2d3f 100644 --- a/src/BangazonUserAuth/Models/BangazonWebViewModels/SingleProductViewModel.cs +++ b/src/BangazonUserAuth/Models/BangazonWebViewModels/SingleProductViewModel.cs @@ -15,6 +15,6 @@ public class SingleProductViewModel : BaseViewModel public string CustomerName {get;set;} //Displayed on detail view to show sellers name. - public SingleProductViewModel(UserManager userManager, ApplicationDbContext ctx1, BangazonWebContext ctx2) : base(userManager, ctx1, ctx2) { } + public SingleProductViewModel(UserManager userManager, ApplicationDbContext ctx1) : base(userManager, ctx1) { } } } diff --git a/src/BangazonUserAuth/Models/Customer.cs b/src/BangazonUserAuth/Models/Customer.cs deleted file mode 100644 index 30ab9a0..0000000 --- a/src/BangazonUserAuth/Models/Customer.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - - -namespace BangazonUserAuth.Models -{ - //Class Name: Customer - //Author: Chris Smalley And Debbie Bourne - //Purpose of the class: This class serves as a model for our Customer objects being transfered, manipulated, and saved between our Database, context, and Views. - //Methods in Class: None. - public class Customer - { - [Key] - public int CustomerId {get;set;} - - [Required] - [StringLength(50)] - public string FirstName {get;set;} - - [Required] - [StringLength(50)] - public string LastName {get;set;} - - public ICollection PaymentTypes; - - public ICollection Orders; - } -} diff --git a/src/BangazonUserAuth/Models/Order.cs b/src/BangazonUserAuth/Models/Order.cs index ff0120d..ed6b7f8 100644 --- a/src/BangazonUserAuth/Models/Order.cs +++ b/src/BangazonUserAuth/Models/Order.cs @@ -20,8 +20,8 @@ public class Order public PaymentType PaymentType {get; set;} [Required] - public int CustomerId {get; set;} - public Customer Customer {get; set;} + public virtual ApplicationUser User { get; set; } + public ICollection LineItems; [Required] diff --git a/src/BangazonUserAuth/Models/PaymentType.cs b/src/BangazonUserAuth/Models/PaymentType.cs index ed74400..4888315 100644 --- a/src/BangazonUserAuth/Models/PaymentType.cs +++ b/src/BangazonUserAuth/Models/PaymentType.cs @@ -12,11 +12,11 @@ public class PaymentType { [Key] public int PaymentTypeId {get;set;} - + + [Required] - public int CustomerId {get;set;} + public virtual ApplicationUser User { get; set; } - public Customer Customer {get;set;} [Required] public string CardNumber {get;set;} diff --git a/src/BangazonUserAuth/Models/Product.cs b/src/BangazonUserAuth/Models/Product.cs index 56a39c9..f30fedc 100644 --- a/src/BangazonUserAuth/Models/Product.cs +++ b/src/BangazonUserAuth/Models/Product.cs @@ -29,9 +29,9 @@ public class Product [Required] // Added to ProductTypeId public int SubProductTypeId { get; set; } public SubProductType SubProductType { get; set; } - public ICollection LineItems; + public ICollection LineItems; [Required] - public int CustomerId {get;set;} - public Customer Customer {get;set;} - } + public virtual ApplicationUser User { get; set; } + + } } diff --git a/src/BangazonUserAuth/Startup.cs b/src/BangazonUserAuth/Startup.cs index 85fb481..a61edd6 100644 --- a/src/BangazonUserAuth/Startup.cs +++ b/src/BangazonUserAuth/Startup.cs @@ -55,10 +55,6 @@ public void ConfigureServices(IServiceCollection services) .AllowAnyHeader()); }); - string path = System.Environment.GetEnvironmentVariable("NTABangazonWeb_Db_Path"); - var connection = $"Filename={path}"; - services.AddDbContext(options => options.UseSqlite(connection)); - // Add application services. services.AddTransient(); services.AddTransient(); diff --git a/src/BangazonUserAuth/Views/Customers/Payment.cshtml b/src/BangazonUserAuth/Views/Customers/Payment.cshtml index 47e40c5..c1da069 100644 --- a/src/BangazonUserAuth/Views/Customers/Payment.cshtml +++ b/src/BangazonUserAuth/Views/Customers/Payment.cshtml @@ -9,11 +9,7 @@
-
-
- -
-
+
diff --git a/src/BangazonUserAuth/Views/Shared/_Layout.cshtml b/src/BangazonUserAuth/Views/Shared/_Layout.cshtml index 26685c2..f2e2216 100644 --- a/src/BangazonUserAuth/Views/Shared/_Layout.cshtml +++ b/src/BangazonUserAuth/Views/Shared/_Layout.cshtml @@ -30,8 +30,8 @@