├── src ├── Commerce.Web │ ├── wwwroot │ │ ├── js │ │ │ ├── site.min.js │ │ │ └── site.js │ │ ├── favicon.ico │ │ ├── lib │ │ │ ├── bootstrap │ │ │ │ ├── dist │ │ │ │ │ ├── fonts │ │ │ │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ │ │ │ └── glyphicons-halflings-regular.woff2 │ │ │ │ │ ├── js │ │ │ │ │ │ └── npm.js │ │ │ │ │ └── css │ │ │ │ │ │ └── bootstrap-theme.min.css.map │ │ │ │ ├── .bower.json │ │ │ │ └── LICENSE │ │ │ ├── jquery │ │ │ │ ├── .bower.json │ │ │ │ └── LICENSE.txt │ │ │ ├── jquery-validation │ │ │ │ ├── .bower.json │ │ │ │ └── LICENSE.md │ │ │ └── jquery-validation-unobtrusive │ │ │ │ ├── .bower.json │ │ │ │ └── jquery.validate.unobtrusive.min.js │ │ ├── _references.js │ │ ├── css │ │ │ ├── site.min.css │ │ │ └── site.css │ │ └── images │ │ │ ├── banner2.svg │ │ │ ├── banner1.svg │ │ │ ├── banner3.svg │ │ │ └── banner4.svg │ ├── .bowerrc │ ├── Views │ │ ├── _ViewStart.cshtml │ │ ├── Home │ │ │ ├── About.cshtml │ │ │ ├── Contact.cshtml │ │ │ └── Index.cshtml │ │ ├── Account │ │ │ ├── ForgotPasswordConfirmation.cshtml │ │ │ ├── ExternalLoginFailure.cshtml │ │ │ ├── Lockout.cshtml │ │ │ ├── ResetPasswordConfirmation.cshtml │ │ │ ├── ConfirmEmail.cshtml │ │ │ ├── SendCode.cshtml │ │ │ ├── ForgotPassword.cshtml │ │ │ ├── ExternalLoginConfirmation.cshtml │ │ │ ├── VerifyCode.cshtml │ │ │ ├── Register.cshtml │ │ │ ├── ResetPassword.cshtml │ │ │ └── Login.cshtml │ │ ├── _ViewImports.cshtml │ │ ├── Shared │ │ │ ├── Error.cshtml │ │ │ ├── _ValidationScriptsPartial.cshtml │ │ │ ├── _LoginPartial.cshtml │ │ │ └── _Layout.cshtml │ │ └── Manage │ │ │ ├── AddPhoneNumber.cshtml │ │ │ ├── VerifyPhoneNumber.cshtml │ │ │ ├── SetPassword.cshtml │ │ │ ├── ChangePassword.cshtml │ │ │ ├── ManageLogins.cshtml │ │ │ └── Index.cshtml │ ├── Areas │ │ └── Admin │ │ │ ├── Views │ │ │ ├── _ViewStart.cshtml │ │ │ ├── Shared │ │ │ │ ├── Layouts │ │ │ │ │ ├── Partials │ │ │ │ │ │ ├── _Header.cshtml │ │ │ │ │ │ └── _Footer.cshtml │ │ │ │ │ └── _Layout.cshtml │ │ │ │ └── _ValidationScriptsPartial.cshtml │ │ │ ├── Home │ │ │ │ └── Index.cshtml │ │ │ └── _ViewImports.cshtml │ │ │ └── Controllers │ │ │ └── HomeController.cs │ ├── bower.json │ ├── Services │ │ ├── ISmsSender.cs │ │ ├── IEmailSender.cs │ │ └── MessageServices.cs │ ├── Models │ │ ├── ManageViewModels │ │ │ ├── FactorViewModel.cs │ │ │ ├── RemoveLoginViewModel.cs │ │ │ ├── ConfigureTwoFactorViewModel.cs │ │ │ ├── AddPhoneNumberViewModel.cs │ │ │ ├── ManageLoginsViewModel.cs │ │ │ ├── VerifyPhoneNumberViewModel.cs │ │ │ ├── IndexViewModel.cs │ │ │ ├── SetPasswordViewModel.cs │ │ │ └── ChangePasswordViewModel.cs │ │ └── AccountViewModels │ │ │ ├── ForgotPasswordViewModel.cs │ │ │ ├── ExternalLoginConfirmationViewModel.cs │ │ │ ├── SendCodeViewModel.cs │ │ │ ├── LoginViewModel.cs │ │ │ ├── VerifyCodeViewModel.cs │ │ │ ├── ResetPasswordViewModel.cs │ │ │ └── RegisterViewModel.cs │ ├── appsettings.json │ ├── web.config │ ├── Program.cs │ ├── bundleconfig.json │ ├── Properties │ │ └── launchSettings.json │ ├── Controllers │ │ ├── HomeController.cs │ │ └── DemoController.cs │ ├── Commerce.Web.xproj │ ├── project.json │ └── Startup.cs ├── Commerce.Contracts │ ├── Models │ │ ├── IModelBase.cs │ │ ├── IUser.cs │ │ ├── IBasketItem.cs │ │ ├── IOrder.cs │ │ ├── ICategory.cs │ │ ├── IVoucherType.cs │ │ ├── IOrderItem.cs │ │ ├── IBasketVoucher.cs │ │ ├── IProduct.cs │ │ ├── IBasket.cs │ │ └── IVoucher.cs │ ├── project.json │ ├── EntityMapping │ │ └── IEntityMappingConfiguration.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Commerce.Contracts.xproj │ └── Repositories │ │ └── IRepositoryBase.cs ├── Commerce.DAL │ ├── TemporaryDeveloperTool │ │ ├── Program.cs │ │ └── TemporaryDbContextFactor.cs │ ├── project.json │ ├── EntityMapping │ │ ├── EntityMappingConfigurationBase.cs │ │ └── BasketMap.cs │ ├── Repositories │ │ ├── OrderRepository.cs │ │ ├── UserRepository.cs │ │ ├── ProductRepository.cs │ │ ├── VoucherRepository.cs │ │ ├── BasketRepository.cs │ │ ├── CategoryRepository.cs │ │ ├── OrdersRepository.cs │ │ ├── VoucherTypeRepository.cs │ │ ├── BasketVoucherRepository.cs │ │ └── RepositoryBase.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Commerce.DAL.xproj │ ├── Data │ │ └── DataContext.cs │ └── Initialize │ │ └── InitializeData.cs └── Commerce.Model │ ├── project.json │ ├── Entities │ ├── BasketItem.cs │ ├── OrderItem.cs │ ├── Category.cs │ ├── User.cs │ ├── BasketVoucher.cs │ ├── VoucherType.cs │ ├── Order.cs │ ├── Voucher.cs │ ├── Product.cs │ └── Basket.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── Commerce.Model.xproj ├── global.json ├── test ├── Commerce.DAL.Test │ ├── project.json │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RepositoryTest.cs │ └── Commerce.DAL.Test.xproj └── Commerce.Web.Test │ ├── Properties │ └── AssemblyInfo.cs │ ├── project.json │ ├── DemoControllerTest.cs │ ├── Commerce.Web.Test.xproj │ └── ManageControllerTest.cs ├── README.md ├── .gitattributes ├── e-Commerce.sln └── .gitignore /src/Commerce.Web/wwwroot/js/site.min.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Commerce.Web/.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "wwwroot/lib" 3 | } 4 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Write your Javascript code. 2 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "Layouts/_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Views/Shared/Layouts/Partials/_Header.cshtml: -------------------------------------------------------------------------------- 1 | 2 |

Admin Header

3 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ "src", "test" ], 3 | "sdk": { 4 | "version": "1.0.0-preview2-003121" 5 | } 6 | } -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eyupgevenim/e-Commerce/HEAD/src/Commerce.Web/wwwroot/favicon.ico -------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Admin Index"; 3 | } 4 | 5 | 6 |

Admin Index

-------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Views/Shared/Layouts/Partials/_Footer.cshtml: -------------------------------------------------------------------------------- 1 | 2 |
3 | 6 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Home/About.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "About"; 3 | } 4 |

@ViewData["Title"].

5 |

@ViewData["Message"]

6 | 7 |

Use this area to provide additional information.

8 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eyupgevenim/e-Commerce/HEAD/src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eyupgevenim/e-Commerce/HEAD/src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eyupgevenim/e-Commerce/HEAD/src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eyupgevenim/e-Commerce/HEAD/src/Commerce.Web/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/ForgotPasswordConfirmation.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Forgot Password Confirmation"; 3 | } 4 | 5 |

@ViewData["Title"].

6 |

7 | Please check your email to reset your password. 8 |

9 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/ExternalLoginFailure.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Login Failure"; 3 | } 4 | 5 |
6 |

@ViewData["Title"].

7 |

Unsuccessful login with service.

8 |
9 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/Lockout.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Locked out"; 3 | } 4 | 5 |
6 |

Locked out.

7 |

This account has been locked out, please try again later.

8 |
9 | -------------------------------------------------------------------------------- /src/Commerce.Web/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "asp.net", 3 | "private": true, 4 | "dependencies": { 5 | "bootstrap": "3.3.6", 6 | "jquery": "2.2.0", 7 | "jquery-validation": "1.14.0", 8 | "jquery-validation-unobtrusive": "3.2.6" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/ResetPasswordConfirmation.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Reset password confirmation"; 3 | } 4 | 5 |

@ViewData["Title"].

6 |

7 | Your password has been reset. Please Click here to log in. 8 |

9 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IModelBase 9 | { 10 | object Id { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/ConfirmEmail.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Confirm Email"; 3 | } 4 | 5 |

@ViewData["Title"].

6 |
7 |

8 | Thank you for confirming your email. Please Click here to Log in. 9 |

10 |
11 | -------------------------------------------------------------------------------- /src/Commerce.Web/Services/ISmsSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Web.Services 7 | { 8 | public interface ISmsSender 9 | { 10 | Task SendSmsAsync(string number, string message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/FactorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Web.Models.ManageViewModels 7 | { 8 | public class FactorViewModel 9 | { 10 | public string Purpose { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Commerce.Web/Services/IEmailSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Web.Services 7 | { 8 | public interface IEmailSender 9 | { 10 | Task SendEmailAsync(string email, string subject, string message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Commerce.DAL/TemporaryDeveloperTool/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.DAL.TemporaryDeveloperTool 7 | { 8 | public class Program 9 | { 10 | public static void Main(string[] args) 11 | { 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using Commerce.Web 2 | @using Commerce.Web.Models 3 | @using Commerce.Web.Models.AccountViewModels 4 | @using Commerce.Web.Models.ManageViewModels 5 | @using Microsoft.AspNetCore.Identity 6 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 7 | @inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration 8 | -------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using Commerce.Web 2 | @using Commerce.Web.Models 3 | @using Commerce.Web.Models.AccountViewModels 4 | @using Commerce.Web.Models.ManageViewModels 5 | @using Microsoft.AspNetCore.Identity 6 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 7 | @inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/_references.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 6 | 7 | namespace Commerce.Contracts.Models 8 | { 9 | public interface IUser 10 | { 11 | ICollection IOrders { get; } 12 | ICollection IBaskets { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IBasketItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IBasketItem 9 | { 10 | int Id { get; set; } 11 | int Quantity { get; set; } 12 | 13 | string BasketId { get; set; } 14 | 15 | int ProductId { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IOrder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IOrder 9 | { 10 | int Id { get; set; } 11 | DateTime OrderDate { get; set; } 12 | 13 | string UserId { get; set; } 14 | 15 | ICollection IOrderItems { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/AccountViewModels/ForgotPasswordViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.AccountViewModels 8 | { 9 | public class ForgotPasswordViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/RemoveLoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.ManageViewModels 8 | { 9 | public class RemoveLoginViewModel 10 | { 11 | public string LoginProvider { get; set; } 12 | public string ProviderKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/css/site.min.css: -------------------------------------------------------------------------------- 1 | body{padding-top:50px;padding-bottom:20px}.body-content{padding-left:15px;padding-right:15px}input,select,textarea{max-width:280px}.carousel-caption p{font-size:20px;line-height:1.4}.btn-bracketed::before{display:inline-block;content:"[";padding-right:.5em}.btn-bracketed::after{display:inline-block;content:"]";padding-left:.5em}.carousel-inner .item img[src$=".svg"]{width:100%}@media screen and (max-width:767px){.carousel-caption{display:none}} -------------------------------------------------------------------------------- /src/Commerce.Web/Models/AccountViewModels/ExternalLoginConfirmationViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.AccountViewModels 8 | { 9 | public class ExternalLoginConfirmationViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/ICategory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface ICategory 9 | { 10 | int Id { get; set; } 11 | string CategoryName { get; set; } 12 | string Description { get; set; } 13 | string Picture { get; set; } 14 | ICollection IProducts { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | 4 | "dependencies": { 5 | "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", 6 | "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0", 7 | "NETStandard.Library": "1.6.0" 8 | }, 9 | 10 | "frameworks": { 11 | "netstandard1.6": { 12 | "imports": "dnxcore50" 13 | } 14 | }, 15 | "tools": { 16 | "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IVoucherType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IVoucherType 9 | { 10 | int Id { get; set; } 11 | string Description { get; set; } 12 | string Type { get; set; } 13 | string VoucherModule { get; set; } 14 | 15 | ICollection IVouchers { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Commerce.Web/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ApplicationInsights": { 3 | "InstrumentationKey": "" 4 | }, 5 | "ConnectionStrings": { 6 | "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=e_CommerceDatabase;Trusted_Connection=True;MultipleActiveResultSets=true" 7 | }, 8 | "Logging": { 9 | "IncludeScopes": false, 10 | "LogLevel": { 11 | "Default": "Debug", 12 | "System": "Information", 13 | "Microsoft": "Information" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/ConfigureTwoFactorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc.Rendering; 6 | 7 | namespace Commerce.Web.Models.ManageViewModels 8 | { 9 | public class ConfigureTwoFactorViewModel 10 | { 11 | public string SelectedProvider { get; set; } 12 | 13 | public ICollection Providers { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/AddPhoneNumberViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.ManageViewModels 8 | { 9 | public class AddPhoneNumberViewModel 10 | { 11 | [Required] 12 | [Phone] 13 | [Display(Name = "Phone number")] 14 | public string PhoneNumber { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Authorization; 7 | 8 | namespace Commerce.Web.Areas.Admin.Controllers 9 | { 10 | [Area("Admin")] 11 | [Authorize(Roles = "Admin")] 12 | public class HomeController : Controller 13 | { 14 | public IActionResult Index() 15 | { 16 | return View(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/ManageLoginsViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http.Authentication; 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | namespace Commerce.Web.Models.ManageViewModels 9 | { 10 | public class ManageLoginsViewModel 11 | { 12 | public IList CurrentLogins { get; set; } 13 | 14 | public IList OtherLogins { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Home/Contact.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Contact"; 3 | } 4 |

@ViewData["Title"].

5 |

@ViewData["Message"]

6 | 7 |
8 | One Microsoft Way
9 | Redmond, WA 98052-6399
10 | P: 11 | 425.555.0100 12 |
13 | 14 |
15 | Support: Support@example.com
16 | Marketing: Marketing@example.com 17 |
18 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IOrderItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IOrderItem 9 | { 10 | int Id { get; set; } 11 | 12 | int ProductId { get; set; } 13 | 14 | int OrderId { get; set; } 15 | 16 | string Description { get; set; } 17 | string ImageUrl { get; set; } 18 | int Quantity { get; set; } 19 | decimal Price { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Commerce.Model/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Commerce.Contracts": "1.0.0-*", 4 | "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", 5 | "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0", 6 | "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" 7 | }, 8 | "frameworks": { 9 | "netcoreapp1.0": { 10 | "imports": [ "dotnet5.6", "portable-net45+win8" ] 11 | } 12 | }, 13 | "tools": { 14 | "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" 15 | }, 16 | "version": "1.0.0-*" 17 | } 18 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/dist/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/VerifyPhoneNumberViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.ManageViewModels 8 | { 9 | public class VerifyPhoneNumberViewModel 10 | { 11 | [Required] 12 | public string Code { get; set; } 13 | 14 | [Required] 15 | [Phone] 16 | [Display(Name = "Phone number")] 17 | public string PhoneNumber { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/AccountViewModels/SendCodeViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc.Rendering; 6 | 7 | namespace Commerce.Web.Models.AccountViewModels 8 | { 9 | public class SendCodeViewModel 10 | { 11 | public string SelectedProvider { get; set; } 12 | 13 | public ICollection Providers { get; set; } 14 | 15 | public string ReturnUrl { get; set; } 16 | 17 | public bool RememberMe { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/IndexViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Identity; 6 | 7 | namespace Commerce.Web.Models.ManageViewModels 8 | { 9 | public class IndexViewModel 10 | { 11 | public bool HasPassword { get; set; } 12 | 13 | public IList Logins { get; set; } 14 | 15 | public string PhoneNumber { get; set; } 16 | 17 | public bool TwoFactor { get; set; } 18 | 19 | public bool BrowserRemembered { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Commerce.Web/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/EntityMapping/IEntityMappingConfiguration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Contracts.EntityMapping 9 | { 10 | public interface IEntityMappingConfiguration 11 | { 12 | void Map(ModelBuilder b); 13 | } 14 | 15 | public interface IEntityMappingConfiguration : IEntityMappingConfiguration where T : class 16 | { 17 | void Map(EntityTypeBuilder builder); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IBasketVoucher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IBasketVoucher 9 | { 10 | int Id { get; set; } 11 | int AppliesToProductId { get; set; } 12 | decimal Value { get; set; } 13 | string VoucherCode { get; set; } 14 | string VoucherDescription { get; set; } 15 | string VoucherType { get; set; } 16 | 17 | string BasketId { get; set; } 18 | 19 | int VoucherId { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IProduct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IProduct 9 | { 10 | int Id { get; set; } 11 | decimal CostPrice { get; set; } 12 | string Description { get; set; } 13 | string ImageUrl { get; set; } 14 | decimal Price { get; set; } 15 | 16 | int CategoryId { get; set; } 17 | 18 | ICollection IOrderItems { get; } 19 | ICollection IBasketItems { get; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Commerce.DAL/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "buildOptions": { 3 | "emitEntryPoint": true 4 | }, 5 | "frameworks": { 6 | "netcoreapp1.0": {} 7 | }, 8 | "dependencies": { 9 | "Commerce.Model": "1.0.0-*", 10 | "Microsoft.NETCore.App": { 11 | "version": "1.0.0", 12 | "type": "platform" 13 | }, 14 | "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final", 15 | "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", 16 | "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0" 17 | }, 18 | "tools": { 19 | "Microsoft.EntityFrameworkCore.Tools": { 20 | "version": "1.0.0-preview2-final" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Commerce.Web/Models/AccountViewModels/LoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.AccountViewModels 8 | { 9 | public class LoginViewModel 10 | { 11 | [Required] 12 | //[EmailAddress] 13 | public string Email { get; set; } 14 | 15 | [Required] 16 | [DataType(DataType.Password)] 17 | public string Password { get; set; } 18 | 19 | [Display(Name = "Remember me?")] 20 | public bool RememberMe { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/jquery/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "main": "dist/jquery.js", 4 | "license": "MIT", 5 | "ignore": [ 6 | "package.json" 7 | ], 8 | "keywords": [ 9 | "jquery", 10 | "javascript", 11 | "browser", 12 | "library" 13 | ], 14 | "homepage": "https://github.com/jquery/jquery-dist", 15 | "version": "2.2.0", 16 | "_release": "2.2.0", 17 | "_resolution": { 18 | "type": "version", 19 | "tag": "2.2.0", 20 | "commit": "6fc01e29bdad0964f62ef56d01297039cdcadbe5" 21 | }, 22 | "_source": "git://github.com/jquery/jquery-dist.git", 23 | "_target": "2.2.0", 24 | "_originalSource": "jquery" 25 | } -------------------------------------------------------------------------------- /src/Commerce.Web/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Hosting; 7 | 8 | namespace Commerce.Web 9 | { 10 | public class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | var host = new WebHostBuilder() 15 | .UseKestrel() 16 | .UseContentRoot(Directory.GetCurrentDirectory()) 17 | .UseIISIntegration() 18 | .UseStartup() 19 | .Build(); 20 | 21 | host.Run(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Commerce.DAL/EntityMapping/EntityMappingConfigurationBase.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.EntityMapping; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace Commerce.DAL.EntityMapping 10 | { 11 | public abstract class EntityMappingConfigurationBase : IEntityMappingConfiguration where T : class 12 | { 13 | public abstract void Map(EntityTypeBuilder b); 14 | 15 | public void Map(ModelBuilder b) 16 | { 17 | Map(b.Entity()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/BasketItem.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class BasketItem : IBasketItem 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | public int Quantity { get; set; } 15 | 16 | public int ProductId { get; set; } 17 | public virtual Product Product { get; set; } 18 | 19 | public string BasketId { get; set; } 20 | public virtual Basket Basket { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Commerce.DAL/EntityMapping/BasketMap.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Model.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 7 | 8 | namespace Commerce.DAL.EntityMapping 9 | { 10 | public class BasketMap : EntityMappingConfigurationBase 11 | { 12 | public override void Map(EntityTypeBuilder b) 13 | { 14 | b.HasKey(x => x.Id); 15 | b.Property(x => x.date).IsRequired(); 16 | //... 17 | b.HasOne(o => o.User).WithMany(m => m.Baskets).HasForeignKey(f => f.UserId); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IBasket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IBasket 9 | { 10 | string Id { get; set; } 11 | DateTime date { get; set; } 12 | 13 | ICollection IBasketItems { get; } 14 | ICollection IBasketVouchers { get; } 15 | 16 | string UserId { get; set; } 17 | 18 | void AddBasketItem(IBasketItem item); 19 | void AddBasketVoucher(IBasketVoucher voucher); 20 | decimal BasketTotal(); 21 | decimal BasketItemCount(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Models/IVoucher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Models 7 | { 8 | public interface IVoucher 9 | { 10 | int Id { get; set; } 11 | int AppliesToProductId { get; set; } 12 | string AssignedTo { get; set; } 13 | decimal MinSpend { get; set; } 14 | bool multipleUse { get; set; } 15 | decimal Value { get; set; } 16 | string VoucherCode { get; set; } 17 | string VoucherDescription { get; set; } 18 | 19 | int VoucherTypeId { get; set; } 20 | 21 | ICollection IBasketVouchers { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Commerce.Web/bundleconfig.json: -------------------------------------------------------------------------------- 1 | // Configure bundling and minification for the project. 2 | // More info at https://go.microsoft.com/fwlink/?LinkId=808241 3 | [ 4 | { 5 | "outputFileName": "wwwroot/css/site.min.css", 6 | // An array of relative input file paths. Globbing patterns supported 7 | "inputFiles": [ 8 | "wwwroot/css/site.css" 9 | ] 10 | }, 11 | { 12 | "outputFileName": "wwwroot/js/site.min.js", 13 | "inputFiles": [ 14 | "wwwroot/js/site.js" 15 | ], 16 | // Optionally specify minification options 17 | "minify": { 18 | "enabled": true, 19 | "renameLocals": true 20 | }, 21 | // Optinally generate .map file 22 | "sourceMap": false 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/AccountViewModels/VerifyCodeViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.AccountViewModels 8 | { 9 | public class VerifyCodeViewModel 10 | { 11 | [Required] 12 | public string Provider { get; set; } 13 | 14 | [Required] 15 | public string Code { get; set; } 16 | 17 | public string ReturnUrl { get; set; } 18 | 19 | [Display(Name = "Remember this browser?")] 20 | public bool RememberBrowser { get; set; } 21 | 22 | [Display(Name = "Remember me?")] 23 | public bool RememberMe { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Commerce.Web/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:15725/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Commerce.Web": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "launchUrl": "http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Error"; 3 | } 4 | 5 |

Error.

6 |

An error occurred while processing your request.

7 | 8 |

Development Mode

9 |

10 | Swapping to Development environment will display more detailed information about the error that occurred. 11 |

12 |

13 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. 14 |

15 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/SendCode.cshtml: -------------------------------------------------------------------------------- 1 | @model SendCodeViewModel 2 | @{ 3 | ViewData["Title"] = "Send Verification Code"; 4 | } 5 | 6 |

@ViewData["Title"].

7 | 8 |
9 | 10 |
11 |
12 | Select Two-Factor Authentication Provider: 13 | 14 | 15 |
16 |
17 |
18 | 19 | @section Scripts { 20 | @{await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 21 | } 22 | -------------------------------------------------------------------------------- /src/Commerce.DAL/TemporaryDeveloperTool/TemporaryDbContextFactor.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace Commerce.DAL.TemporaryDeveloperTool 10 | { 11 | public class TemporaryDbContextFactory : IDbContextFactory 12 | { 13 | public DataContext Create(DbContextFactoryOptions options) 14 | { 15 | var builder = new DbContextOptionsBuilder(); 16 | builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=e_CommerceDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"); 17 | return new DataContext(builder.Options); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/OrderItem.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class OrderItem : IOrderItem 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | public string Description { get; set; } 15 | 16 | [MaxLength(255)] 17 | public string ImageUrl { get; set; } 18 | 19 | public int Quantity { get; set; } 20 | public decimal Price { get; set; } 21 | 22 | public int ProductId { get; set; } 23 | public virtual Product Product { get; set; } 24 | 25 | public int OrderId { get; set; } 26 | public virtual Order Order { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/Commerce.DAL.Test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | 4 | "testRunner": "xunit", 5 | 6 | "dependencies": { 7 | 8 | "Microsoft.NETCore.App": { 9 | "type": "platform", 10 | "version": "1.0.0" 11 | }, 12 | "xunit": "2.2.0-beta2-build3300", 13 | "dotnet-test-xunit": "2.2.0-preview2-build1029", 14 | "Moq": "4.7.99", 15 | "System.Diagnostics.Tracing": "4.3.0", 16 | 17 | "Commerce.DAL": { "target": "project" }, 18 | "Commerce.Contracts": { "target": "project" }, 19 | "Commerce.Web": { "target": "project" } 20 | }, 21 | 22 | "frameworks": { 23 | "netcoreapp1.0": { 24 | "imports": [ 25 | "dotnet54", 26 | "portable-net45+win8" 27 | ] 28 | } 29 | }, 30 | 31 | "tools": { 32 | "Microsoft.EntityFrameworkCore.Tools": { 33 | "version": "1.0.0-preview2-final" 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/OrderRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class OrderRepository : RepositoryBase 11 | { 12 | public OrderRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.Orders.FirstOrDefault(x => x.Id == (int)id)); 21 | base.Commit(); 22 | } 23 | 24 | public override Order GetById(object id) 25 | { 26 | return context.Orders.Single(s=>s.Id == (int)id); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class UserRepository : RepositoryBase 11 | { 12 | public UserRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.Users.FirstOrDefault(x => x.Id == id.ToString())); 21 | base.Commit(); 22 | } 23 | 24 | public override User GetById(object id) 25 | { 26 | return context.Users.Single(s => s.Id == id.ToString()); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/SetPasswordViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.ManageViewModels 8 | { 9 | public class SetPasswordViewModel 10 | { 11 | [Required] 12 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 13 | [DataType(DataType.Password)] 14 | [Display(Name = "New password")] 15 | public string NewPassword { get; set; } 16 | 17 | [DataType(DataType.Password)] 18 | [Display(Name = "Confirm new password")] 19 | [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] 20 | public string ConfirmPassword { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class ProductRepository : RepositoryBase 11 | { 12 | public ProductRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.Products.FirstOrDefault(x => x.Id == (int)id)); 21 | base.Commit(); 22 | } 23 | 24 | public override Product GetById(object id) 25 | { 26 | return context.Products.Single(s => s.Id == (int)id); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/VoucherRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class VoucherRepository : RepositoryBase 11 | { 12 | public VoucherRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.Vouchers.FirstOrDefault(x => x.Id == (int)id)); 21 | base.Commit(); 22 | } 23 | 24 | public override Voucher GetById(object id) 25 | { 26 | return context.Vouchers.Single(s => s.Id == (int)id); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/BasketRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Commerce.Model.Entities; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class BasketRepository : RepositoryBase 11 | { 12 | public BasketRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.Baskets.FirstOrDefault(x => x.Id == id.ToString())); 21 | base.Commit(); 22 | } 23 | 24 | public override Basket GetById(object id) 25 | { 26 | return context.Baskets.Single(s => s.Id == id.ToString()); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("Commerce.DAL")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("a0cdb1a5-8427-4b12-87b2-a7ad61b75383")] 20 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/CategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class CategoryRepository : RepositoryBase 11 | { 12 | public CategoryRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.Categories.FirstOrDefault(x => x.Id == (int)id)); 21 | base.Commit(); 22 | } 23 | 24 | public override Category GetById(object id) 25 | { 26 | return context.Categories.Single(s => s.Id == (int)id); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/Category.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class Category : ICategory 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | public string CategoryName { get; set; } 15 | public string Description { get; set; } 16 | public string Picture { get; set; } 17 | 18 | public virtual ICollection Products { get; set; } 19 | 20 | public virtual ICollection IProducts 21 | { 22 | get { return Products.Select(s => (IProduct)s).ToList(); } 23 | } 24 | 25 | public Category() 26 | { 27 | this.Products = new HashSet(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Commerce.Model/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("Commerce.Model")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("10d1b1d7-29c2-45df-8066-4102d96780e5")] 20 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("Commerce.Contracts")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("7131b84e-faab-479a-bf50-0c2f1867dd25")] 20 | -------------------------------------------------------------------------------- /test/Commerce.DAL.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("Commerce.DAL.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("077847dc-fcc6-4639-89db-5ef58726d18b")] 20 | -------------------------------------------------------------------------------- /test/Commerce.Web.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("Commerce.Web.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("fb73ee50-e5fe-4517-8ed6-375da2638ef5")] 20 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/OrdersRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class OrdersRepository : RepositoryBase 11 | { 12 | public OrdersRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | { 16 | throw new ArgumentNullException(); 17 | } 18 | } 19 | 20 | public override void Delete(object id) 21 | { 22 | base.Delete(context.Orders.FirstOrDefault(x => x.Id == (int)id)); 23 | base.Commit(); 24 | } 25 | 26 | public override Order GetById(object id) 27 | { 28 | return context.Orders.Single(s => s.Id == (int)id); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/VoucherTypeRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class VoucherTypeRepository : RepositoryBase 11 | { 12 | public VoucherTypeRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.VoucherTypes.FirstOrDefault(x => x.Id == (int)id)); 21 | base.Commit(); 22 | } 23 | 24 | public override VoucherType GetById(object id) 25 | { 26 | return context.VoucherTypes.Single(s => s.Id == (int)id); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Commerce.Web.Test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | 4 | "testRunner": "xunit", 5 | 6 | "dependencies": { 7 | 8 | "Microsoft.NETCore.App": { 9 | "type": "platform", 10 | "version": "1.0.0" 11 | }, 12 | "xunit": "2.2.0-beta2-build3300", 13 | "dotnet-test-xunit": "2.2.0-preview2-build1029", 14 | "Moq": "4.7.99", 15 | "System.Diagnostics.Tracing": "4.3.0", 16 | 17 | "Commerce.DAL": { "target": "project" }, 18 | "Commerce.Contracts": { "target": "project" }, 19 | "Commerce.Web": { "target": "project" }, 20 | "Microsoft.EntityFrameworkCore.InMemory": "1.1.2" 21 | }, 22 | 23 | "frameworks": { 24 | "netcoreapp1.0": { 25 | "imports": [ 26 | "dotnet54", 27 | "portable-net45+win8" 28 | ] 29 | } 30 | }, 31 | 32 | "tools": { 33 | "Microsoft.EntityFrameworkCore.Tools": { 34 | "version": "1.0.0-preview2-final" 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/BasketVoucherRepository.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.DAL.Repositories 9 | { 10 | public class BasketVoucherRepository : RepositoryBase 11 | { 12 | public BasketVoucherRepository(DataContext context) : base(context) 13 | { 14 | if (context == null) 15 | throw new ArgumentNullException(); 16 | } 17 | 18 | public override void Delete(object id) 19 | { 20 | base.Delete(context.BasketVouchers.FirstOrDefault(x => x.Id == (int)id)); 21 | base.Commit(); 22 | } 23 | 24 | public override BasketVoucher GetById(object id) 25 | { 26 | return context.BasketVouchers.Single(s => s.Id == (int)id); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.Web/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Identity; 7 | using Commerce.Model.Entities; 8 | 9 | namespace Commerce.Web.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | public IActionResult Index() 14 | { 15 | return View(); 16 | } 17 | 18 | public IActionResult About() 19 | { 20 | ViewData["Message"] = "Your application description page."; 21 | 22 | return View(); 23 | } 24 | 25 | public IActionResult Contact() 26 | { 27 | ViewData["Message"] = "Your contact page."; 28 | 29 | return View(); 30 | } 31 | 32 | public IActionResult Error() 33 | { 34 | return View(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Commerce.Web/Services/MessageServices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Web.Services 7 | { 8 | // This class is used by the application to send Email and SMS 9 | // when you turn on two-factor authentication in ASP.NET Identity. 10 | // For more details see this link http://go.microsoft.com/fwlink/?LinkID=532713 11 | public class AuthMessageSender : IEmailSender, ISmsSender 12 | { 13 | public Task SendEmailAsync(string email, string subject, string message) 14 | { 15 | // Plug in your email service here to send an email. 16 | return Task.FromResult(0); 17 | } 18 | 19 | public Task SendSmsAsync(string number, string message) 20 | { 21 | // Plug in your SMS service here to send a text message. 22 | return Task.FromResult(0); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 6 | using Commerce.Contracts.Models; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class User : IdentityUser, IUser 11 | { 12 | public virtual ICollection Orders { get; set; } 13 | public virtual ICollection IOrders 14 | { 15 | get { return Orders.Select(s => (IOrder)s).ToList(); } 16 | } 17 | 18 | public virtual ICollection Baskets { get; set; } 19 | public virtual ICollection IBaskets 20 | { 21 | get { return Baskets.Select(s => (IBasket)s).ToList(); } 22 | } 23 | public User() 24 | { 25 | this.Orders = new HashSet(); 26 | this.Baskets = new HashSet(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 14 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/AccountViewModels/ResetPasswordViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.AccountViewModels 8 | { 9 | public class ResetPasswordViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | 15 | [Required] 16 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 17 | [DataType(DataType.Password)] 18 | public string Password { get; set; } 19 | 20 | [DataType(DataType.Password)] 21 | [Display(Name = "Confirm password")] 22 | [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 23 | public string ConfirmPassword { get; set; } 24 | 25 | public string Code { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/BasketVoucher.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class BasketVoucher : IBasketVoucher 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | 15 | [MaxLength(10)] 16 | public string VoucherCode { get; set; } 17 | 18 | [MaxLength(100)] 19 | public string VoucherType { get; set; } 20 | 21 | public decimal Value { get; set; } 22 | 23 | [MaxLength(150)] 24 | public string VoucherDescription { get; set; } 25 | 26 | public int AppliesToProductId { get; set; } 27 | 28 | public string BasketId { get; set; } 29 | public virtual Basket Basket { get; set; } 30 | 31 | public int VoucherId { get; set; } 32 | public virtual Voucher Voucher { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/AccountViewModels/RegisterViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.AccountViewModels 8 | { 9 | public class RegisterViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | [Display(Name = "Email")] 14 | public string Email { get; set; } 15 | 16 | [Required] 17 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 18 | [DataType(DataType.Password)] 19 | [Display(Name = "Password")] 20 | public string Password { get; set; } 21 | 22 | [DataType(DataType.Password)] 23 | [Display(Name = "Confirm password")] 24 | [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 25 | public string ConfirmPassword { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Commerce.Web/Controllers/DemoController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Commerce.Contracts.Repositories; 7 | using Commerce.Model.Entities; 8 | 9 | namespace Commerce.Web.Controllers 10 | { 11 | public class DemoController : Controller 12 | { 13 | private readonly IRepositoryBase _basket; 14 | 15 | public DemoController(IRepositoryBase basket) 16 | { 17 | _basket = basket; 18 | } 19 | 20 | public IActionResult Index() 21 | { 22 | _basket.GetAll(x => x.Id == "5"); 23 | return View(); 24 | } 25 | 26 | public void CreateBasket(Basket basket) 27 | { 28 | _basket.Insert(basket); 29 | _basket.Commit(); 30 | } 31 | 32 | public List GetBaskets() 33 | { 34 | return _basket.GetAll().ToList(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/VoucherType.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class VoucherType : IVoucherType 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | public string VoucherModule { get; set; } 15 | [MaxLength(30)] 16 | public string Type { get; set; } 17 | [MaxLength(150)] 18 | public string Description { get; set; } 19 | 20 | public virtual ICollection Vouchers { get; set; } 21 | public VoucherType() 22 | { 23 | this.Vouchers = new HashSet(); 24 | } 25 | public virtual ICollection IVouchers 26 | { 27 | get 28 | { 29 | return Vouchers.Select(s => (IVoucher)s).ToList(); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/Order.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class Order : IOrder 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | 15 | public DateTime OrderDate { get; set; } 16 | 17 | public int CustomerId { get; set; } 18 | 19 | public virtual ICollection OrderItems { get; set; } 20 | 21 | public Order() 22 | { 23 | this.OrderItems = new HashSet(); 24 | } 25 | 26 | public string UserId { get; set; } 27 | public User User { get; set; } 28 | 29 | public virtual ICollection IOrderItems 30 | { 31 | get 32 | { 33 | return OrderItems.Select(s => (IOrderItem)s).ToList(); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Manage/AddPhoneNumber.cshtml: -------------------------------------------------------------------------------- 1 | @model AddPhoneNumberViewModel 2 | @{ 3 | ViewData["Title"] = "Add Phone Number"; 4 | } 5 | 6 |

@ViewData["Title"].

7 |
8 |

Add a phone number.

9 |
10 |
11 |
12 | 13 |
14 | 15 | 16 |
17 |
18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 | @section Scripts { 26 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 27 | } 28 | -------------------------------------------------------------------------------- /src/Commerce.Web/Models/ManageViewModels/ChangePasswordViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Commerce.Web.Models.ManageViewModels 8 | { 9 | public class ChangePasswordViewModel 10 | { 11 | [Required] 12 | [DataType(DataType.Password)] 13 | [Display(Name = "Current password")] 14 | public string OldPassword { get; set; } 15 | 16 | [Required] 17 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 18 | [DataType(DataType.Password)] 19 | [Display(Name = "New password")] 20 | public string NewPassword { get; set; } 21 | 22 | [DataType(DataType.Password)] 23 | [Display(Name = "Confirm new password")] 24 | [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] 25 | public string ConfirmPassword { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Shared/_LoginPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @using Commerce.Web.Models 3 | @using Commerce.Model.Entities 4 | 5 | @inject SignInManager SignInManager 6 | @inject UserManager UserManager 7 | 8 | @if (SignInManager.IsSignedIn(User)) 9 | { 10 | 20 | } 21 | else 22 | { 23 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/jquery-validation/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-validation", 3 | "homepage": "http://jqueryvalidation.org/", 4 | "repository": { 5 | "type": "git", 6 | "url": "git://github.com/jzaefferer/jquery-validation.git" 7 | }, 8 | "authors": [ 9 | "Jörn Zaefferer " 10 | ], 11 | "description": "Form validation made easy", 12 | "main": "dist/jquery.validate.js", 13 | "keywords": [ 14 | "forms", 15 | "validation", 16 | "validate" 17 | ], 18 | "license": "MIT", 19 | "ignore": [ 20 | "**/.*", 21 | "node_modules", 22 | "bower_components", 23 | "test", 24 | "demo", 25 | "lib" 26 | ], 27 | "dependencies": { 28 | "jquery": ">= 1.7.2" 29 | }, 30 | "version": "1.14.0", 31 | "_release": "1.14.0", 32 | "_resolution": { 33 | "type": "version", 34 | "tag": "1.14.0", 35 | "commit": "c1343fb9823392aa9acbe1c3ffd337b8c92fed48" 36 | }, 37 | "_source": "git://github.com/jzaefferer/jquery-validation.git", 38 | "_target": ">=1.8", 39 | "_originalSource": "jquery-validation" 40 | } -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap", 3 | "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", 4 | "keywords": [ 5 | "css", 6 | "js", 7 | "less", 8 | "mobile-first", 9 | "responsive", 10 | "front-end", 11 | "framework", 12 | "web" 13 | ], 14 | "homepage": "http://getbootstrap.com", 15 | "license": "MIT", 16 | "moduleType": "globals", 17 | "main": [ 18 | "less/bootstrap.less", 19 | "dist/js/bootstrap.js" 20 | ], 21 | "ignore": [ 22 | "/.*", 23 | "_config.yml", 24 | "CNAME", 25 | "composer.json", 26 | "CONTRIBUTING.md", 27 | "docs", 28 | "js/tests", 29 | "test-infra" 30 | ], 31 | "dependencies": { 32 | "jquery": "1.9.1 - 2" 33 | }, 34 | "version": "3.3.6", 35 | "_release": "3.3.6", 36 | "_resolution": { 37 | "type": "version", 38 | "tag": "v3.3.6", 39 | "commit": "81df608a40bf0629a1dc08e584849bb1e43e0b7a" 40 | }, 41 | "_source": "git://github.com/twbs/bootstrap.git", 42 | "_target": "3.3.6", 43 | "_originalSource": "bootstrap" 44 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # e-Commerce 2 | e-Commerce [Asp.Net Core MVC 6 Multi Layer Project] 3 | 4 | 5 |

.Net Core sdk version

6 | 1.0.0-preview2-003121 7 | download 8 | 9 |

Project Directory

10 |
11 |
 
12 | 	e-Commerce[Solution]
13 | 		|
14 | 		|
15 | 		|------src
16 | 		|	|	
17 | 		|	|---Commerce.Contracts
18 | 		|	|
19 | 		|	|---Commerce.DAL
20 | 		|	|
21 | 		|	|---Commerce.Model
22 | 		|	|	
23 | 		|	|---Commerce.Web
24 | 		|
25 | 		|		
26 | 		|------test
27 | 			|
28 | 			|---Commerce.DAL.Test
29 | 			|	
30 | 			|---Commerce.Web.Test
31 | 				
32 | 
33 | 34 |

Edit database connection string in appsettings.json

35 | 36 | "DefaultConnection": "server=localhost;userid=root;pwd=[database password];port=[your port number]; 37 | database=ExamService;sslmode=none;charset=utf8;" 38 | 39 |
Example :
40 | 41 | "DefaultConnection": "server=localhost;userid=root;pwd=;port=3306; 42 | database=ExamService;sslmode=none;charset=utf8;" 43 | 44 | 45 | -------------------------------------------------------------------------------- /test/Commerce.DAL.Test/RepositoryTest.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Repositories; 2 | using Commerce.Model.Entities; 3 | using Commerce.Web.Controllers; 4 | using Moq; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | 11 | namespace Commerce.DAL.Test 12 | { 13 | public class RepositoryTest 14 | { 15 | [Fact] 16 | public void When_Get_Baskets() 17 | { 18 | var bList = new Basket[] 19 | { 20 | new Basket {UserId ="user id 1",date =DateTime.Now }, 21 | new Basket {UserId ="user id 2",date =DateTime.Now }, 22 | new Basket {UserId ="user id 3",date =DateTime.Now }, 23 | new Basket {UserId ="user id 4",date =DateTime.Now }, 24 | new Basket {UserId ="user id 5",date =DateTime.Now } 25 | }; 26 | 27 | var mockBasket = new Mock>(); 28 | mockBasket.Setup(x => x.GetAll()).Returns(() => bList.AsQueryable()); 29 | 30 | Assert.Equal(mockBasket.Object.GetAll().Count(), 5); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Manage/VerifyPhoneNumber.cshtml: -------------------------------------------------------------------------------- 1 | @model VerifyPhoneNumberViewModel 2 | @{ 3 | ViewData["Title"] = "Verify Phone Number"; 4 | } 5 | 6 |

@ViewData["Title"].

7 | 8 |
9 | 10 |

Add a phone number.

11 |
@ViewData["Status"]
12 |
13 |
14 |
15 | 16 |
17 | 18 | 19 |
20 |
21 |
22 |
23 | 24 |
25 |
26 |
27 | 28 | @section Scripts { 29 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 30 | } 31 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2015 Twitter, Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/ForgotPassword.cshtml: -------------------------------------------------------------------------------- 1 | @model ForgotPasswordViewModel 2 | @{ 3 | ViewData["Title"] = "Forgot your password?"; 4 | } 5 | 6 |

@ViewData["Title"]

7 |

8 | For more information on how to enable reset password please see this article. 9 |

10 | 11 | @*
12 |

Enter your email.

13 |
14 |
15 |
16 | 17 |
18 | 19 | 20 |
21 |
22 |
23 |
24 | 25 |
26 |
27 |
*@ 28 | 29 | @section Scripts { 30 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 31 | } 32 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Wrapping element */ 7 | /* Set some basic padding to keep content from hitting the edges */ 8 | .body-content { 9 | padding-left: 15px; 10 | padding-right: 15px; 11 | } 12 | 13 | /* Set widths on the form inputs since otherwise they're 100% wide */ 14 | input, 15 | select, 16 | textarea { 17 | max-width: 280px; 18 | } 19 | 20 | /* Carousel */ 21 | .carousel-caption p { 22 | font-size: 20px; 23 | line-height: 1.4; 24 | } 25 | 26 | /* buttons and links extension to use brackets: [ click me ] */ 27 | .btn-bracketed::before { 28 | display:inline-block; 29 | content: "["; 30 | padding-right: 0.5em; 31 | } 32 | .btn-bracketed::after { 33 | display:inline-block; 34 | content: "]"; 35 | padding-left: 0.5em; 36 | } 37 | 38 | /* Make .svg files in the carousel display properly in older browsers */ 39 | .carousel-inner .item img[src$=".svg"] 40 | { 41 | width: 100%; 42 | } 43 | 44 | /* Hide/rearrange for smaller screens */ 45 | @media screen and (max-width: 767px) { 46 | /* Hide captions */ 47 | .carousel-caption { 48 | display: none 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Commerce.DAL.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | a0cdb1a5-8427-4b12-87b2-a7ad61b75383 11 | Commerce.DAL 12 | .\obj 13 | .\bin\ 14 | v4.6.1 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Commerce.Model/Commerce.Model.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 10d1b1d7-29c2-45df-8066-4102d96780e5 11 | Commerce.Model 12 | .\obj 13 | .\bin\ 14 | v4.6.1 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Commerce.Contracts.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 7131b84e-faab-479a-bf50-0c2f1867dd25 11 | Commerce.Contracts 12 | .\obj 13 | .\bin\ 14 | v4.6.1 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/Commerce.Web.Test/DemoControllerTest.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Repositories; 2 | using Commerce.Model.Entities; 3 | using Commerce.Web.Controllers; 4 | using Moq; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using Xunit; 10 | 11 | namespace Commerce.Web.Test 12 | { 13 | public class DemoControllerTest 14 | { 15 | [Fact] 16 | public void When_Get_List_Baskets() 17 | { 18 | var bList = new Basket [] 19 | { 20 | new Basket {UserId ="user id 1",date =DateTime.Now }, 21 | new Basket {UserId ="user id 2",date =DateTime.Now }, 22 | new Basket {UserId ="user id 3",date =DateTime.Now }, 23 | new Basket {UserId ="user id 4",date =DateTime.Now }, 24 | new Basket {UserId ="user id 5",date =DateTime.Now } 25 | }; 26 | 27 | var mockBasket = new Mock>(); 28 | mockBasket.Setup(x => x.GetAll()).Returns(() => bList.AsQueryable()); 29 | var demoController = new DemoController(mockBasket.Object); 30 | 31 | Assert.Equal(demoController.GetBaskets().Count(), 5); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Commerce.Contracts/Repositories/IRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Commerce.Contracts.Repositories 7 | { 8 | public interface IRepositoryBase where TEntity : class 9 | { 10 | void Commit(); 11 | Task CommitAsync(); 12 | void Delete(object id); 13 | void Delete(TEntity entity); 14 | void Dispose(); 15 | IQueryable GetAll(); 16 | IQueryable GetAll(Func where = null); 17 | TEntity GetById(object id); 18 | TEntity GetFullObject(object id); 19 | IQueryable GetPaged(int top = 20, int skip = 0, Func orderBy = null, Func where = null); 20 | IQueryable GetPaged(int top = 20, int skip = 0); 21 | void Insert(TEntity entity); 22 | void Update(TEntity entity); 23 | void RunCommand(string query); 24 | Task RunCommandAsync(string query); 25 | void RunCommandWithParameter(string query, params object[] parameters); 26 | Task RunCommandWithParameterAsync(string query, CancellationToken cancellationToken = default(CancellationToken), params object[] parameters); 27 | } 28 | } -------------------------------------------------------------------------------- /test/Commerce.DAL.Test/Commerce.DAL.Test.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 077847dc-fcc6-4639-89db-5ef58726d18b 10 | Commerce.DAL.Test 11 | .\obj 12 | .\bin\ 13 | v4.6.1 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/Commerce.Web.Test/Commerce.Web.Test.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | fb73ee50-e5fe-4517-8ed6-375da2638ef5 10 | Commerce.Web.Test 11 | .\obj 12 | .\bin\ 13 | v4.6.1 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/jquery-validation-unobtrusive/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-validation-unobtrusive", 3 | "version": "3.2.6", 4 | "homepage": "https://github.com/aspnet/jquery-validation-unobtrusive", 5 | "description": "Add-on to jQuery Validation to enable unobtrusive validation options in data-* attributes.", 6 | "main": [ 7 | "jquery.validate.unobtrusive.js" 8 | ], 9 | "ignore": [ 10 | "**/.*", 11 | "*.json", 12 | "*.md", 13 | "*.txt", 14 | "gulpfile.js" 15 | ], 16 | "keywords": [ 17 | "jquery", 18 | "asp.net", 19 | "mvc", 20 | "validation", 21 | "unobtrusive" 22 | ], 23 | "authors": [ 24 | "Microsoft" 25 | ], 26 | "license": "http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm", 27 | "repository": { 28 | "type": "git", 29 | "url": "git://github.com/aspnet/jquery-validation-unobtrusive.git" 30 | }, 31 | "dependencies": { 32 | "jquery-validation": ">=1.8", 33 | "jquery": ">=1.8" 34 | }, 35 | "_release": "3.2.6", 36 | "_resolution": { 37 | "type": "version", 38 | "tag": "v3.2.6", 39 | "commit": "13386cd1b5947d8a5d23a12b531ce3960be1eba7" 40 | }, 41 | "_source": "git://github.com/aspnet/jquery-validation-unobtrusive.git", 42 | "_target": "3.2.6", 43 | "_originalSource": "jquery-validation-unobtrusive" 44 | } -------------------------------------------------------------------------------- /src/Commerce.Web/Commerce.Web.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 5a1a0a91-8eb4-4b27-a21a-572eb2fa2317 10 | Commerce.Web 11 | .\obj 12 | .\bin\ 13 | v4.6.1 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/ExternalLoginConfirmation.cshtml: -------------------------------------------------------------------------------- 1 | @model ExternalLoginConfirmationViewModel 2 | @{ 3 | ViewData["Title"] = "Register"; 4 | } 5 | 6 |

@ViewData["Title"].

7 |

Associate your @ViewData["LoginProvider"] account.

8 | 9 |
10 |

Association Form

11 |
12 |
13 | 14 |

15 | You've successfully authenticated with @ViewData["LoginProvider"]. 16 | Please enter an email address for this site below and click the Register button to finish 17 | logging in. 18 |

19 |
20 | 21 |
22 | 23 | 24 |
25 |
26 |
27 |
28 | 29 |
30 |
31 |
32 | 33 | @section Scripts { 34 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 35 | } 36 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/VerifyCode.cshtml: -------------------------------------------------------------------------------- 1 | @model VerifyCodeViewModel 2 | @{ 3 | ViewData["Title"] = "Verify"; 4 | } 5 | 6 |

@ViewData["Title"].

7 | 8 |
9 |
10 | 11 | 12 |

@ViewData["Status"]

13 |
14 |
15 | 16 |
17 | 18 | 19 |
20 |
21 |
22 |
23 |
24 | 25 | 26 |
27 |
28 |
29 |
30 |
31 | 32 |
33 |
34 |
35 | 36 | @section Scripts { 37 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 38 | } 39 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/Voucher.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class Voucher : IVoucher 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | 15 | [MaxLength(10)] 16 | public string VoucherCode { get; set; } 17 | 18 | [MaxLength(150)] 19 | public string VoucherDescription { get; set; } 20 | 21 | public int AppliesToProductId { get; set; }//this is so we can apply it to a specifc product 22 | 23 | public decimal Value { get; set; } 24 | 25 | public decimal MinSpend { get; set; } 26 | 27 | public bool multipleUse { get; set; } 28 | 29 | [MaxLength(255)] 30 | public string AssignedTo { get; set; } 31 | 32 | public int VoucherTypeId { get; set; } 33 | public virtual VoucherType VoucherType { get; set; } 34 | 35 | public virtual ICollection BasketVouchers { get; set; } 36 | public Voucher() 37 | { 38 | this.BasketVouchers = new HashSet(); 39 | } 40 | public virtual ICollection IBasketVouchers 41 | { 42 | get 43 | { 44 | return BasketVouchers.Select(s => (IBasketVoucher)s).ToList(); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/Product.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class Product : IProduct 11 | { 12 | [Key] 13 | public int Id { get; set; } 14 | 15 | public string Description { get; set; } 16 | 17 | [MaxLength(255)] 18 | public string ImageUrl { get; set; } 19 | 20 | public decimal Price { get; set; } 21 | public decimal CostPrice { get; set; } 22 | 23 | public int CategoryId { get; set; } 24 | public virtual Category Category { get; set; } 25 | 26 | public virtual ICollection OrderItems { get; set; } 27 | public virtual ICollection BasketItems { get; set; } 28 | 29 | public Product() 30 | { 31 | this.OrderItems = new HashSet(); 32 | this.BasketItems = new HashSet(); 33 | } 34 | 35 | public virtual ICollection IOrderItems 36 | { 37 | get 38 | { 39 | return OrderItems.Select(s => (IOrderItem)s).ToList(); 40 | } 41 | } 42 | 43 | public virtual ICollection IBasketItems 44 | { 45 | get 46 | { 47 | return BasketItems.Select(s => (IBasketItem)s).ToList(); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Manage/SetPassword.cshtml: -------------------------------------------------------------------------------- 1 | @model SetPasswordViewModel 2 | @{ 3 | ViewData["Title"] = "Set Password"; 4 | } 5 | 6 |

7 | You do not have a local username/password for this site. Add a local 8 | account so you can log in without an external login. 9 |

10 | 11 |
12 |

Set your password

13 |
14 |
15 |
16 | 17 |
18 | 19 | 20 |
21 |
22 |
23 | 24 |
25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 |
33 |
34 |
35 | 36 | @section Scripts { 37 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 38 | } 39 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/Register.cshtml: -------------------------------------------------------------------------------- 1 | @model RegisterViewModel 2 | @{ 3 | ViewData["Title"] = "Register"; 4 | } 5 | 6 |

@ViewData["Title"].

7 | 8 |
9 |

Create a new account.

10 |
11 |
12 |
13 | 14 |
15 | 16 | 17 |
18 |
19 |
20 | 21 |
22 | 23 | 24 |
25 |
26 |
27 | 28 |
29 | 30 | 31 |
32 |
33 |
34 |
35 | 36 |
37 |
38 |
39 | 40 | @section Scripts { 41 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 42 | } 43 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Manage/ChangePassword.cshtml: -------------------------------------------------------------------------------- 1 | @model ChangePasswordViewModel 2 | @{ 3 | ViewData["Title"] = "Change Password"; 4 | } 5 | 6 |

@ViewData["Title"].

7 | 8 |
9 |

Change Password Form

10 |
11 |
12 |
13 | 14 |
15 | 16 | 17 |
18 |
19 |
20 | 21 |
22 | 23 | 24 |
25 |
26 |
27 | 28 |
29 | 30 | 31 |
32 |
33 |
34 |
35 | 36 |
37 |
38 |
39 | 40 | @section Scripts { 41 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 42 | } 43 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/ResetPassword.cshtml: -------------------------------------------------------------------------------- 1 | @model ResetPasswordViewModel 2 | @{ 3 | ViewData["Title"] = "Reset password"; 4 | } 5 | 6 |

@ViewData["Title"].

7 | 8 |
9 |

Reset your password.

10 |
11 |
12 | 13 |
14 | 15 |
16 | 17 | 18 |
19 |
20 |
21 | 22 |
23 | 24 | 25 |
26 |
27 |
28 | 29 |
30 | 31 | 32 |
33 |
34 |
35 |
36 | 37 |
38 |
39 |
40 | 41 | @section Scripts { 42 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 43 | } 44 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/jquery/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright jQuery Foundation and other contributors, https://jquery.org/ 2 | 3 | This software consists of voluntary contributions made by many 4 | individuals. For exact contribution history, see the revision history 5 | available at https://github.com/jquery/jquery 6 | 7 | The following license applies to all parts of this software except as 8 | documented below: 9 | 10 | ==== 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining 13 | a copy of this software and associated documentation files (the 14 | "Software"), to deal in the Software without restriction, including 15 | without limitation the rights to use, copy, modify, merge, publish, 16 | distribute, sublicense, and/or sell copies of the Software, and to 17 | permit persons to whom the Software is furnished to do so, subject to 18 | the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be 21 | included in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | 31 | ==== 32 | 33 | All files located in the node_modules and external directories are 34 | externally maintained libraries used by this software which have their 35 | own licenses; we recommend you read them, as their terms may differ from 36 | the terms above. 37 | -------------------------------------------------------------------------------- /src/Commerce.Model/Entities/Basket.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace Commerce.Model.Entities 9 | { 10 | public class Basket : IBasket 11 | { 12 | [Key] 13 | public string Id { get; set; } 14 | public DateTime date { get; set; } 15 | 16 | public virtual ICollection BasketItems { get; set; } 17 | public virtual ICollection BasketVouchers { get; set; } 18 | 19 | 20 | public Basket() 21 | { 22 | Id = Guid.NewGuid().ToString(); 23 | this.BasketItems = new HashSet(); 24 | this.BasketVouchers = new HashSet(); 25 | } 26 | 27 | public virtual ICollection IBasketItems 28 | { 29 | get { return BasketItems.Select(s => (IBasketItem)s).ToList(); } 30 | } 31 | public virtual ICollection IBasketVouchers 32 | { 33 | get { return BasketVouchers.Select(i => (IBasketVoucher)i).ToList(); } 34 | } 35 | 36 | 37 | public string UserId { get; set; } 38 | public virtual User User { get; set; } 39 | 40 | 41 | public void AddBasketItem(IBasketItem item) 42 | { 43 | BasketItems.Add((BasketItem)item); 44 | } 45 | 46 | public void AddBasketVoucher(IBasketVoucher voucher) 47 | { 48 | BasketVouchers.Add((BasketVoucher)voucher); 49 | } 50 | 51 | public decimal BasketItemCount() 52 | { 53 | return BasketItems.Count(); 54 | } 55 | 56 | public decimal BasketTotal() 57 | { 58 | decimal? total = BasketItems.Select(i => (int)i.Quantity * i.Product.Price).Sum(); 59 | return total ?? decimal.Zero; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Commerce.Web/Areas/Admin/Views/Shared/Layouts/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @ViewData["Title"] | Admin 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | @Html.ApplicationInsightsJavaScript(TelemetryConfiguration) 20 | 21 | 22 | 23 |
24 | @await Html.PartialAsync("Layouts/Partials/_Header") 25 | 26 | @RenderBody() 27 | 28 | @await Html.PartialAsync("Layouts/Partials/_Footer") 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 41 | 45 | 46 | 47 | 48 | @RenderSection("scripts", required: false) 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Data/DataContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Commerce.Model.Entities; 6 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 7 | using Microsoft.EntityFrameworkCore; 8 | 9 | namespace Commerce.DAL.Data 10 | { 11 | public class DataContext : IdentityDbContext 12 | { 13 | /// 14 | /// You can either pass the Name of a connection string from web config or explicity declare one 15 | /// 16 | public DataContext(DbContextOptions options) : base(options) 17 | { 18 | 19 | } 20 | 21 | protected override void OnModelCreating(ModelBuilder builder) 22 | { 23 | base.OnModelCreating(builder); 24 | 25 | // ef identity tables renamed 26 | builder.Entity().ToTable("Users"); 27 | builder.Entity>().ToTable("UserClaims"); 28 | builder.Entity>().ToTable("UserRoles"); 29 | builder.Entity().ToTable("Roles"); 30 | builder.Entity>().ToTable("RoleClaims"); 31 | builder.Entity>().ToTable("UserLogins"); 32 | builder.Entity>().ToTable("UserTokens"); 33 | 34 | //new BasketMap().Map(builder); 35 | } 36 | 37 | /// 38 | /// All persistent entities must be declared 39 | /// 40 | public virtual DbSet Products { get; set; } 41 | public virtual DbSet Categories { get; set; } 42 | public virtual DbSet Orders { get; set; } 43 | public virtual DbSet OrderItems { get; set; } 44 | //public virtual DbSet Customers { get; set; } 45 | public virtual new DbSet Users { get; set; } 46 | public virtual DbSet Baskets { get; set; } 47 | public virtual DbSet BasketItems { get; set; } 48 | public virtual DbSet Vouchers { get; set; } 49 | public virtual DbSet BasketVouchers { get; set; } 50 | public virtual DbSet VoucherTypes { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Manage/ManageLogins.cshtml: -------------------------------------------------------------------------------- 1 | @model ManageLoginsViewModel 2 | @using Microsoft.AspNetCore.Http.Authentication 3 | @{ 4 | ViewData["Title"] = "Manage your external logins"; 5 | } 6 | 7 |

@ViewData["Title"].

8 | 9 |

@ViewData["StatusMessage"]

10 | @if (Model.CurrentLogins.Count > 0) 11 | { 12 |

Registered Logins

13 | 14 | 15 | @for (var index = 0; index < Model.CurrentLogins.Count; index++) 16 | { 17 | 18 | 19 | 35 | 36 | } 37 | 38 |
@Model.CurrentLogins[index].LoginProvider 20 | @if ((bool)ViewData["ShowRemoveButton"]) 21 | { 22 |
23 |
24 | 25 | 26 | 27 |
28 |
29 | } 30 | else 31 | { 32 | @:   33 | } 34 |
39 | } 40 | @if (Model.OtherLogins.Count > 0) 41 | { 42 |

Add another service to log in.

43 |
44 |
45 |
46 |

47 | @foreach (var provider in Model.OtherLogins) 48 | { 49 | 50 | } 51 |

52 |
53 |
54 | } 55 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Manage/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IndexViewModel 2 | @{ 3 | ViewData["Title"] = "Manage your account"; 4 | } 5 | 6 |

@ViewData["Title"].

7 |

@ViewData["StatusMessage"]

8 | 9 |
10 |

Change your account settings

11 |
12 |
13 |
Password:
14 |
15 | @if (Model.HasPassword) 16 | { 17 | Change 18 | } 19 | else 20 | { 21 | Create 22 | } 23 |
24 |
External Logins:
25 |
26 | 27 | @Model.Logins.Count Manage 28 |
29 |
Phone Number:
30 |
31 |

32 | Phone Numbers can used as a second factor of verification in two-factor authentication. 33 | See this article 34 | for details on setting up this ASP.NET application to support two-factor authentication using SMS. 35 |

36 | @*@(Model.PhoneNumber ?? "None") 37 | @if (Model.PhoneNumber != null) 38 | { 39 |
40 | Change 41 |
42 | [] 43 |
44 | } 45 | else 46 | { 47 | Add 48 | }*@ 49 |
50 | 51 |
Two-Factor Authentication:
52 |
53 |

54 | There are no two-factor authentication providers configured. See this article 55 | for setting up this application to support two-factor authentication. 56 |

57 | @*@if (Model.TwoFactor) 58 | { 59 |
60 | Enabled 61 |
62 | } 63 | else 64 | { 65 |
66 | Disabled 67 |
68 | }*@ 69 |
70 |
71 |
72 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewData["Title"] | Commerce 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | @Html.ApplicationInsightsJavaScript(TelemetryConfiguration) 19 | 20 | 21 | 42 |
43 | @RenderBody() 44 |
45 |
46 |

© 2017 - Commerce

47 |
48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 64 | 65 | 66 | 67 | @RenderSection("scripts", required: false) 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/Commerce.Web/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "userSecretsId": "aspnet-Commerce.Web-a9c816f2-8556-487d-852d-cd41e68af326", 3 | 4 | "dependencies": { 5 | "Microsoft.NETCore.App": { 6 | "version": "1.0.0", 7 | "type": "platform" 8 | }, 9 | "Microsoft.ApplicationInsights.AspNetCore": "1.0.0", 10 | "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", 11 | "Microsoft.AspNetCore.Diagnostics": "1.0.0", 12 | "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0", 13 | "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0", 14 | "Microsoft.AspNetCore.Mvc": "1.0.0", 15 | "Microsoft.AspNetCore.Razor.Tools": { 16 | "version": "1.0.0-preview2-final", 17 | "type": "build" 18 | }, 19 | "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 20 | "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 21 | "Microsoft.AspNetCore.StaticFiles": "1.0.0", 22 | "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", 23 | "Microsoft.EntityFrameworkCore.SqlServer.Design": { 24 | "version": "1.0.0", 25 | "type": "build" 26 | }, 27 | "Microsoft.EntityFrameworkCore.Tools": { 28 | "version": "1.0.0-preview2-final", 29 | "type": "build" 30 | }, 31 | "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 32 | "Microsoft.Extensions.Configuration.Json": "1.0.0", 33 | "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", 34 | "Microsoft.Extensions.Logging": "1.0.0", 35 | "Microsoft.Extensions.Logging.Console": "1.0.0", 36 | "Microsoft.Extensions.Logging.Debug": "1.0.0", 37 | "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", 38 | "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0", 39 | "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 40 | "version": "1.0.0-preview2-final", 41 | "type": "build" 42 | }, 43 | "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { 44 | "version": "1.0.0-preview2-final", 45 | "type": "build" 46 | }, 47 | "Commerce.Model": "1.0.0-*", 48 | "Commerce.DAL": "1.0.0-*", 49 | "Commerce.Contracts": "1.0.0-*" 50 | }, 51 | 52 | "tools": { 53 | "BundlerMinifier.Core": "2.0.238", 54 | "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", 55 | "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", 56 | "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", 57 | "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final", 58 | "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 59 | "version": "1.0.0-preview2-final", 60 | "imports": [ 61 | "portable-net45+win8" 62 | ] 63 | } 64 | }, 65 | 66 | "frameworks": { 67 | "netcoreapp1.0": { 68 | "imports": [ 69 | "dotnet5.6", 70 | "portable-net45+win8" 71 | ] 72 | } 73 | }, 74 | 75 | "buildOptions": { 76 | "emitEntryPoint": true, 77 | "preserveCompilationContext": true 78 | }, 79 | 80 | "runtimeOptions": { 81 | "configProperties": { 82 | "System.GC.Server": true 83 | } 84 | }, 85 | 86 | "publishOptions": { 87 | "include": [ 88 | "wwwroot", 89 | "Views", 90 | "Areas/**/Views", 91 | "appsettings.json", 92 | "web.config" 93 | ] 94 | }, 95 | 96 | "scripts": { 97 | "prepublish": [ "bower install", "dotnet bundle" ], 98 | "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Commerce.DAL/Repositories/RepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Commerce.Contracts.Repositories; 2 | using Commerce.DAL.Data; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.EntityFrameworkCore; 8 | using System.Threading; 9 | using System.Linq.Expressions; 10 | 11 | namespace Commerce.DAL.Repositories 12 | { 13 | public abstract class RepositoryBase : IRepositoryBase where TEntity : class 14 | { 15 | internal DataContext context; 16 | internal DbSet dbSet; 17 | 18 | public RepositoryBase(DataContext context) 19 | { 20 | this.context = context; 21 | this.dbSet = context.Set(); 22 | } 23 | public virtual void Commit() 24 | { 25 | context.SaveChanges(); 26 | } 27 | 28 | public virtual async Task CommitAsync() 29 | { 30 | await context.SaveChangesAsync(); 31 | } 32 | 33 | public virtual void Delete(TEntity entity) 34 | { 35 | if (context.Entry(entity).State == EntityState.Detached) 36 | dbSet.Attach(entity); 37 | 38 | dbSet.Remove(entity); 39 | } 40 | 41 | //public virtual void Delete(object id) 42 | //{ 43 | // TEntity entity = null;//dbSet.Find(id); 44 | // Delete(entity); 45 | //} 46 | public abstract void Delete(object id); 47 | 48 | public virtual void Dispose() 49 | { 50 | context.Dispose(); 51 | } 52 | 53 | public virtual IQueryable GetAll() 54 | { 55 | return dbSet; 56 | } 57 | 58 | public virtual IQueryable GetAll(Func where) 59 | { 60 | //need to override in order to implement specific filtering. 61 | return dbSet.Where(where).AsQueryable(); 62 | } 63 | 64 | //public virtual TEntity GetById(object id) 65 | //{ 66 | // return null;// dbSet.Find(id); 67 | //} 68 | public abstract TEntity GetById(object id); 69 | 70 | public virtual TEntity GetFullObject(object id) 71 | { 72 | return null; //need to override in order to implement specific filtering. 73 | 74 | } 75 | 76 | public virtual IQueryable GetPaged(int top = 20, int skip = 0, Func orderBy = null, Func where = null) 77 | { 78 | //need to override in order to implement specific filtering and ordering 79 | return dbSet.Skip(skip).Take(top).OrderBy(orderBy).Where(where).AsQueryable(); 80 | } 81 | 82 | public virtual IQueryable GetPaged(int top = 20, int skip = 0) 83 | { 84 | //need to override in order to implement specific filtering and ordering 85 | return dbSet.Skip(skip).Take(top); 86 | } 87 | 88 | public virtual void Insert(TEntity entity) 89 | { 90 | dbSet.Add(entity); 91 | } 92 | 93 | public virtual void Update(TEntity entity) 94 | { 95 | dbSet.Attach(entity); 96 | context.Entry(entity).State = EntityState.Modified; 97 | } 98 | 99 | public void RunCommand(string query) 100 | { 101 | context.Database.ExecuteSqlCommand(query); 102 | } 103 | 104 | public async Task RunCommandAsync(string query) 105 | { 106 | await context.Database.ExecuteSqlCommandAsync(query); 107 | } 108 | 109 | public void RunCommandWithParameter(string query, params object[] parameters) 110 | { 111 | context.Database.ExecuteSqlCommand(query, parameters); 112 | } 113 | 114 | public async Task RunCommandWithParameterAsync(string query, CancellationToken cancellationToken = default(CancellationToken), params object[] parameters) 115 | { 116 | await context.Database.ExecuteSqlCommandAsync(query, cancellationToken, parameters); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Account/Login.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Collections.Generic 2 | @using Microsoft.AspNetCore.Http 3 | @using Microsoft.AspNetCore.Http.Authentication 4 | @using Commerce.Model.Entities 5 | @model LoginViewModel 6 | @inject SignInManager SignInManager 7 | 8 | @{ 9 | ViewData["Title"] = "Log in"; 10 | } 11 | 12 |

@ViewData["Title"].

13 |
14 |
15 |
16 |
17 |

Use a local account to log in.

18 |
19 |
20 |
21 | 22 |
23 | 24 | 25 |
26 |
27 |
28 | 29 |
30 | 31 | 32 |
33 |
34 |
35 |
36 |
37 | 41 |
42 |
43 |
44 |
45 |
46 | 47 |
48 |
49 |

50 | Register as a new user? 51 |

52 |

53 | Forgot your password? 54 |

55 |
56 |
57 |
58 |
59 |
60 |

Use another service to log in.

61 |
62 | @{ 63 | var loginProviders = SignInManager.GetExternalAuthenticationSchemes().ToList(); 64 | if (loginProviders.Count == 0) 65 | { 66 |
67 |

68 | There are no external authentication services configured. See this article 69 | for details on setting up this ASP.NET application to support logging in via external services. 70 |

71 |
72 | } 73 | else 74 | { 75 |
76 |
77 |

78 | @foreach (var provider in loginProviders) 79 | { 80 | 81 | } 82 |

83 |
84 |
85 | } 86 | } 87 |
88 |
89 |
90 | 91 | @section Scripts { 92 | @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } 93 | } 94 | -------------------------------------------------------------------------------- /e-Commerce.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9D8C3BB1-AEDB-4757-8559-995D12A4E6D0}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E6485FFF-33D6-4AFF-84A3-906FB3241010}" 9 | ProjectSection(SolutionItems) = preProject 10 | global.json = global.json 11 | README.md = README.md 12 | EndProjectSection 13 | EndProject 14 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commerce.DAL", "src\Commerce.DAL\Commerce.DAL.xproj", "{A0CDB1A5-8427-4B12-87B2-A7AD61B75383}" 15 | EndProject 16 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commerce.Contracts", "src\Commerce.Contracts\Commerce.Contracts.xproj", "{7131B84E-FAAB-479A-BF50-0C2F1867DD25}" 17 | EndProject 18 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commerce.Model", "src\Commerce.Model\Commerce.Model.xproj", "{10D1B1D7-29C2-45DF-8066-4102D96780E5}" 19 | EndProject 20 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commerce.Web", "src\Commerce.Web\Commerce.Web.xproj", "{5A1A0A91-8EB4-4B27-A21A-572EB2FA2317}" 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{35440559-057B-449E-A972-0F0F43DB0CA9}" 23 | EndProject 24 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commerce.DAL.Test", "test\Commerce.DAL.Test\Commerce.DAL.Test.xproj", "{077847DC-FCC6-4639-89DB-5EF58726D18B}" 25 | EndProject 26 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commerce.Web.Test", "test\Commerce.Web.Test\Commerce.Web.Test.xproj", "{FB73EE50-E5FE-4517-8ED6-375DA2638EF5}" 27 | EndProject 28 | Global 29 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 30 | Debug|Any CPU = Debug|Any CPU 31 | Release|Any CPU = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 34 | {A0CDB1A5-8427-4B12-87B2-A7AD61B75383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {A0CDB1A5-8427-4B12-87B2-A7AD61B75383}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {A0CDB1A5-8427-4B12-87B2-A7AD61B75383}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {A0CDB1A5-8427-4B12-87B2-A7AD61B75383}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {7131B84E-FAAB-479A-BF50-0C2F1867DD25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {7131B84E-FAAB-479A-BF50-0C2F1867DD25}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {7131B84E-FAAB-479A-BF50-0C2F1867DD25}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {7131B84E-FAAB-479A-BF50-0C2F1867DD25}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {10D1B1D7-29C2-45DF-8066-4102D96780E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {10D1B1D7-29C2-45DF-8066-4102D96780E5}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {10D1B1D7-29C2-45DF-8066-4102D96780E5}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {10D1B1D7-29C2-45DF-8066-4102D96780E5}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {5A1A0A91-8EB4-4B27-A21A-572EB2FA2317}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {5A1A0A91-8EB4-4B27-A21A-572EB2FA2317}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {5A1A0A91-8EB4-4B27-A21A-572EB2FA2317}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {5A1A0A91-8EB4-4B27-A21A-572EB2FA2317}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {077847DC-FCC6-4639-89DB-5EF58726D18B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {077847DC-FCC6-4639-89DB-5EF58726D18B}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {077847DC-FCC6-4639-89DB-5EF58726D18B}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {077847DC-FCC6-4639-89DB-5EF58726D18B}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {FB73EE50-E5FE-4517-8ED6-375DA2638EF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {FB73EE50-E5FE-4517-8ED6-375DA2638EF5}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {FB73EE50-E5FE-4517-8ED6-375DA2638EF5}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {FB73EE50-E5FE-4517-8ED6-375DA2638EF5}.Release|Any CPU.Build.0 = Release|Any CPU 58 | EndGlobalSection 59 | GlobalSection(SolutionProperties) = preSolution 60 | HideSolutionNode = FALSE 61 | EndGlobalSection 62 | GlobalSection(NestedProjects) = preSolution 63 | {A0CDB1A5-8427-4B12-87B2-A7AD61B75383} = {9D8C3BB1-AEDB-4757-8559-995D12A4E6D0} 64 | {7131B84E-FAAB-479A-BF50-0C2F1867DD25} = {9D8C3BB1-AEDB-4757-8559-995D12A4E6D0} 65 | {10D1B1D7-29C2-45DF-8066-4102D96780E5} = {9D8C3BB1-AEDB-4757-8559-995D12A4E6D0} 66 | {5A1A0A91-8EB4-4B27-A21A-572EB2FA2317} = {9D8C3BB1-AEDB-4757-8559-995D12A4E6D0} 67 | {077847DC-FCC6-4639-89DB-5EF58726D18B} = {35440559-057B-449E-A972-0F0F43DB0CA9} 68 | {FB73EE50-E5FE-4517-8ED6-375DA2638EF5} = {35440559-057B-449E-A972-0F0F43DB0CA9} 69 | EndGlobalSection 70 | EndGlobal 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ -------------------------------------------------------------------------------- /src/Commerce.Web/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 8 | using Microsoft.EntityFrameworkCore; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Microsoft.Extensions.Logging; 12 | using Commerce.Web.Models; 13 | using Commerce.Web.Services; 14 | using Commerce.DAL.Data; 15 | using Commerce.Contracts.Repositories; 16 | using Commerce.DAL.Repositories; 17 | using Commerce.Model.Entities; 18 | using Commerce.DAL.Initialize; 19 | 20 | namespace Commerce.Web 21 | { 22 | public class Startup 23 | { 24 | public Startup(IHostingEnvironment env) 25 | { 26 | var builder = new ConfigurationBuilder() 27 | .SetBasePath(env.ContentRootPath) 28 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 29 | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); 30 | 31 | if (env.IsDevelopment()) 32 | { 33 | // For more details on using the user secret store see... 34 | builder.AddUserSecrets(); 35 | 36 | // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. 37 | builder.AddApplicationInsightsSettings(developerMode: true); 38 | } 39 | 40 | builder.AddEnvironmentVariables(); 41 | Configuration = builder.Build(); 42 | } 43 | 44 | public IConfigurationRoot Configuration { get; } 45 | 46 | // This method gets called by the runtime. Use this method to add services to the container. 47 | public void ConfigureServices(IServiceCollection services) 48 | { 49 | // Add framework services. 50 | services.AddApplicationInsightsTelemetry(Configuration); 51 | 52 | 53 | services.AddDbContext(options => 54 | options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), 55 | b=>b.MigrationsAssembly("Commerce.DAL"))); 56 | 57 | services.AddIdentity() 58 | .AddEntityFrameworkStores() 59 | .AddDefaultTokenProviders(); 60 | 61 | 62 | services.AddMvc(); 63 | 64 | // Add application services. 65 | services.AddTransient(); 66 | services.AddTransient(); 67 | 68 | //add application data access DI 69 | services.AddScoped, UserRepository>(); 70 | services.AddScoped, ProductRepository>(); 71 | 72 | services.AddTransient, BasketRepository>(); 73 | services.AddTransient, VoucherRepository>(); 74 | services.AddTransient, VoucherTypeRepository>(); 75 | 76 | services.AddSingleton, BasketVoucherRepository>(); 77 | services.AddSingleton, CategoryRepository>(); 78 | 79 | } 80 | 81 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 82 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 83 | { 84 | loggerFactory.AddConsole(Configuration.GetSection("Logging")); 85 | loggerFactory.AddDebug(); 86 | 87 | app.UseApplicationInsightsRequestTelemetry(); 88 | 89 | if (env.IsDevelopment()) 90 | { 91 | app.UseDeveloperExceptionPage(); 92 | app.UseDatabaseErrorPage(); 93 | app.UseBrowserLink(); 94 | } 95 | else 96 | { 97 | app.UseExceptionHandler("/Home/Error"); 98 | } 99 | 100 | app.UseApplicationInsightsExceptionTelemetry(); 101 | 102 | app.UseStaticFiles(); 103 | 104 | app.UseIdentity(); 105 | 106 | // Add external authentication middleware below. 107 | 108 | app.UseMvc(routes => 109 | { 110 | routes.MapRoute( 111 | name: "default", 112 | template: "{controller=Home}/{action=Index}/{id?}"); // for General routes 113 | 114 | routes.MapRoute( 115 | name: "areaRoute", 116 | template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); //for Areas routes 117 | }); 118 | 119 | //when first run database is created and added some data 120 | InitializeData.InitializeEIADatabaseAsync(app.ApplicationServices).Wait(); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | ** Unobtrusive validation support library for jQuery and jQuery Validate 3 | ** Copyright (C) Microsoft Corporation. All rights reserved. 4 | */ 5 | !function(a){function e(a,e,n){a.rules[e]=n,a.message&&(a.messages[e]=a.message)}function n(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function t(a){return a.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function r(a){return a.substr(0,a.lastIndexOf(".")+1)}function i(a,e){return 0===a.indexOf("*.")&&(a=a.replace("*.",e)),a}function o(e,n){var r=a(this).find("[data-valmsg-for='"+t(n[0].name)+"']"),i=r.attr("data-valmsg-replace"),o=i?a.parseJSON(i)!==!1:null;r.removeClass("field-validation-valid").addClass("field-validation-error"),e.data("unobtrusiveContainer",r),o?(r.empty(),e.removeClass("input-validation-error").appendTo(r)):e.hide()}function d(e,n){var t=a(this).find("[data-valmsg-summary=true]"),r=t.find("ul");r&&r.length&&n.errorList.length&&(r.empty(),t.addClass("validation-summary-errors").removeClass("validation-summary-valid"),a.each(n.errorList,function(){a("
  • ").html(this.message).appendTo(r)}))}function s(e){var n=e.data("unobtrusiveContainer");if(n){var t=n.attr("data-valmsg-replace"),r=t?a.parseJSON(t):null;n.addClass("field-validation-valid").removeClass("field-validation-error"),e.removeData("unobtrusiveContainer"),r&&n.empty()}}function l(e){var n=a(this),t="__jquery_unobtrusive_validation_form_reset";if(!n.data(t)){n.data(t,!0);try{n.data("validator").resetForm()}finally{n.removeData(t)}n.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors"),n.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}}function m(e){var n=a(e),t=n.data(v),r=a.proxy(l,e),i=p.unobtrusive.options||{},m=function(n,t){var r=i[n];r&&a.isFunction(r)&&r.apply(e,t)};return t||(t={options:{errorClass:i.errorClass||"input-validation-error",errorElement:i.errorElement||"span",errorPlacement:function(){o.apply(e,arguments),m("errorPlacement",arguments)},invalidHandler:function(){d.apply(e,arguments),m("invalidHandler",arguments)},messages:{},rules:{},success:function(){s.apply(e,arguments),m("success",arguments)}},attachValidation:function(){n.off("reset."+v,r).on("reset."+v,r).validate(this.options)},validate:function(){return n.validate(),n.valid()}},n.data(v,t)),t}var u,p=a.validator,v="unobtrusiveValidation";p.unobtrusive={adapters:[],parseElement:function(e,n){var t,r,i,o=a(e),d=o.parents("form")[0];d&&(t=m(d),t.options.rules[e.name]=r={},t.options.messages[e.name]=i={},a.each(this.adapters,function(){var n="data-val-"+this.name,t=o.attr(n),s={};void 0!==t&&(n+="-",a.each(this.params,function(){s[this]=o.attr(n+this)}),this.adapt({element:e,form:d,message:t,params:s,rules:r,messages:i}))}),a.extend(r,{__dummy__:!0}),n||t.attachValidation())},parse:function(e){var n=a(e),t=n.parents().addBack().filter("form").add(n.find("form")).has("[data-val=true]");n.find("[data-val=true]").each(function(){p.unobtrusive.parseElement(this,!0)}),t.each(function(){var a=m(this);a&&a.attachValidation()})}},u=p.unobtrusive.adapters,u.add=function(a,e,n){return n||(n=e,e=[]),this.push({name:a,params:e,adapt:n}),this},u.addBool=function(a,n){return this.add(a,function(t){e(t,n||a,!0)})},u.addMinMax=function(a,n,t,r,i,o){return this.add(a,[i||"min",o||"max"],function(a){var i=a.params.min,o=a.params.max;i&&o?e(a,r,[i,o]):i?e(a,n,i):o&&e(a,t,o)})},u.addSingleVal=function(a,n,t){return this.add(a,[n||"val"],function(r){e(r,t||a,r.params[n])})},p.addMethod("__dummy__",function(a,e,n){return!0}),p.addMethod("regex",function(a,e,n){var t;return this.optional(e)?!0:(t=new RegExp(n).exec(a),t&&0===t.index&&t[0].length===a.length)}),p.addMethod("nonalphamin",function(a,e,n){var t;return n&&(t=a.match(/\W/g),t=t&&t.length>=n),t}),p.methods.extension?(u.addSingleVal("accept","mimtype"),u.addSingleVal("extension","extension")):u.addSingleVal("extension","extension","accept"),u.addSingleVal("regex","pattern"),u.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"),u.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range"),u.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength"),u.add("equalto",["other"],function(n){var o=r(n.element.name),d=n.params.other,s=i(d,o),l=a(n.form).find(":input").filter("[name='"+t(s)+"']")[0];e(n,"equalTo",l)}),u.add("required",function(a){("INPUT"!==a.element.tagName.toUpperCase()||"CHECKBOX"!==a.element.type.toUpperCase())&&e(a,"required",!0)}),u.add("remote",["url","type","additionalfields"],function(o){var d={url:o.params.url,type:o.params.type||"GET",data:{}},s=r(o.element.name);a.each(n(o.params.additionalfields||o.element.name),function(e,n){var r=i(n,s);d.data[r]=function(){var e=a(o.form).find(":input").filter("[name='"+t(r)+"']");return e.is(":checkbox")?e.filter(":checked").val()||e.filter(":hidden").val()||"":e.is(":radio")?e.filter(":checked").val()||"":e.val()}}),e(o,"remote",d)}),u.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&e(a,"minlength",a.params.min),a.params.nonalphamin&&e(a,"nonalphamin",a.params.nonalphamin),a.params.regex&&e(a,"regex",a.params.regex)}),a(function(){p.unobtrusive.parse(document)})}(jQuery); -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["less/theme.less","less/mixins/vendor-prefixes.less","less/mixins/gradients.less","less/mixins/reset-filter.less"],"names":[],"mappings":";;;;AAmBA,YAAA,aAAA,UAAA,aAAA,aAAA,aAME,YAAA,EAAA,KAAA,EAAA,eC2CA,mBAAA,MAAA,EAAA,IAAA,EAAA,sBAAA,EAAA,IAAA,IAAA,iBACQ,WAAA,MAAA,EAAA,IAAA,EAAA,sBAAA,EAAA,IAAA,IAAA,iBDvCR,mBAAA,mBAAA,oBAAA,oBAAA,iBAAA,iBAAA,oBAAA,oBAAA,oBAAA,oBAAA,oBAAA,oBCsCA,mBAAA,MAAA,EAAA,IAAA,IAAA,iBACQ,WAAA,MAAA,EAAA,IAAA,IAAA,iBDlCR,qBAAA,sBAAA,sBAAA,uBAAA,mBAAA,oBAAA,sBAAA,uBAAA,sBAAA,uBAAA,sBAAA,uBAAA,+BAAA,gCAAA,6BAAA,gCAAA,gCAAA,gCCiCA,mBAAA,KACQ,WAAA,KDlDV,mBAAA,oBAAA,iBAAA,oBAAA,oBAAA,oBAuBI,YAAA,KAyCF,YAAA,YAEE,iBAAA,KAKJ,aErEI,YAAA,EAAA,IAAA,EAAA,KACA,iBAAA,iDACA,iBAAA,4CAAA,iBAAA,qEAEA,iBAAA,+CCnBF,OAAA,+GH4CA,OAAA,0DACA,kBAAA,SAuC2C,aAAA,QAA2B,aAAA,KArCtE,mBAAA,mBAEE,iBAAA,QACA,oBAAA,EAAA,MAGF,oBAAA,oBAEE,iBAAA,QACA,aAAA,QAMA,sBAAA,6BAAA,4BAAA,6BAAA,4BAAA,4BAAA,uBAAA,8BAAA,6BAAA,8BAAA,6BAAA,6BAAA,gCAAA,uCAAA,sCAAA,uCAAA,sCAAA,sCAME,iBAAA,QACA,iBAAA,KAgBN,aEtEI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDAEA,OAAA,+GCnBF,OAAA,0DH4CA,kBAAA,SACA,aAAA,QAEA,mBAAA,mBAEE,iBAAA,QACA,oBAAA,EAAA,MAGF,oBAAA,oBAEE,iBAAA,QACA,aAAA,QAMA,sBAAA,6BAAA,4BAAA,6BAAA,4BAAA,4BAAA,uBAAA,8BAAA,6BAAA,8BAAA,6BAAA,6BAAA,gCAAA,uCAAA,sCAAA,uCAAA,sCAAA,sCAME,iBAAA,QACA,iBAAA,KAiBN,aEvEI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDAEA,OAAA,+GCnBF,OAAA,0DH4CA,kBAAA,SACA,aAAA,QAEA,mBAAA,mBAEE,iBAAA,QACA,oBAAA,EAAA,MAGF,oBAAA,oBAEE,iBAAA,QACA,aAAA,QAMA,sBAAA,6BAAA,4BAAA,6BAAA,4BAAA,4BAAA,uBAAA,8BAAA,6BAAA,8BAAA,6BAAA,6BAAA,gCAAA,uCAAA,sCAAA,uCAAA,sCAAA,sCAME,iBAAA,QACA,iBAAA,KAkBN,UExEI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDAEA,OAAA,+GCnBF,OAAA,0DH4CA,kBAAA,SACA,aAAA,QAEA,gBAAA,gBAEE,iBAAA,QACA,oBAAA,EAAA,MAGF,iBAAA,iBAEE,iBAAA,QACA,aAAA,QAMA,mBAAA,0BAAA,yBAAA,0BAAA,yBAAA,yBAAA,oBAAA,2BAAA,0BAAA,2BAAA,0BAAA,0BAAA,6BAAA,oCAAA,mCAAA,oCAAA,mCAAA,mCAME,iBAAA,QACA,iBAAA,KAmBN,aEzEI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDAEA,OAAA,+GCnBF,OAAA,0DH4CA,kBAAA,SACA,aAAA,QAEA,mBAAA,mBAEE,iBAAA,QACA,oBAAA,EAAA,MAGF,oBAAA,oBAEE,iBAAA,QACA,aAAA,QAMA,sBAAA,6BAAA,4BAAA,6BAAA,4BAAA,4BAAA,uBAAA,8BAAA,6BAAA,8BAAA,6BAAA,6BAAA,gCAAA,uCAAA,sCAAA,uCAAA,sCAAA,sCAME,iBAAA,QACA,iBAAA,KAoBN,YE1EI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDAEA,OAAA,+GCnBF,OAAA,0DH4CA,kBAAA,SACA,aAAA,QAEA,kBAAA,kBAEE,iBAAA,QACA,oBAAA,EAAA,MAGF,mBAAA,mBAEE,iBAAA,QACA,aAAA,QAMA,qBAAA,4BAAA,2BAAA,4BAAA,2BAAA,2BAAA,sBAAA,6BAAA,4BAAA,6BAAA,4BAAA,4BAAA,+BAAA,sCAAA,qCAAA,sCAAA,qCAAA,qCAME,iBAAA,QACA,iBAAA,KA2BN,eAAA,WClCE,mBAAA,EAAA,IAAA,IAAA,iBACQ,WAAA,EAAA,IAAA,IAAA,iBD2CV,0BAAA,0BE3FI,iBAAA,QACA,iBAAA,oDACA,iBAAA,+CAAA,iBAAA,wEACA,iBAAA,kDACA,OAAA,+GF0FF,kBAAA,SAEF,yBAAA,+BAAA,+BEhGI,iBAAA,QACA,iBAAA,oDACA,iBAAA,+CAAA,iBAAA,wEACA,iBAAA,kDACA,OAAA,+GFgGF,kBAAA,SASF,gBE7GI,iBAAA,iDACA,iBAAA,4CACA,iBAAA,qEAAA,iBAAA,+CACA,OAAA,+GACA,OAAA,0DCnBF,kBAAA,SH+HA,cAAA,ICjEA,mBAAA,MAAA,EAAA,IAAA,EAAA,sBAAA,EAAA,IAAA,IAAA,iBACQ,WAAA,MAAA,EAAA,IAAA,EAAA,sBAAA,EAAA,IAAA,IAAA,iBD6DV,sCAAA,oCE7GI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SD2CF,mBAAA,MAAA,EAAA,IAAA,IAAA,iBACQ,WAAA,MAAA,EAAA,IAAA,IAAA,iBD0EV,cAAA,iBAEE,YAAA,EAAA,IAAA,EAAA,sBAIF,gBEhII,iBAAA,iDACA,iBAAA,4CACA,iBAAA,qEAAA,iBAAA,+CACA,OAAA,+GACA,OAAA,0DCnBF,kBAAA,SHkJA,cAAA,IAHF,sCAAA,oCEhII,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SD2CF,mBAAA,MAAA,EAAA,IAAA,IAAA,gBACQ,WAAA,MAAA,EAAA,IAAA,IAAA,gBDgFV,8BAAA,iCAYI,YAAA,EAAA,KAAA,EAAA,gBAKJ,qBAAA,kBAAA,mBAGE,cAAA,EAqBF,yBAfI,mDAAA,yDAAA,yDAGE,MAAA,KE7JF,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,UFqKJ,OACE,YAAA,EAAA,IAAA,EAAA,qBC3HA,mBAAA,MAAA,EAAA,IAAA,EAAA,sBAAA,EAAA,IAAA,IAAA,gBACQ,WAAA,MAAA,EAAA,IAAA,EAAA,sBAAA,EAAA,IAAA,IAAA,gBDsIV,eEtLI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF8KF,aAAA,QAKF,YEvLI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF8KF,aAAA,QAMF,eExLI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF8KF,aAAA,QAOF,cEzLI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF8KF,aAAA,QAeF,UEjMI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SFuMJ,cE3MI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SFwMJ,sBE5MI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SFyMJ,mBE7MI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF0MJ,sBE9MI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF2MJ,qBE/MI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF+MJ,sBElLI,iBAAA,yKACA,iBAAA,oKACA,iBAAA,iKFyLJ,YACE,cAAA,IC9KA,mBAAA,EAAA,IAAA,IAAA,iBACQ,WAAA,EAAA,IAAA,IAAA,iBDgLV,wBAAA,8BAAA,8BAGE,YAAA,EAAA,KAAA,EAAA,QEnOE,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SFiOF,aAAA,QALF,+BAAA,qCAAA,qCAQI,YAAA,KAUJ,OCnME,mBAAA,EAAA,IAAA,IAAA,gBACQ,WAAA,EAAA,IAAA,IAAA,gBD4MV,8BE5PI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SFyPJ,8BE7PI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF0PJ,8BE9PI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF2PJ,2BE/PI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF4PJ,8BEhQI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SF6PJ,6BEjQI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SFoQJ,MExQI,iBAAA,oDACA,iBAAA,+CACA,iBAAA,wEAAA,iBAAA,kDACA,OAAA,+GACA,kBAAA,SFsQF,aAAA,QC3NA,mBAAA,MAAA,EAAA,IAAA,IAAA,gBAAA,EAAA,IAAA,EAAA,qBACQ,WAAA,MAAA,EAAA,IAAA,IAAA,gBAAA,EAAA,IAAA,EAAA"} -------------------------------------------------------------------------------- /src/Commerce.DAL/Initialize/InitializeData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Identity; 6 | using Microsoft.EntityFrameworkCore; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 9 | using Commerce.DAL.Data; 10 | using Commerce.Model.Entities; 11 | 12 | namespace Commerce.DAL.Initialize 13 | { 14 | public static class InitializeData 15 | { 16 | public static async Task InitializeEIADatabaseAsync(IServiceProvider serviceProvider, bool createUsers = true) 17 | { 18 | using (var serviceScope = serviceProvider.GetRequiredService().CreateScope()) 19 | { 20 | var db = serviceScope.ServiceProvider.GetService(); 21 | 22 | // if there isn't database, to create database and return true 23 | if (await db.Database.EnsureCreatedAsync()) 24 | { 25 | await InsertData(serviceProvider); 26 | 27 | if (createUsers) 28 | { 29 | await CreateUser(serviceProvider); 30 | } 31 | 32 | } 33 | } 34 | } 35 | 36 | private static async Task InsertData(IServiceProvider serviceProvider) 37 | { 38 | await AddOrUpdateAsync(serviceProvider, r => r.Id, Roles.Select(role => role.Value)); 39 | } 40 | 41 | // TODO [EF] This may be replaced by a first class mechanism in EF 42 | private static async Task AddOrUpdateAsync( 43 | IServiceProvider serviceProvider, 44 | Func propertyToMatch, IEnumerable entities) 45 | where TEntity : class 46 | { 47 | // Query in a separate context so that we can attach existing entities as modified 48 | List existingData; 49 | using (var serviceScope = serviceProvider.GetRequiredService().CreateScope()) 50 | { 51 | var db = serviceScope.ServiceProvider.GetService(); 52 | existingData = db.Set().ToList(); 53 | } 54 | 55 | using (var serviceScope = serviceProvider.GetRequiredService().CreateScope()) 56 | { 57 | var db = serviceScope.ServiceProvider.GetService(); 58 | foreach (var item in entities) 59 | { 60 | db.Entry(item).State = existingData.Any(g => propertyToMatch(g).Equals(propertyToMatch(item))) 61 | ? EntityState.Modified 62 | : EntityState.Added; 63 | } 64 | 65 | await db.SaveChangesAsync(); 66 | } 67 | }//AddOrUpdateAsync 68 | 69 | //create users 70 | private static async Task CreateUser(IServiceProvider serviceProvider) 71 | { 72 | var userManager = serviceProvider.GetService>(); 73 | 74 | //Super Admin 75 | var user1 = new User 76 | { 77 | UserName = "superAdminTest", 78 | Email = "s@s.com" 79 | }; 80 | await userManager.CreateAsync(user1, "Passw0rd!"); 81 | await userManager.AddToRoleAsync(user1, "SuperAdmin"); 82 | 83 | //admin 84 | var user2 = new User 85 | { 86 | UserName = "adminTest", 87 | Email = "a@a.com" 88 | }; 89 | await userManager.CreateAsync(user2, "Passw0rd!"); 90 | await userManager.AddToRoleAsync(user2, "Admin"); 91 | 92 | // Development 93 | var user3 = new User 94 | { 95 | UserName = "developmentTest", 96 | Email = "d@d.com" 97 | }; 98 | await userManager.CreateAsync(user3, "Passw0rd!"); 99 | await userManager.AddToRoleAsync(user3, "Development"); 100 | 101 | //Customer 102 | var user4 = new User 103 | { 104 | UserName = "customerTest", 105 | Email = "c@c.com" 106 | }; 107 | await userManager.CreateAsync(user4, "Passw0rd!"); 108 | await userManager.AddToRoleAsync(user4, "Customer"); 109 | } 110 | 111 | //user roles list 112 | private static Dictionary roles; 113 | private static Dictionary Roles 114 | { 115 | get 116 | { 117 | if (roles == null) 118 | { 119 | var rolesList = new IdentityRole[] 120 | { 121 | new IdentityRole { Name = "Development" , NormalizedName="DEVELOPMENT" }, 122 | new IdentityRole { Name = "SuperAdmin" , NormalizedName="SUPERADMIN" }, 123 | new IdentityRole { Name = "Admin" , NormalizedName="ADMIN" }, 124 | new IdentityRole { Name = "Customer" , NormalizedName="CUSTOMER" } 125 | }; 126 | 127 | roles = new Dictionary(); 128 | 129 | foreach (IdentityRole role in rolesList) 130 | { 131 | roles.Add(role.Name, role); 132 | } 133 | } 134 | return roles; 135 | } 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /test/Commerce.Web.Test/ManageControllerTest.cs: -------------------------------------------------------------------------------- 1 | using Commerce.DAL.Data; 2 | using Commerce.Model.Entities; 3 | using Commerce.Web.Controllers; 4 | using Commerce.Web.Models.ManageViewModels; 5 | using Commerce.Web.Services; 6 | using Microsoft.AspNetCore.Http; 7 | using Microsoft.AspNetCore.Http.Features.Authentication; 8 | using Microsoft.AspNetCore.Identity; 9 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 10 | using Microsoft.AspNetCore.Mvc; 11 | using Microsoft.EntityFrameworkCore; 12 | using Microsoft.Extensions.DependencyInjection; 13 | using Microsoft.Extensions.Logging; 14 | using System; 15 | using System.Collections.Generic; 16 | using System.Linq; 17 | using System.Security.Claims; 18 | using System.Threading.Tasks; 19 | using Xunit; 20 | 21 | namespace Commerce.Web.Test 22 | { 23 | public class ManageControllerTest 24 | { 25 | private readonly IServiceProvider _serviceProvider; 26 | 27 | public ManageControllerTest() 28 | { 29 | var efServiceProvider = new ServiceCollection() 30 | .AddEntityFrameworkInMemoryDatabase() 31 | .BuildServiceProvider(); 32 | 33 | var services = new ServiceCollection(); 34 | services.AddOptions(); 35 | services.AddDbContext(b => b.UseInMemoryDatabase() 36 | .UseInternalServiceProvider(efServiceProvider)); 37 | 38 | services.AddIdentity() 39 | .AddEntityFrameworkStores(); 40 | 41 | services.AddTransient(); 42 | services.AddTransient(); 43 | 44 | services.AddLogging(); 45 | services.AddOptions(); 46 | 47 | // IHttpContextAccessor is required for SignInManager, and UserManager 48 | var context = new DefaultHttpContext(); 49 | context.Features.Set( 50 | new HttpAuthenticationFeature() 51 | { 52 | Handler = new TestAuthHandler() 53 | }); 54 | 55 | services.AddSingleton( 56 | new HttpContextAccessor() 57 | { 58 | HttpContext = context, 59 | }); 60 | 61 | _serviceProvider = services.BuildServiceProvider(); 62 | } 63 | 64 | [Fact] 65 | public async Task Index_ReturnsViewBagMessagesExpected() 66 | { 67 | // Arrange 68 | var userId = "TestUserA"; 69 | var phone = "abcdefg"; 70 | var claims = new List { new Claim(ClaimTypes.NameIdentifier, userId) }; 71 | 72 | var userManager = _serviceProvider.GetRequiredService>(); 73 | var userManagerResult = await userManager.CreateAsync( 74 | new User { Id = userId, UserName = "Test", TwoFactorEnabled = true, PhoneNumber = phone }, 75 | "Pass@word1"); 76 | Assert.True(userManagerResult.Succeeded); 77 | 78 | var signInManager = _serviceProvider.GetRequiredService>(); 79 | 80 | var httpContext = _serviceProvider.GetRequiredService().HttpContext; 81 | httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(claims)); 82 | 83 | var emailSender = _serviceProvider.GetRequiredService(); 84 | var smsSender = _serviceProvider.GetRequiredService(); 85 | var loggerFactory = _serviceProvider.GetRequiredService();//.CreateLogger() 86 | 87 | var controller = new ManageController(userManager, signInManager,emailSender,smsSender,loggerFactory); 88 | controller.ControllerContext.HttpContext = httpContext; 89 | 90 | // Act 91 | var result = await controller.Index(); 92 | 93 | // Assert 94 | var viewResult = Assert.IsType(result); 95 | Assert.Null(viewResult.ViewName); 96 | 97 | Assert.Empty(controller.ViewBag.StatusMessage); 98 | 99 | Assert.NotNull(viewResult.ViewData); 100 | var model = Assert.IsType(viewResult.ViewData.Model); 101 | Assert.True(model.TwoFactor); 102 | Assert.Equal(phone, model.PhoneNumber); 103 | Assert.True(model.HasPassword); 104 | } 105 | 106 | private class TestAuthHandler : IAuthenticationHandler 107 | { 108 | public void Authenticate(AuthenticateContext context) 109 | { 110 | context.NotAuthenticated(); 111 | } 112 | 113 | public Task AuthenticateAsync(AuthenticateContext context) 114 | { 115 | context.NotAuthenticated(); 116 | return Task.FromResult(0); 117 | } 118 | 119 | public Task ChallengeAsync(ChallengeContext context) 120 | { 121 | throw new NotImplementedException(); 122 | } 123 | 124 | public void GetDescriptions(DescribeSchemesContext context) 125 | { 126 | throw new NotImplementedException(); 127 | } 128 | 129 | public Task SignInAsync(SignInContext context) 130 | { 131 | throw new NotImplementedException(); 132 | } 133 | 134 | public Task SignOutAsync(SignOutContext context) 135 | { 136 | throw new NotImplementedException(); 137 | } 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/Commerce.Web/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 | 67 | 68 | 110 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/images/banner2.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/images/banner1.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/images/banner3.svg: -------------------------------------------------------------------------------- 1 | banner3b -------------------------------------------------------------------------------- /src/Commerce.Web/wwwroot/images/banner4.svg: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------