Repository: lizhi5753186/OnlineStore
Branch: master
Commit: e5aa45a51d0f
Files: 547
Total size: 38.7 MB
Directory structure:
gitextract_wa3viklp/
├── .gitattributes
├── .gitignore
├── .nuget/
│ ├── NuGet.Config
│ └── NuGet.targets
├── OnlineStore.Application/
│ ├── AddressResolver.cs
│ ├── App_Data/
│ │ ├── OnlineStore.mdf
│ │ └── OnlineStore_log.ldf
│ ├── ApplicationService.cs
│ ├── Global.asax
│ ├── Global.asax.cs
│ ├── InversedAddressResolver.cs
│ ├── Logs/
│ │ └── onlinestore.txt
│ ├── OnlineStore.Application.csproj
│ ├── OrderService.svc
│ ├── OrderService.svc.cs
│ ├── ProductService.svc
│ ├── ProductService.svc.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── ServiceImplementations/
│ │ ├── OrderServiceImp.cs
│ │ ├── ProductServiceImp.cs
│ │ └── UserServiceImp.cs
│ ├── UserService.svc
│ ├── UserService.svc.cs
│ ├── Web.Debug.config
│ ├── Web.Release.config
│ ├── Web.config
│ └── packages.config
├── OnlineStore.Domain/
│ ├── DomainException.cs
│ ├── Events/
│ │ ├── DomainEvent.cs
│ │ ├── EventHandlers/
│ │ │ ├── OrderConfirmedEventHandler.cs
│ │ │ └── OrderDispatchedEventHandler.cs
│ │ ├── IDomainEvent.cs
│ │ ├── IDomainEventHandler.cs
│ │ ├── OrderConfirmedEvent.cs
│ │ └── OrderDispatchedEvent.cs
│ ├── IAggregateRoot.cs
│ ├── IEntity.cs
│ ├── Model/
│ │ ├── Address.cs
│ │ ├── AggregateRoot.cs
│ │ ├── Category.cs
│ │ ├── Order.cs
│ │ ├── OrderItem.cs
│ │ ├── OrderStatus.cs
│ │ ├── Product.cs
│ │ ├── ProductCategorization.cs
│ │ ├── Role.cs
│ │ ├── ShoppingCart.cs
│ │ ├── ShoppingCartItem.cs
│ │ ├── User.cs
│ │ └── UserRole.cs
│ ├── OnlineStore.Domain.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── Repositories/
│ │ ├── ICategoryRepository.cs
│ │ ├── IOrderRepository.cs
│ │ ├── IProductCategorizationRepository.cs
│ │ ├── IProductRepository.cs
│ │ ├── IRepository.cs
│ │ ├── IRepositoryContext.cs
│ │ ├── IRoleRepository.cs
│ │ ├── IShoppingCartItemRepository.cs
│ │ ├── IShoppingCartRepository.cs
│ │ ├── IUserRepository.cs
│ │ ├── IUserRoleRepository.cs
│ │ └── SortOrder.cs
│ ├── Services/
│ │ ├── DomainService.cs
│ │ └── IDomainService.cs
│ ├── Specifications/
│ │ ├── AnySpecification.cs
│ │ ├── ExpressionSpecification.cs
│ │ ├── ISpecification.cs
│ │ ├── ParameterReplacer.cs
│ │ ├── SpecExprExtensions.cs
│ │ └── Specification.cs
│ └── app.config
├── OnlineStore.Events/
│ ├── Bus/
│ │ ├── EventBus.cs
│ │ ├── IBus.cs
│ │ ├── IEventBus.cs
│ │ ├── MsmqBusOptions.cs
│ │ └── MsmqEventBus.cs
│ ├── EventAggregator.cs
│ ├── HandlesAsynchronouslyAttribute.cs
│ ├── IEvent.cs
│ ├── IEventAggregator.cs
│ ├── IEventHandler.cs
│ ├── OnlineStore.Events.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── app.config
├── OnlineStore.Events.Handlers/
│ ├── OnlineStore.Events.Handlers.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── SendEmailHandler.cs
│ └── app.config
├── OnlineStore.Infrastructure/
│ ├── Caching/
│ │ ├── AppfabricCacheProvider.cs
│ │ ├── CacheAttribute.cs
│ │ ├── CachingMethod.cs
│ │ ├── EntLibCacheProvider.cs
│ │ └── ICacheProvider.cs
│ ├── DisposableObject.cs
│ ├── IUnitOfWork.cs
│ ├── InterceptionBehaviors/
│ │ ├── CachingBehavior.cs
│ │ └── ExceptionLoggingBehavior.cs
│ ├── OnlineStore.Infrastructure.csproj
│ ├── PagedResult.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── ServiceLocator.cs
│ ├── Utils.cs
│ ├── app.config
│ └── packages.config
├── OnlineStore.ModelDTO/
│ ├── OnlineStore.ModelDTO.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── Service References/
│ │ ├── OrderService/
│ │ │ ├── OnlineStore.ModelDTO.OrderService.ShoppingCart.datasource
│ │ │ ├── OrderService.disco
│ │ │ ├── OrderService.wsdl
│ │ │ ├── OrderService.xsd
│ │ │ ├── OrderService1.xsd
│ │ │ ├── OrderService2.xsd
│ │ │ ├── Reference.cs
│ │ │ ├── Reference.svcmap
│ │ │ ├── configuration.svcinfo
│ │ │ └── configuration91.svcinfo
│ │ └── ProductService/
│ │ ├── OnlineStore.ModelDTO.ProductService.Category.datasource
│ │ ├── OnlineStore.ModelDTO.ProductService.Product.datasource
│ │ ├── ProductService.disco
│ │ ├── ProductService.wsdl
│ │ ├── ProductService.xsd
│ │ ├── ProductService1.wsdl
│ │ ├── ProductService1.xsd
│ │ ├── ProductService2.xsd
│ │ ├── Reference.cs
│ │ ├── Reference.svcmap
│ │ ├── configuration.svcinfo
│ │ └── configuration91.svcinfo
│ └── app.config
├── OnlineStore.Repositories/
│ ├── App.config
│ ├── EntityFramework/
│ │ ├── CategoryRepository.cs
│ │ ├── EntityFrameworkRepository.cs
│ │ ├── EntityFrameworkRepositoryContext.cs
│ │ ├── IEntityFrameworkRepositoryContext.cs
│ │ ├── ModelConfigurations/
│ │ │ ├── CategoryTypeConfiguration.cs
│ │ │ ├── OrderItemTypeConfiguration.cs
│ │ │ ├── OrderTypeConfiguration.cs
│ │ │ ├── ProductCategorizationTypeConfiguration.cs
│ │ │ ├── ProductTypeConfiguration.cs
│ │ │ ├── RoleTypeConfiguration.cs
│ │ │ ├── ShoppingCartItemTypeConfiguration.cs
│ │ │ ├── ShoppingCartTypeConfiguration.cs
│ │ │ ├── UserRoleTypeConfiguration.cs
│ │ │ └── UserTypeConfiguration.cs
│ │ ├── OnlineStoreDbContext.cs
│ │ ├── OnlineStoreDbContextInitailizer.cs
│ │ ├── OrderRepository.cs
│ │ ├── ProductCategorizationRepository.cs
│ │ ├── ProductRepository.cs
│ │ ├── RoleRepository.cs
│ │ ├── ShoppingCartItemRepository.cs
│ │ ├── ShoppingCartRepository.cs
│ │ ├── SortByExtension.cs
│ │ ├── UserRepository.cs
│ │ └── UserRoleRepository.cs
│ ├── OnlineStore.Repositories.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── OnlineStore.ServiceContract/
│ ├── IOrderService.cs
│ ├── IProductService.cs
│ ├── IUserService.cs
│ ├── ModelDTOs/
│ │ ├── AddressDto.cs
│ │ ├── CategoryDto.cs
│ │ ├── FaultData.cs
│ │ ├── OrderDto.cs
│ │ ├── OrderItemDto.cs
│ │ ├── OrderStatusDto.cs
│ │ ├── Pagination.cs
│ │ ├── ProductCategorizationDto.cs
│ │ ├── ProductDto.cs
│ │ ├── ProductDtoWithPagination.cs
│ │ ├── RoleDto.cs
│ │ ├── ShoppingCartDto.cs
│ │ ├── ShoppingCartItemDto.cs
│ │ └── UserDto.cs
│ ├── OnlineStore.ServiceContracts.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── app.config
├── OnlineStore.Web/
│ ├── App_Code/
│ │ ├── HtmlExtension.cs
│ │ ├── PermissionKeys.cs
│ │ └── UrlHelperExtension.cs
│ ├── App_Start/
│ │ ├── AuthConfig.cs
│ │ ├── BundleConfig.cs
│ │ ├── FilterConfig.cs
│ │ ├── RouteConfig.cs
│ │ └── WebApiConfig.cs
│ ├── Content/
│ │ ├── Site.css
│ │ ├── themes/
│ │ │ └── base/
│ │ │ ├── jquery-ui.css
│ │ │ ├── jquery.ui.accordion.css
│ │ │ ├── jquery.ui.all.css
│ │ │ ├── jquery.ui.autocomplete.css
│ │ │ ├── jquery.ui.base.css
│ │ │ ├── jquery.ui.button.css
│ │ │ ├── jquery.ui.core.css
│ │ │ ├── jquery.ui.datepicker.css
│ │ │ ├── jquery.ui.dialog.css
│ │ │ ├── jquery.ui.progressbar.css
│ │ │ ├── jquery.ui.resizable.css
│ │ │ ├── jquery.ui.selectable.css
│ │ │ ├── jquery.ui.slider.css
│ │ │ ├── jquery.ui.tabs.css
│ │ │ └── jquery.ui.theme.css
│ │ ├── uploadify.css
│ │ └── uploadify.swf
│ ├── Controllers/
│ │ ├── AccountController.cs
│ │ ├── AdminController.cs
│ │ ├── ControllerBase.cs
│ │ ├── HomeController.cs
│ │ └── LayoutController.cs
│ ├── Global.asax
│ ├── Global.asax.cs
│ ├── Membership/
│ │ ├── OnlineStoreMembershipProvider.cs
│ │ └── OnlineStoreMembershipUser.cs
│ ├── MvcSiteMap.cs
│ ├── OnlineStore.Web.csproj
│ ├── OnlineStore.Web.csproj.DotSettings
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── Scripts/
│ │ ├── _references.js
│ │ ├── hoverIntent.js
│ │ ├── jquery-1.7.1.intellisense.js
│ │ ├── jquery-1.7.1.js
│ │ ├── jquery-ui-1.8.20.js
│ │ ├── jquery.unobtrusive-ajax.js
│ │ ├── jquery.uploadify.js
│ │ ├── jquery.validate-vsdoc.js
│ │ ├── jquery.validate.js
│ │ ├── jquery.validate.unobtrusive.js
│ │ ├── knockout-2.1.0.debug.js
│ │ ├── knockout-2.1.0.js
│ │ ├── modernizr-2.5.3.js
│ │ ├── superfish.js
│ │ └── supersubs.js
│ ├── Service References/
│ │ ├── OnlineStoreDto.Partial.cs
│ │ ├── OrderService/
│ │ │ ├── OnlineStore.Web.OrderService.OrderDto.datasource
│ │ │ ├── OnlineStore.Web.OrderService.ShoppingCartDto.datasource
│ │ │ ├── OrderService.disco
│ │ │ ├── OrderService.wsdl
│ │ │ ├── OrderService.xsd
│ │ │ ├── OrderService1.xsd
│ │ │ ├── OrderService2.xsd
│ │ │ ├── Reference.cs
│ │ │ ├── Reference.svcmap
│ │ │ ├── configuration.svcinfo
│ │ │ └── configuration91.svcinfo
│ │ ├── ProductService/
│ │ │ ├── OnlineStore.Web.ProductService.CategoryDto.datasource
│ │ │ ├── OnlineStore.Web.ProductService.ProductCategorizationDto.datasource
│ │ │ ├── OnlineStore.Web.ProductService.ProductDto.datasource
│ │ │ ├── OnlineStore.Web.ProductService.ProductDtoWithPagination.datasource
│ │ │ ├── ProductService.disco
│ │ │ ├── ProductService.wsdl
│ │ │ ├── ProductService.xsd
│ │ │ ├── ProductService1.wsdl
│ │ │ ├── ProductService1.xsd
│ │ │ ├── ProductService2.xsd
│ │ │ ├── ProductService3.xsd
│ │ │ ├── Reference.cs
│ │ │ ├── Reference.svcmap
│ │ │ ├── configuration.svcinfo
│ │ │ └── configuration91.svcinfo
│ │ └── UserService/
│ │ ├── OnlineStore.Web.UserService.OrderDto.datasource
│ │ ├── OnlineStore.Web.UserService.RoleDto.datasource
│ │ ├── OnlineStore.Web.UserService.UserDto.datasource
│ │ ├── Reference.cs
│ │ ├── Reference.svcmap
│ │ ├── UserService.disco
│ │ ├── UserService.wsdl
│ │ ├── UserService.xsd
│ │ ├── UserService1.wsdl
│ │ ├── UserService1.xsd
│ │ ├── UserService2.xsd
│ │ ├── UserService3.xsd
│ │ ├── configuration.svcinfo
│ │ └── configuration91.svcinfo
│ ├── SiteMap.xml
│ ├── ViewModels/
│ │ ├── LoginViewModel.cs
│ │ └── UserAccountModel.cs
│ ├── Views/
│ │ ├── Account/
│ │ │ ├── Login.cshtml
│ │ │ ├── Manage.cshtml
│ │ │ └── Register.cshtml
│ │ ├── Admin/
│ │ │ ├── AddCategory.cshtml
│ │ │ ├── AddProduct.cshtml
│ │ │ ├── AddRole.cshtml
│ │ │ ├── AddUserAccount.cshtml
│ │ │ ├── Administration.cshtml
│ │ │ ├── Categories.cshtml
│ │ │ ├── EditCategory.cshtml
│ │ │ ├── EditProduct.cshtml
│ │ │ ├── EditRole.cshtml
│ │ │ ├── EditUserAccount.cshtml
│ │ │ ├── Order.cshtml
│ │ │ ├── Orders.cshtml
│ │ │ ├── Products.cshtml
│ │ │ ├── Roles.cshtml
│ │ │ └── UserAccounts.cshtml
│ │ ├── Home/
│ │ │ ├── About.cshtml
│ │ │ ├── Category.cshtml
│ │ │ ├── Checkout.cshtml
│ │ │ ├── Contact.cshtml
│ │ │ ├── Index.cshtml
│ │ │ ├── Order.cshtml
│ │ │ ├── Orders.cshtml
│ │ │ ├── ProductDetail.cshtml
│ │ │ ├── ShoppingCart.cshtml
│ │ │ └── SuccessPage.cshtml
│ │ ├── Shared/
│ │ │ ├── CategoriesPartial.cshtml
│ │ │ ├── Error.cshtml
│ │ │ ├── NewProductsPartial.cshtml
│ │ │ ├── ProductsPartial.cshtml
│ │ │ ├── _Layout.cshtml
│ │ │ └── _LoginPartial.cshtml
│ │ ├── Web.config
│ │ └── _ViewStart.cshtml
│ ├── Web.Debug.config
│ ├── Web.Release.config
│ ├── Web.config
│ └── packages.config
├── OnlineStore.sln
├── README.md
├── Scripts/
│ ├── dbo.Categories.data.sql
│ ├── dbo.ProductCategorizations.data.sql
│ ├── dbo.Products.data.sql
│ ├── dbo.Roles.sql
│ ├── dbo.UserRoles.data.sql
│ └── dbo.Users.data.sql
└── packages/
├── Antlr.3.4.1.9004/
│ └── Antlr.3.4.1.9004.nupkg
├── Antlr.3.5.0.2/
│ └── Antlr.3.5.0.2.nupkg
├── AutoMapper.3.3.1/
│ ├── AutoMapper.3.3.1.nupkg
│ ├── lib/
│ │ ├── MonoAndroid/
│ │ │ └── AutoMapper.xml
│ │ ├── MonoTouch/
│ │ │ └── AutoMapper.xml
│ │ ├── net40/
│ │ │ └── AutoMapper.xml
│ │ ├── portable-windows8+net40+wp8+sl5+MonoAndroid+MonoTouch/
│ │ │ └── AutoMapper.xml
│ │ ├── portable-windows8+net40+wp8+wpa81+sl5+MonoAndroid+MonoTouch/
│ │ │ └── AutoMapper.xml
│ │ ├── sl5/
│ │ │ └── AutoMapper.xml
│ │ ├── windows8/
│ │ │ └── AutoMapper.xml
│ │ ├── wp8/
│ │ │ └── AutoMapper.xml
│ │ └── wpa81/
│ │ └── AutoMapper.xml
│ └── tools/
│ ├── AutoMapper.targets
│ ├── MonoAndroid/
│ │ ├── Install.ps1
│ │ └── uninstall.ps1
│ ├── MonoTouch/
│ │ ├── Install.ps1
│ │ └── uninstall.ps1
│ ├── net40/
│ │ ├── Install.ps1
│ │ └── uninstall.ps1
│ ├── sl5/
│ │ ├── Install.ps1
│ │ └── uninstall.ps1
│ ├── windows8/
│ │ ├── Install.ps1
│ │ └── uninstall.ps1
│ ├── wp8/
│ │ ├── Install.ps1
│ │ └── uninstall.ps1
│ └── wpa81/
│ ├── Install.ps1
│ └── uninstall.ps1
├── CommonServiceLocator.1.3/
│ ├── CommonServiceLocator.1.3.nupkg
│ └── lib/
│ └── portable-net4+sl5+netcore45+wpa81+wp8/
│ └── Microsoft.Practices.ServiceLocation.XML
├── DotNetOpenAuth.AspNet.4.0.3.12153/
│ ├── DotNetOpenAuth.AspNet.4.0.3.12153.nupkg
│ └── lib/
│ └── net40-full/
│ └── DotNetOpenAuth.AspNet.xml
├── DotNetOpenAuth.AspNet.4.3.0.13117/
│ ├── DotNetOpenAuth.AspNet.4.3.0.13117.nupkg
│ └── lib/
│ ├── net40-full/
│ │ └── DotNetOpenAuth.AspNet.xml
│ └── net45-full/
│ └── DotNetOpenAuth.AspNet.xml
├── DotNetOpenAuth.Core.4.0.3.12153/
│ ├── DotNetOpenAuth.Core.4.0.3.12153.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.Core.xml
│ └── net40-full/
│ └── DotNetOpenAuth.Core.xml
├── DotNetOpenAuth.Core.4.3.0.13117/
│ ├── DotNetOpenAuth.Core.4.3.0.13117.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.Core.xml
│ ├── net40-full/
│ │ └── DotNetOpenAuth.Core.xml
│ └── net45-full/
│ └── DotNetOpenAuth.Core.xml
├── DotNetOpenAuth.OAuth.Consumer.4.0.3.12153/
│ ├── DotNetOpenAuth.OAuth.Consumer.4.0.3.12153.nupkg
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.OAuth.Consumer.xml
│ └── net40-full/
│ └── DotNetOpenAuth.OAuth.Consumer.xml
├── DotNetOpenAuth.OAuth.Consumer.4.3.0.13117/
│ ├── DotNetOpenAuth.OAuth.Consumer.4.3.0.13117.nupkg
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.OAuth.Consumer.xml
│ ├── net40-full/
│ │ └── DotNetOpenAuth.OAuth.Consumer.xml
│ └── net45-full/
│ └── DotNetOpenAuth.OAuth.Consumer.xml
├── DotNetOpenAuth.OAuth.Core.4.0.3.12153/
│ ├── DotNetOpenAuth.OAuth.Core.4.0.3.12153.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.OAuth.xml
│ └── net40-full/
│ └── DotNetOpenAuth.OAuth.xml
├── DotNetOpenAuth.OAuth.Core.4.3.0.13117/
│ ├── DotNetOpenAuth.OAuth.Core.4.3.0.13117.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.OAuth.xml
│ ├── net40-full/
│ │ └── DotNetOpenAuth.OAuth.xml
│ └── net45-full/
│ └── DotNetOpenAuth.OAuth.xml
├── DotNetOpenAuth.OpenId.Core.4.0.3.12153/
│ ├── DotNetOpenAuth.OpenId.Core.4.0.3.12153.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ ├── DotNetOpenAuth.OpenId.xml
│ │ ├── Mono.Math.xml
│ │ └── Org.Mentalis.Security.Cryptography.xml
│ └── net40-full/
│ ├── DotNetOpenAuth.OpenId.xml
│ ├── Mono.Math.xml
│ └── Org.Mentalis.Security.Cryptography.xml
├── DotNetOpenAuth.OpenId.Core.4.3.0.13117/
│ ├── DotNetOpenAuth.OpenId.Core.4.3.0.13117.nupkg
│ ├── content/
│ │ ├── net35-full/
│ │ │ └── web.config.transform
│ │ ├── net40-full/
│ │ │ └── web.config.transform
│ │ └── net45-full/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ ├── DotNetOpenAuth.OpenId.xml
│ │ ├── Mono.Math.xml
│ │ └── Org.Mentalis.Security.Cryptography.xml
│ ├── net40-full/
│ │ ├── DotNetOpenAuth.OpenId.xml
│ │ ├── Mono.Math.xml
│ │ └── Org.Mentalis.Security.Cryptography.xml
│ └── net45-full/
│ ├── DotNetOpenAuth.OpenId.xml
│ ├── Mono.Math.xml
│ └── Org.Mentalis.Security.Cryptography.xml
├── DotNetOpenAuth.OpenId.RelyingParty.4.0.3.12153/
│ ├── DotNetOpenAuth.OpenId.RelyingParty.4.0.3.12153.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.OpenId.RelyingParty.xml
│ └── net40-full/
│ └── DotNetOpenAuth.OpenId.RelyingParty.xml
├── DotNetOpenAuth.OpenId.RelyingParty.4.3.0.13117/
│ ├── DotNetOpenAuth.OpenId.RelyingParty.4.3.0.13117.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ ├── net35-full/
│ │ └── DotNetOpenAuth.OpenId.RelyingParty.xml
│ ├── net40-full/
│ │ └── DotNetOpenAuth.OpenId.RelyingParty.xml
│ └── net45-full/
│ └── DotNetOpenAuth.OpenId.RelyingParty.xml
├── EnterpriseLibrary.Caching.5.0.505.0/
│ ├── EnterpriseLibrary.Caching.5.0.505.0.nupkg
│ ├── lib/
│ │ ├── NET35/
│ │ │ └── Microsoft.Practices.EnterpriseLibrary.Caching.xml
│ │ └── SL40/
│ │ └── Microsoft.Practices.EnterpriseLibrary.Caching.Silverlight.xml
│ └── tools/
│ ├── Utils.psm1
│ └── install.ps1
├── EnterpriseLibrary.Common.5.0.505.0/
│ ├── EnterpriseLibrary.Common.5.0.505.0.nupkg
│ ├── lib/
│ │ ├── NET35/
│ │ │ └── Microsoft.Practices.EnterpriseLibrary.Common.xml
│ │ └── SL40/
│ │ └── Microsoft.Practices.EnterpriseLibrary.Common.Silverlight.xml
│ └── tools/
│ ├── Utils.psm1
│ └── install.ps1
├── EntityFramework.5.0.0/
│ ├── Content/
│ │ ├── App.config.transform
│ │ └── Web.config.transform
│ ├── EntityFramework.5.0.0.nupkg
│ ├── lib/
│ │ ├── net40/
│ │ │ └── EntityFramework.xml
│ │ └── net45/
│ │ └── EntityFramework.xml
│ └── tools/
│ ├── EntityFramework.PS3.psd1
│ ├── EntityFramework.psd1
│ ├── EntityFramework.psm1
│ ├── Redirect.VS11.config
│ ├── Redirect.config
│ ├── about_EntityFramework.help.txt
│ ├── init.ps1
│ └── install.ps1
├── EntityFramework.6.1.3/
│ ├── EntityFramework.6.1.3.nupkg
│ ├── content/
│ │ ├── App.config.transform
│ │ └── Web.config.transform
│ ├── lib/
│ │ ├── net40/
│ │ │ ├── EntityFramework.SqlServer.xml
│ │ │ └── EntityFramework.xml
│ │ └── net45/
│ │ ├── EntityFramework.SqlServer.xml
│ │ └── EntityFramework.xml
│ └── tools/
│ ├── EntityFramework.psd1
│ ├── EntityFramework.psm1
│ ├── about_EntityFramework.help.txt
│ ├── init.ps1
│ └── install.ps1
├── Microsoft.AspNet.Mvc.4.0.20710.0/
│ ├── Microsoft.AspNet.Mvc.4.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ └── System.Web.Mvc.xml
├── Microsoft.AspNet.Razor.2.0.20710.0/
│ ├── Microsoft.AspNet.Razor.2.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ └── System.Web.Razor.xml
├── Microsoft.AspNet.Web.Optimization.1.0.0/
│ └── Microsoft.AspNet.Web.Optimization.1.0.0.nupkg
├── Microsoft.AspNet.WebApi.4.0.20710.0/
│ └── Microsoft.AspNet.WebApi.4.0.20710.0.nupkg
├── Microsoft.AspNet.WebApi.Client.4.0.20710.0/
│ ├── Microsoft.AspNet.WebApi.Client.4.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ └── System.Net.Http.Formatting.xml
├── Microsoft.AspNet.WebApi.Core.4.0.20710.0/
│ ├── Microsoft.AspNet.WebApi.Core.4.0.20710.0.nupkg
│ ├── content/
│ │ └── web.config.transform
│ └── lib/
│ └── net40/
│ └── System.Web.Http.xml
├── Microsoft.AspNet.WebApi.WebHost.4.0.20710.0/
│ ├── Microsoft.AspNet.WebApi.WebHost.4.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ └── System.Web.Http.WebHost.xml
├── Microsoft.AspNet.WebPages.2.0.20710.0/
│ ├── Microsoft.AspNet.WebPages.2.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ ├── System.Web.Helpers.xml
│ ├── System.Web.WebPages.Deployment.xml
│ ├── System.Web.WebPages.Razor.xml
│ └── System.Web.WebPages.xml
├── Microsoft.AspNet.WebPages.Data.2.0.20710.0/
│ ├── Microsoft.AspNet.WebPages.Data.2.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ └── WebMatrix.Data.xml
├── Microsoft.AspNet.WebPages.OAuth.2.0.20710.0/
│ ├── Microsoft.AspNet.WebPages.OAuth.2.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ └── Microsoft.Web.WebPages.OAuth.xml
├── Microsoft.AspNet.WebPages.WebData.2.0.20710.0/
│ ├── Microsoft.AspNet.WebPages.WebData.2.0.20710.0.nupkg
│ └── lib/
│ └── net40/
│ └── WebMatrix.WebData.xml
├── Microsoft.Net.Http.2.0.20710.0/
│ ├── Microsoft.Net.Http.2.0.20710.0.nupkg
│ └── lib/
│ ├── net40/
│ │ ├── System.Net.Http.WebRequest.xml
│ │ └── System.Net.Http.xml
│ └── net45/
│ └── _._
├── Microsoft.Web.Infrastructure.1.0.0.0/
│ └── Microsoft.Web.Infrastructure.1.0.0.0.nupkg
├── Microsoft.jQuery.Unobtrusive.Ajax.2.0.20710.0/
│ ├── Content/
│ │ └── Scripts/
│ │ └── jquery.unobtrusive-ajax.js
│ └── Microsoft.jQuery.Unobtrusive.Ajax.2.0.20710.0.nupkg
├── Microsoft.jQuery.Unobtrusive.Validation.2.0.20710.0/
│ ├── Content/
│ │ └── Scripts/
│ │ └── jquery.validate.unobtrusive.js
│ └── Microsoft.jQuery.Unobtrusive.Validation.2.0.20710.0.nupkg
├── Modernizr.2.5.3/
│ ├── Content/
│ │ └── Scripts/
│ │ └── modernizr-2.5.3.js
│ └── Modernizr.2.5.3.nupkg
├── Newtonsoft.Json.4.5.6/
│ ├── Newtonsoft.Json.4.5.6.nupkg
│ └── lib/
│ ├── net20/
│ │ └── Newtonsoft.Json.xml
│ ├── net35/
│ │ └── Newtonsoft.Json.xml
│ ├── net40/
│ │ └── Newtonsoft.Json.xml
│ ├── sl3-wp/
│ │ └── Newtonsoft.Json.xml
│ ├── sl4/
│ │ └── Newtonsoft.Json.xml
│ ├── sl4-windowsphone71/
│ │ └── Newtonsoft.Json.xml
│ └── winrt45/
│ └── Newtonsoft.Json.xml
├── Unity.3.5.1404.0/
│ ├── Unity.3.5.1404.0.nupkg
│ ├── UnityConfiguration30.xsd
│ └── lib/
│ ├── net45/
│ │ ├── Microsoft.Practices.Unity.Configuration.XML
│ │ ├── Microsoft.Practices.Unity.RegistrationByConvention.XML
│ │ └── Microsoft.Practices.Unity.xml
│ ├── portable-net45+wp80+win8+MonoAndroid10+MonoTouch10/
│ │ └── Microsoft.Practices.Unity.xml
│ ├── win8/
│ │ ├── Microsoft.Practices.Unity.RegistrationByConvention.XML
│ │ ├── Microsoft.Practices.Unity.RegistrationByConvention.pri
│ │ └── Microsoft.Practices.Unity.xml
│ └── wp80/
│ ├── Microsoft.Practices.Unity.RegistrationByConvention.XML
│ └── Microsoft.Practices.Unity.xml
├── Unity.Interception.3.5.1404.0/
│ ├── Unity.Interception.3.5.1404.0.nupkg
│ └── lib/
│ └── Net45/
│ ├── Microsoft.Practices.Unity.Interception.Configuration.xml
│ └── Microsoft.Practices.Unity.Interception.xml
├── WebGrease.1.1.0/
│ └── WebGrease.1.1.0.nupkg
├── jQuery.1.7.1.1/
│ ├── Content/
│ │ └── Scripts/
│ │ ├── jquery-1.7.1-vsdoc.js
│ │ └── jquery-1.7.1.js
│ ├── Tools/
│ │ ├── common.ps1
│ │ ├── install.ps1
│ │ ├── jquery-1.7.1.intellisense.js
│ │ └── uninstall.ps1
│ └── jQuery.1.7.1.1.nupkg
├── jQuery.UI.Combined.1.8.20.1/
│ ├── Content/
│ │ ├── Content/
│ │ │ └── themes/
│ │ │ └── base/
│ │ │ ├── jquery-ui.css
│ │ │ ├── jquery.ui.accordion.css
│ │ │ ├── jquery.ui.all.css
│ │ │ ├── jquery.ui.autocomplete.css
│ │ │ ├── jquery.ui.base.css
│ │ │ ├── jquery.ui.button.css
│ │ │ ├── jquery.ui.core.css
│ │ │ ├── jquery.ui.datepicker.css
│ │ │ ├── jquery.ui.dialog.css
│ │ │ ├── jquery.ui.progressbar.css
│ │ │ ├── jquery.ui.resizable.css
│ │ │ ├── jquery.ui.selectable.css
│ │ │ ├── jquery.ui.slider.css
│ │ │ ├── jquery.ui.tabs.css
│ │ │ └── jquery.ui.theme.css
│ │ └── Scripts/
│ │ └── jquery-ui-1.8.20.js
│ └── jQuery.UI.Combined.1.8.20.1.nupkg
├── jQuery.Validation.1.9.0.1/
│ ├── Content/
│ │ └── Scripts/
│ │ ├── jquery.validate-vsdoc.js
│ │ └── jquery.validate.js
│ └── jQuery.Validation.1.9.0.1.nupkg
├── knockoutjs.2.1.0/
│ ├── Content/
│ │ └── Scripts/
│ │ ├── knockout-2.1.0.debug.js
│ │ └── knockout-2.1.0.js
│ └── knockoutjs.2.1.0.nupkg
├── log4net.2.0.3/
│ ├── lib/
│ │ ├── net10-full/
│ │ │ └── log4net.xml
│ │ ├── net11-full/
│ │ │ └── log4net.xml
│ │ ├── net20-full/
│ │ │ └── log4net.xml
│ │ ├── net35-client/
│ │ │ └── log4net.xml
│ │ ├── net35-full/
│ │ │ └── log4net.xml
│ │ ├── net40-client/
│ │ │ └── log4net.xml
│ │ └── net40-full/
│ │ └── log4net.xml
│ └── log4net.2.0.3.nupkg
└── repositories.config
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
================================================
FILE: .gitignore
================================================
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
================================================
FILE: .nuget/NuGet.Config
================================================
================================================
FILE: .nuget/NuGet.targets
================================================
$(MSBuildProjectDirectory)\..\
false
false
true
false
$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
$(SolutionDir).nuget
$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config
$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config
$(MSBuildProjectDirectory)\packages.config
$(PackagesProjectConfig)
$(NuGetToolsPath)\NuGet.exe
@(PackageSource)
"$(NuGetExePath)"
mono --runtime=v4.0.30319 "$(NuGetExePath)"
$(TargetDir.Trim('\\'))
-RequireConsent
-NonInteractive
"$(SolutionDir) "
"$(SolutionDir)"
$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)
$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
RestorePackages;
$(BuildDependsOn);
$(BuildDependsOn);
BuildPackage;
================================================
FILE: OnlineStore.Application/AddressResolver.cs
================================================
using AutoMapper;
using OnlineStore.Domain.Model;
using OnlineStore.ServiceContracts.ModelDTOs;
namespace OnlineStore.Application
{
public class AddressResolver : ValueResolver
{
protected override Address ResolveCore(AddressDto source)
{
return new Address
{
City = source.City,
Country = source.Country,
State = source.State,
Street = source.Street,
Zip = source.Zip
};
}
}
}
================================================
FILE: OnlineStore.Application/ApplicationService.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using OnlineStore.Domain;
using OnlineStore.Domain.Model;
using OnlineStore.Domain.Repositories;
using OnlineStore.ServiceContracts.ModelDTOs;
using OrderStatus = OnlineStore.Domain.Model.OrderStatus;
namespace OnlineStore.Application
{
// 定义一个应用服务抽象类,以便把重复的代码放在该抽象类中
public abstract class ApplicationService
{
private readonly IRepositoryContext _repositoryContext;
protected ApplicationService(IRepositoryContext repositoryContext)
{
_repositoryContext = repositoryContext;
}
protected IRepositoryContext RepositorytContext
{
get { return this._repositoryContext; }
}
#region Protected Methods
// 判断给定字符串是否是Guid.Empty
protected bool IsEmptyGuidString(string s)
{
if (string.IsNullOrWhiteSpace(s))
return true;
var guid = new Guid(s);
return guid == Guid.Empty;
}
// 处理简单的聚合创建逻辑。
protected TDtoList PerformCreateObjects(TDtoList dataTransferObjects,
IRepository repository,
Action processDto = null,
Action processAggregateRoot = null)
where TDtoList : List, new() where TAggregateRoot : class, IAggregateRoot
{
if (dataTransferObjects == null)
throw new ArgumentNullException("dataTransferObjects");
if (repository == null)
throw new ArgumentNullException("repository");
TDtoList result = new TDtoList();
if (dataTransferObjects.Count <= 0) return result;
var ars = new List();
foreach (var dto in dataTransferObjects)
{
if (processDto != null)
processDto(dto);
var ar = Mapper.Map(dto);
if (processAggregateRoot != null)
processAggregateRoot(ar);
ars.Add(ar);
repository.Add(ar);
}
RepositorytContext.Commit();
ars.ForEach(ar => result.Add(Mapper.Map(ar)));
return result;
}
// 处理简单的聚合更新操作。
protected TDtoList PerformUpdateObjects(TDtoList dataTransferObjects,
IRepository repository,
Func idFunc,
Action updateAction)
where TDtoList : List, new()
where TAggregateRoot : class, IAggregateRoot
{
if (dataTransferObjects == null)
throw new ArgumentNullException("dataTransferObjects");
if (repository == null)
throw new ArgumentNullException("repository");
if (idFunc == null)
throw new ArgumentNullException("idFunc");
if (updateAction == null)
throw new ArgumentNullException("updateAction");
TDtoList result = null;
if (dataTransferObjects.Count > 0)
{
result = new TDtoList();
foreach (var dto in dataTransferObjects)
{
if (IsEmptyGuidString(idFunc(dto)))
throw new ArgumentNullException("Id");
var id = new Guid(idFunc(dto));
var ar = repository.GetByKey(id);
updateAction(ar, dto);
repository.Update(ar);
result.Add(Mapper.Map(ar));
}
RepositorytContext.Commit();
}
return result;
}
// 处理简单的删除聚合根的操作。
protected void PerformDeleteObjects(IList ids, IRepository repository, Action preDelete = null, Action postDelete = null)
where TAggregateRoot : class, IAggregateRoot
{
if (ids == null)
throw new ArgumentNullException("ids");
if (repository == null)
throw new ArgumentNullException("repository");
foreach (var id in ids)
{
var guid = new Guid(id);
if (preDelete != null)
preDelete(guid);
var ar = repository.GetByKey(guid);
repository.Remove(ar);
if (postDelete != null)
postDelete(guid);
}
RepositorytContext.Commit();
}
#endregion
// AutoMapper框架的初始化
public static void Initialize()
{
Mapper.CreateMap();
Mapper.CreateMap()
.ForMember(uMermber => uMermber.ContactAddress, mceUto=> mceUto.ResolveUsing().FromMember(fm=>fm.ContactAddress))
.ForMember(uMember => uMember.DeliveryAddress, mceUto =>
mceUto.ResolveUsing().FromMember(fm => fm.DeliveryAddress));
Mapper.CreateMap()
.ForMember(udoMember => udoMember.ContactAddress, mceU =>
mceU.ResolveUsing().FromMember(fm => fm.ContactAddress))
.ForMember(udoMember => udoMember.DeliveryAddress, mceU =>
mceU.ResolveUsing().FromMember(fm => fm.DeliveryAddress));
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap()
//.ForMember(odtoMember => odtoMember.Subtotal,
// mceO => mceO.ResolveUsing(
// o => o.OrderItems.Sum(item => item.ItemAmout)))
.ForMember(odtoMember => odtoMember.UserContact,
mceO => mceO.ResolveUsing(o => o.User.Contact))
.ForMember(odtoMember => odtoMember.UserPhone,
mceO => mceO.ResolveUsing(o => o.User.PhoneNumber))
.ForMember(odtoMember => odtoMember.UserEmail,
mceO => mceO.ResolveUsing(o => o.User.Email))
.ForMember(odtoMember => odtoMember.UserId,
mceO => mceO.ResolveUsing(o => o.User.Id))
.ForMember(odtoMember => odtoMember.UserName,
mceO => mceO.ResolveUsing(o => o.User.UserName))
.ForMember(odtoMember => odtoMember.UserAddressCountry,
mceO => mceO.ResolveUsing(o => o.User.DeliveryAddress.Country))
.ForMember(odtoMember => odtoMember.UserAddressState,
mceO => mceO.ResolveUsing(o => o.User.DeliveryAddress.State))
.ForMember(odtoMember => odtoMember.UserAddressCity,
mceO => mceO.ResolveUsing(o => o.User.DeliveryAddress.City))
.ForMember(odtoMember => odtoMember.UserAddressStreet,
mceO => mceO.ResolveUsing(o => o.User.DeliveryAddress.Street))
.ForMember(odtoMember => odtoMember.UserAddressZip,
mceO => mceO.ResolveUsing(o => o.User.DeliveryAddress.Zip))
.ForMember(odtoMember => odtoMember.Status,
mceO => mceO.ResolveUsing(o =>
{
switch (o.Status)
{
case OrderStatus.Created:
return OrderStatusDto.Created;
case OrderStatus.Delivered:
return OrderStatusDto.Delivered;
case OrderStatus.Dispatched:
return OrderStatusDto.Dispatched;
case OrderStatus.Paid:
return OrderStatusDto.Paid;
case OrderStatus.Picked:
return OrderStatusDto.Picked;
default:
throw new InvalidOperationException();
}
}));
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap();
}
}
}
================================================
FILE: OnlineStore.Application/Global.asax
================================================
<%@ Application Codebehind="Global.asax.cs" Inherits="OnlineStore.Application.Global" Language="C#" %>
================================================
FILE: OnlineStore.Application/Global.asax.cs
================================================
using System;
using System.Web;
using OnlineStore.Repositories.EntityFramework;
namespace OnlineStore.Application
{
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
OnlineStoreDbContextInitailizer.Initialize();
ApplicationService.Initialize();
log4net.Config.XmlConfigurator.Configure();
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}
================================================
FILE: OnlineStore.Application/InversedAddressResolver.cs
================================================
using AutoMapper;
using OnlineStore.Domain.Model;
using OnlineStore.ServiceContracts.ModelDTOs;
namespace OnlineStore.Application
{
public class InversedAddressResolver : ValueResolver
{
protected override AddressDto ResolveCore(Address source)
{
return new AddressDto
{
City = source.City,
Country = source.Country,
State = source.State,
Street = source.Street,
Zip = source.Zip
};
}
}
}
================================================
FILE: OnlineStore.Application/Logs/onlinestore.txt
================================================
================================================
FILE: OnlineStore.Application/OnlineStore.Application.csproj
================================================
Debug
AnyCPU
2.0
{C4B3BA5F-A38D-4E52-B49E-6D69E8619016}
{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
Library
Properties
OnlineStore.Application
OnlineStore.Application
v4.5
True
true
..\
true
true
full
false
bin\
DEBUG;TRACE
prompt
4
pdbonly
true
bin\
TRACE
prompt
4
..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll
True
..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll
True
False
..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
..\packages\log4net.2.0.3\lib\net40-full\log4net.dll
True
..\packages\EnterpriseLibrary.Caching.5.0.505.0\lib\NET35\Microsoft.Practices.EnterpriseLibrary.Caching.dll
True
..\packages\EnterpriseLibrary.Common.5.0.505.0\lib\NET35\Microsoft.Practices.EnterpriseLibrary.Common.dll
True
..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll
True
..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.dll
True
..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.Configuration.dll
True
..\packages\Unity.Interception.3.5.1404.0\lib\Net45\Microsoft.Practices.Unity.Interception.dll
True
..\packages\Unity.Interception.3.5.1404.0\lib\Net45\Microsoft.Practices.Unity.Interception.Configuration.dll
True
..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll
True
OnlineStore.mdf
Always
Global.asax
OrderService.svc
ProductService.svc
UserService.svc
Web.config
Always
Web.config
Always
{1ae7732f-2faf-407e-89dd-bad81c4132e0}
OnlineStore.Domain
{2471e6b9-1030-48b8-bbc4-5018a221fbe2}
OnlineStore.Events.Handlers
{f165abc2-f76a-4fd7-8675-833264855221}
OnlineStore.Events
{9dde33cc-cf3c-436e-8a5f-4e1f0f8b603e}
OnlineStore.Infrastructure
{30afab37-57be-459c-a36a-5a72bbf77529}
OnlineStore.Repositories
{d46d13dd-1e1a-451b-ad17-42ed3fc54eac}
OnlineStore.ServiceContracts
10.0
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
True
True
8003
/
http://localhost:8003/
False
False
False
This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
================================================
FILE: OnlineStore.Application/OrderService.svc
================================================
<%@ ServiceHost Language="C#" Debug="true" Service="OnlineStore.Application.OrderService" CodeBehind="OrderService.svc.cs" %>
================================================
FILE: OnlineStore.Application/OrderService.svc.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using OnlineStore.Domain.Model;
using OnlineStore.Infrastructure;
using OnlineStore.ServiceContracts;
using OnlineStore.ServiceContracts.ModelDTOs;
namespace OnlineStore.Application
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class OrderService : IOrderService
{
private readonly IOrderService _orderServiceImp;
public OrderService()
{
_orderServiceImp = ServiceLocator.Instance.GetService();
}
public void AddProductToCart(Guid customerId, Guid productId, int quantity)
{
try
{
_orderServiceImp.AddProductToCart(customerId, productId, quantity);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public ShoppingCartDto GetShoppingCart(Guid customerId)
{
try
{
return _orderServiceImp.GetShoppingCart(customerId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public int GetShoppingCartItemCount(Guid userId)
{
try
{
return _orderServiceImp.GetShoppingCartItemCount(userId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void UpdateShoppingCartItem(Guid shoppingCartItemId, int quantity)
{
try
{
_orderServiceImp.UpdateShoppingCartItem(shoppingCartItemId, quantity);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void DeleteShoppingCartItem(Guid shoppingCartItemId)
{
try
{
_orderServiceImp.DeleteShoppingCartItem(shoppingCartItemId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public OrderDto Checkout(Guid customerId)
{
try
{
return _orderServiceImp.Checkout(customerId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public OrderDto GetOrder(Guid orderId)
{
try
{
return _orderServiceImp.GetOrder(orderId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList GetOrdersForUser(Guid userId)
{
try
{
return _orderServiceImp.GetOrdersForUser(userId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList GetAllOrders()
{
try
{
return _orderServiceImp.GetAllOrders();
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void Confirm(Guid orderId)
{
try
{
_orderServiceImp.Confirm(orderId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void Dispatch(Guid orderId)
{
try
{
_orderServiceImp.Dispatch(orderId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
}
}
================================================
FILE: OnlineStore.Application/ProductService.svc
================================================
<%@ ServiceHost Language="C#" Debug="true" Service="OnlineStore.Application.ProductService" CodeBehind="ProductService.svc.cs" %>
================================================
FILE: OnlineStore.Application/ProductService.svc.cs
================================================
using System;
using System.Collections.Generic;
using System.ServiceModel;
using OnlineStore.Infrastructure;
using OnlineStore.ServiceContracts;
using OnlineStore.ServiceContracts.ModelDTOs;
namespace OnlineStore.Application
{
// 商品WCF服务
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class ProductService : IProductService
{
// 引用商品服务接口
private readonly IProductService _productService;
public ProductService()
{
_productService = ServiceLocator.Instance.GetService();
}
public IEnumerable GetProducts()
{
try
{
return _productService.GetProducts();
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IEnumerable GetProductsForCategory(Guid categoryId)
{
try
{
return _productService.GetProductsForCategory(categoryId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IEnumerable GetNewProducts(int count)
{
try
{
return _productService.GetNewProducts(count);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public CategoryDto GetCategoryById(Guid id)
{
try
{
return _productService.GetCategoryById(id);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IEnumerable GetCategories()
{
try
{
return _productService.GetCategories();
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public ProductDto GetProductById(Guid id)
{
try
{
return _productService.GetProductById(id);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public List CreateProducts(List productsDtos)
{
try
{
return _productService.CreateProducts(productsDtos);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public List CreateCategories(List categoriDtos)
{
try
{
return _productService.CreateCategories(categoriDtos);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public List UpdateProducts(List productsDtos)
{
try
{
return _productService.UpdateProducts(productsDtos);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public List UpdateCategories(List categoriDtos)
{
try
{
return _productService.UpdateCategories(categoriDtos);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void DeleteProducts(List produtList)
{
try
{
_productService.DeleteProducts(produtList);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void DeleteCategories(List categoryList)
{
try
{
_productService.DeleteCategories(categoryList);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public ProductCategorizationDto CategorizeProduct(Guid productId, Guid categoryId)
{
try
{
return _productService.CategorizeProduct(productId, categoryId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void UncategorizeProduct(Guid productId)
{
try
{
_productService.UncategorizeProduct(productId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public ProductDtoWithPagination GetProductsWithPagination(Pagination pagination)
{
try
{
return _productService.GetProductsWithPagination(pagination);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public ProductDtoWithPagination GetProductsForCategoryWithPagination(Guid categoryId, Pagination pagination)
{
try
{
return _productService.GetProductsForCategoryWithPagination(categoryId, pagination);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
}
}
================================================
FILE: OnlineStore.Application/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OnlineStore.Application")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("OnlineStore.Application")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dac59b79-780a-4aa9-a382-7e2af67b7d0c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: OnlineStore.Application/ServiceImplementations/OrderServiceImp.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using OnlineStore.Domain;
using OnlineStore.Domain.Model;
using OnlineStore.Domain.Repositories;
using OnlineStore.Domain.Specifications;
using OnlineStore.ServiceContracts;
using OnlineStore.ServiceContracts.ModelDTOs;
using System.Linq;
using System.Transactions;
using OnlineStore.Domain.Services;
using OnlineStore.Events.Bus;
namespace OnlineStore.Application.ServiceImplementations
{
public class OrderServiceImp : ApplicationService, IOrderService
{
#region Private Fileds
private readonly IShoppingCartRepository _shoppingCartRepository;
private readonly IShoppingCartItemRepository _shoppingCartItemRepository;
private readonly IUserRepository _userRepository;
private readonly IOrderRepository _orderRepository;
private readonly IProductRepository _productRepository;
private readonly IDomainService _domainService;
private readonly IEventBus _eventBus;
#endregion
#region Ctor
public OrderServiceImp(IRepositoryContext context,
IUserRepository userRepository,
IShoppingCartRepository shoppingCartRepository,
IProductRepository productRepository,
IShoppingCartItemRepository shoppingCartItemRepository,
IDomainService domainService,
IOrderRepository orderRepository,
IEventBus eventBus) : base(context)
{
_userRepository = userRepository;
_shoppingCartRepository = shoppingCartRepository;
_productRepository = productRepository;
_shoppingCartItemRepository = shoppingCartItemRepository;
_domainService = domainService;
_orderRepository = orderRepository;
_eventBus = eventBus;
}
#endregion
#region IOrderService Members
public void AddProductToCart(Guid customerId, Guid productId, int quantity)
{
var user = _userRepository.GetByKey(customerId);
var shoppingCart = _shoppingCartRepository.GetBySpecification(new ExpressionSpecification(s=>s.User.Id == user.Id));
if (shoppingCart == null)
throw new DomainException("用户{0}不存在购物车.", customerId);
var product = _productRepository.GetByKey(productId);
var shoppingCartItem = _shoppingCartItemRepository.FindItem(shoppingCart, product);
if (shoppingCartItem == null)
{
shoppingCartItem = new ShoppingCartItem()
{
Product = product,
ShoopingCart = shoppingCart,
Quantity = quantity
};
_shoppingCartItemRepository.Add(shoppingCartItem);
}
else
{
shoppingCartItem.UpdateQuantity(shoppingCartItem.Quantity + quantity);
_shoppingCartItemRepository.Update(shoppingCartItem);
}
RepositorytContext.Commit();
}
public ShoppingCartDto GetShoppingCart(Guid customerId)
{
var user = _userRepository.GetByKey(customerId);
var shoppingCart = _shoppingCartRepository.GetBySpecification(
new ExpressionSpecification(s => s.User.Id == user.Id));
if (shoppingCart == null)
throw new DomainException("用户{0}不存在购物车.", customerId);
var shoppingCartItems =
_shoppingCartItemRepository.GetAll(
new ExpressionSpecification(s => s.ShoopingCart.Id == shoppingCart.Id), elp => elp.Product);
var shoppingCartDto = Mapper.Map(shoppingCart);
shoppingCartDto.Items = new List();
if (shoppingCartItems != null && shoppingCartItems.Any())
{
shoppingCartItems
.ToList()
.ForEach(s => shoppingCartDto.Items.Add(Mapper.Map(s)));
shoppingCartDto.Subtotal = shoppingCartDto.Items.Sum(p => p.ItemAmount);
}
return shoppingCartDto;
}
public int GetShoppingCartItemCount(Guid userId)
{
var user = _userRepository.GetByKey(userId);
var shoppingCart = _shoppingCartRepository.GetBySpecification(new ExpressionSpecification(s => s.User.Id == user.Id));
if(shoppingCart == null)
throw new InvalidOperationException("没有可用的购物车实例.");
var shoppingCartItems =
_shoppingCartItemRepository.GetAll(new ExpressionSpecification(s => s.ShoopingCart.Id == shoppingCart.Id), elp => elp.Product);
return shoppingCartItems.Sum(s => s.Quantity);
}
public void UpdateShoppingCartItem(Guid shoppingCartItemId, int quantity)
{
var shoppingCartItem = _shoppingCartItemRepository.GetByKey(shoppingCartItemId);
shoppingCartItem.UpdateQuantity(quantity);
_shoppingCartItemRepository.Update(shoppingCartItem);
RepositorytContext.Commit();
}
public void DeleteShoppingCartItem(Guid shoppingCartItemId)
{
var shoppingCartItem = _shoppingCartItemRepository.GetByKey(shoppingCartItemId);
_shoppingCartItemRepository.Remove(shoppingCartItem);
RepositorytContext.Commit();
}
public OrderDto Checkout(Guid customerId)
{
var user = _userRepository.GetByKey(customerId);
var shoppingCart = _shoppingCartRepository.GetByExpression(s => s.User.Id == user.Id);
var order = _domainService.CreateOrder(user, shoppingCart);
return Mapper.Map(order);
}
public OrderDto GetOrder(Guid orderId)
{
var order = _orderRepository.GetBySpecification(new ExpressionSpecification(o=>o.Id.Equals(orderId)), elp=>elp.OrderItems);
return Mapper.Map(order);
}
// 获得指定用户的所有订单
public IList GetOrdersForUser(Guid userId)
{
var user = _userRepository.GetByKey(userId);
var orders = _orderRepository.GetAll(new ExpressionSpecification(o => o.User.Id == userId), sp => sp.CreatedDate, SortOrder.Descending, elp=>elp.OrderItems);
var orderDtos = new List();
orders
.ToList()
.ForEach(o=>orderDtos.Add(Mapper.Map(o)));
return orderDtos;
}
public IList GetAllOrders()
{
var orders = _orderRepository.GetAll(sort => sort.CreatedDate, SortOrder.Descending);
var orderDtos = new List();
orders
.ToList()
.ForEach(o=>orderDtos.Add(Mapper.Map(o)));
return orderDtos;
}
public void Confirm(Guid orderId)
{
using (var transactionScope = new TransactionScope())
{
var order = _orderRepository.GetByKey(orderId);
order.Confirm();
_orderRepository.Update(order);
RepositorytContext.Commit();
_eventBus.Commit();
transactionScope.Complete();
}
}
public void Dispatch(Guid orderId)
{
using (var transactionScope = new TransactionScope())
{
var order = _orderRepository.GetByKey(orderId);
order.Dispatch();
_orderRepository.Update(order);
RepositorytContext.Commit();
_eventBus.Commit();
transactionScope.Complete();
}
}
#endregion
}
}
================================================
FILE: OnlineStore.Application/ServiceImplementations/ProductServiceImp.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using OnlineStore.Domain.Model;
using OnlineStore.Domain.Repositories;
using OnlineStore.Domain.Services;
using OnlineStore.Domain.Specifications;
using OnlineStore.ServiceContracts;
using OnlineStore.ServiceContracts.ModelDTOs;
namespace OnlineStore.Application.ServiceImplementations
{
// 商品服务的实现
public class ProductServiceImp : ApplicationService, IProductService
{
#region Private Fields
private readonly IProductRepository _productRepository;
private readonly ICategoryRepository _categoryRepository;
private readonly IProductCategorizationRepository _productCategorizationRepository;
private readonly IDomainService _domainService;
#endregion
#region Ctor
public ProductServiceImp(IRepositoryContext context,
IProductRepository productRepository,
ICategoryRepository categoryRepository,
IProductCategorizationRepository productCategorizationRepository,
IDomainService domainService) :base(context)
{
_categoryRepository = categoryRepository;
_productRepository = productRepository;
_productCategorizationRepository = productCategorizationRepository;
_domainService = domainService;
}
#endregion
#region IProductService Members
public IEnumerable GetProducts()
{
var result = new List();
_productRepository.
GetAll().
ToList().
ForEach(p =>
{
var productDto = Mapper.Map(p);
{
var category = _productCategorizationRepository.GetCategoryForProduct(p);
if (category != null)
productDto.Category = Mapper.Map(category);
}
result.Add(productDto);
});
return result;
}
public ProductDtoWithPagination GetProductsWithPagination(Pagination pagination)
{
var pagedProducts = _productRepository.GetAll(sp => sp.Name, SortOrder.Ascending, pagination.PageNumber,
pagination.PageSize);
pagination.TotalPages = pagedProducts.TotalPages;
var productDtoList = new List();
pagedProducts.PageData.ToList().ForEach(p=>productDtoList.Add(Mapper.Map(p)));
return new ProductDtoWithPagination()
{
Pagination = pagination,
ProductDtos = productDtoList
};
}
public IEnumerable GetProductsForCategory(Guid categoryId)
{
var result = new List();
var category = _categoryRepository.GetByKey(categoryId);
var products = _productCategorizationRepository.GetProductsForCategory(category);
products.ToList().ForEach(p=>result.Add(Mapper.Map(p)));
return result;
}
public ProductDtoWithPagination GetProductsForCategoryWithPagination(Guid categoryId, Pagination pagination)
{
var category = _categoryRepository.GetByKey(categoryId);
var pagedProducts = _productCategorizationRepository.GetProductsForCategoryWithPagination(category, pagination.PageNumber,
pagination.PageSize);
if (pagedProducts == null)
{
pagination.TotalPages = 0;
return new ProductDtoWithPagination()
{
Pagination = pagination,
ProductDtos = new List()
};
}
pagination.TotalPages = pagedProducts.TotalPages;
var productDtoList = new List();
pagedProducts.PageData.ToList().ForEach(p=>productDtoList.Add(Mapper.Map(p)));
return new ProductDtoWithPagination()
{
Pagination = pagination,
ProductDtos = productDtoList
};
}
public IEnumerable GetNewProducts(int count)
{
var newProducts = new List();
_productRepository.GetNewProducts(count)
.ToList()
.ForEach
(
np => newProducts.Add(Mapper.Map(np))
);
return newProducts;
}
public CategoryDto GetCategoryById(Guid id)
{
var category = _categoryRepository.GetByKey(id);
var result = Mapper.Map(category);
return result;
}
public IEnumerable GetCategories()
{
var result = new List();
_categoryRepository.GetAll().ToList().ForEach(c =>
{
var categoryDto = Mapper.Map(c);
result.Add(categoryDto);
});
return result;
}
public ProductDto GetProductById(Guid id)
{
var product = _productRepository.GetByKey(id);
var result = Mapper.Map(product);
result.Category =
Mapper.Map(_productCategorizationRepository.GetCategoryForProduct(product));
return result;
}
public List CreateProducts(List productsDtos)
{
return PerformCreateObjects, ProductDto, Product>(productsDtos, _productRepository);
}
public List CreateCategories(List categoriDtos)
{
return PerformCreateObjects, CategoryDto, Category>(categoriDtos, _categoryRepository);
}
public List UpdateProducts(List productsDtos)
{
return PerformUpdateObjects, ProductDto, Product>(productsDtos,
_productRepository,
pdto => pdto.Id,
(p, pdto) =>
{
if (!string.IsNullOrEmpty(pdto.Description))
p.Description = pdto.Description;
if (!string.IsNullOrEmpty(pdto.ImageUrl))
p.ImageUrl = pdto.ImageUrl;
if (!string.IsNullOrEmpty(pdto.Name))
p.Name = pdto.Name;
if (pdto.IsNew != null)
p.IsNew = pdto.IsNew.Value;
if (pdto.UnitPrice != null)
p.UnitPrice = pdto.UnitPrice.Value;
});
}
public List UpdateCategories(List categoriDtos)
{
return PerformUpdateObjects, CategoryDto, Category>(categoriDtos,
_categoryRepository,
cdto => cdto.Id,
(c, cdto) =>
{
if (!string.IsNullOrEmpty(cdto.Name))
c.Name = cdto.Name;
if (!string.IsNullOrEmpty(cdto.Description))
c.Description = cdto.Description;
});
}
public void DeleteProducts(List produList)
{
PerformDeleteObjects(produList,
_productRepository,
id =>
{
var categorization = _productCategorizationRepository.GetBySpecification(Specification.Eval(c => c.ProductId == id));
if (categorization != null)
_productCategorizationRepository.Remove(categorization);
});
}
public void DeleteCategories(List categoryList)
{
PerformDeleteObjects(categoryList,
_categoryRepository,
id =>
{
var categorization = _productCategorizationRepository.GetBySpecification(Specification.Eval(c => c.CategoryId == id));
if (categorization != null)
_productCategorizationRepository.Remove(categorization);
});
}
public ProductCategorizationDto CategorizeProduct(Guid productId, Guid categoryId)
{
if (productId == Guid.Empty)
throw new ArgumentNullException("productId");
if (categoryId == Guid.Empty)
throw new ArgumentNullException("categoryId");
var product = _productRepository.GetByKey(productId);
var category = _categoryRepository.GetByKey(categoryId);
return Mapper.Map(_domainService.Categorize(product, category));
}
public void UncategorizeProduct(Guid productId)
{
if (productId == Guid.Empty)
throw new ArgumentNullException("productId");
var product = _productRepository.GetByKey(productId);
_domainService.Uncategorize(product);
}
#endregion
}
}
================================================
FILE: OnlineStore.Application/ServiceImplementations/UserServiceImp.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using AutoMapper;
using OnlineStore.Domain.Model;
using OnlineStore.Domain.Repositories;
using OnlineStore.Domain.Services;
using OnlineStore.Domain.Specifications;
using OnlineStore.ServiceContracts;
using OnlineStore.ServiceContracts.ModelDTOs;
namespace OnlineStore.Application.ServiceImplementations
{
public class UserServiceImp :ApplicationService, IUserService
{
private readonly IUserRepository _userRepository;
private readonly IShoppingCartRepository _shoppingCartRepository;
private readonly IUserRoleRepository _userRoleRepository;
private readonly IRoleRepository _roleRepository;
private readonly IDomainService _domainService;
public UserServiceImp(IRepositoryContext repositoryContext,
IUserRepository userRepository,
IShoppingCartRepository shoppingCartRepository,
IDomainService domainService,
IRoleRepository roleRepository,
IUserRoleRepository userRoleRepository)
: base(repositoryContext)
{
_userRepository = userRepository;
_shoppingCartRepository = shoppingCartRepository;
_domainService = domainService;
_roleRepository = roleRepository;
_userRoleRepository = userRoleRepository;
}
#region IUserService Members
public IList CreateUsers(List userDtos)
{
if (userDtos == null)
throw new ArgumentNullException("userDtos");
return PerformCreateObjects, UserDto, User>(userDtos,
_userRepository,
dto =>
{
if (dto.RegisteredDate == null)
dto.RegisteredDate = DateTime.Now;
},
ar =>
{
var shoppingCart = ar.CreateShoppingCart();
_shoppingCartRepository.Add(shoppingCart);
});
}
public bool ValidateUser(string userName, string password)
{
if (string.IsNullOrEmpty(userName))
throw new ArgumentNullException("userName");
if (string.IsNullOrEmpty(password))
throw new ArgumentNullException("password");
return _userRepository.CheckPassword(userName, password);
}
public bool DisableUser(UserDto userDto)
{
if(userDto == null)
throw new ArgumentNullException("userDto");
User user;
if (!IsEmptyGuidString(userDto.Id))
user = _userRepository.GetByKey(new Guid(userDto.Id));
else if (!string.IsNullOrEmpty(userDto.UserName))
user = _userRepository.GetByExpression(u=>u.UserName == userDto.UserName);
else if (!string.IsNullOrEmpty(userDto.Email))
user = _userRepository.GetByExpression(u => u.Email == userDto.Email);
else
throw new ArgumentNullException("userDto", "Either ID, UserName or Email should be specified.");
user.Disable();
_userRepository.Update(user);
RepositorytContext.Commit();
return user.IsDisabled;
}
public bool EnableUser(UserDto userDto)
{
if (userDto == null)
throw new ArgumentNullException("userDto");
User user;
if (!IsEmptyGuidString(userDto.Id))
user = _userRepository.GetByKey(new Guid(userDto.Id));
else if (!string.IsNullOrEmpty(userDto.UserName))
user = _userRepository.GetByExpression(u => u.UserName == userDto.UserName);
else if (!string.IsNullOrEmpty(userDto.Email))
user = _userRepository.GetByExpression(u => u.Email == userDto.Email);
else
throw new ArgumentNullException("userDto", "Either ID, UserName or Email should be specified.");
user.Enable();
_userRepository.Update(user);
RepositorytContext.Commit();
return user.IsDisabled;
}
public IList UpdateUsers(List userDataObjects)
{
return PerformUpdateObjects, UserDto, User>(userDataObjects, _userRepository,
userDto => userDto.Id,
(u, userDto) =>
{
if (!string.IsNullOrEmpty(userDto.Contact))
u.Contact = userDto.Contact;
if (!string.IsNullOrEmpty(userDto.PhoneNumber))
u.PhoneNumber = userDto.PhoneNumber;
if (userDto.ContactAddress != null)
{
if (!string.IsNullOrEmpty(userDto.ContactAddress.City))
u.ContactAddress.City = userDto.ContactAddress.City;
if (!string.IsNullOrEmpty(userDto.ContactAddress.Country))
u.ContactAddress.Country = userDto.ContactAddress.Country;
if (!string.IsNullOrEmpty(userDto.ContactAddress.State))
u.ContactAddress.State = userDto.ContactAddress.State;
if (!string.IsNullOrEmpty(userDto.ContactAddress.Street))
u.ContactAddress.Street = userDto.ContactAddress.Street;
if (!string.IsNullOrEmpty(userDto.ContactAddress.Zip))
u.ContactAddress.Zip = userDto.ContactAddress.Zip;
}
if (userDto.DeliveryAddress != null)
{
if (!string.IsNullOrEmpty(userDto.DeliveryAddress.City))
u.DeliveryAddress.City = userDto.DeliveryAddress.City;
if (!string.IsNullOrEmpty(userDto.DeliveryAddress.Country))
u.DeliveryAddress.Country = userDto.DeliveryAddress.Country;
if (!string.IsNullOrEmpty(userDto.DeliveryAddress.State))
u.DeliveryAddress.State = userDto.DeliveryAddress.State;
if (!string.IsNullOrEmpty(userDto.DeliveryAddress.Street))
u.DeliveryAddress.Street = userDto.DeliveryAddress.Street;
if (!string.IsNullOrEmpty(userDto.DeliveryAddress.Zip))
u.DeliveryAddress.Zip = userDto.DeliveryAddress.Zip;
}
if (userDto.LastLogonDate != null)
u.LastLogonDate = userDto.LastLogonDate;
if (userDto.RegisteredDate != null)
u.RegisteredDate = userDto.RegisteredDate.Value;
if (!string.IsNullOrEmpty(userDto.Email))
u.Email = userDto.Email;
if (userDto.IsDisabled != null)
{
if (userDto.IsDisabled.Value)
u.Disable();
else
u.Enable();
}
if (!string.IsNullOrEmpty(userDto.Password))
u.Password = userDto.Password;
});
}
public void DeleteUsers(List userDtos)
{
if (userDtos == null)
throw new ArgumentNullException("userDtos");
foreach (var userDto in userDtos)
{
User user = null;
if (!IsEmptyGuidString(userDto.Id))
user = _userRepository.GetByKey(new Guid(userDto.Id));
else if (!string.IsNullOrEmpty(userDto.UserName))
user = _userRepository.GetByExpression(u => u.UserName == userDto.UserName);
else if (!string.IsNullOrEmpty(userDto.Email))
user = _userRepository.GetByExpression(u=>u.Email == userDto.Email);
else
throw new ArgumentNullException("userDtos", "Either ID, UserName or Email should be specified.");
var userRole = _userRoleRepository.GetBySpecification(Specification.Eval(ur => ur.UserId == user.Id));
if (userRole != null)
_userRoleRepository.Remove(userRole);
_userRepository.Remove(user);
}
RepositorytContext.Commit();
}
public UserDto GetUserByKey(Guid id)
{
var user = _userRepository.GetByKey(id);
var userDto = Mapper.Map(user);
return userDto;
}
public UserDto GetUserByEmail(string email)
{
if(string.IsNullOrEmpty(email))
throw new ArgumentException("email");
var user = _userRepository.GetByExpression(u => u.Email == email);
var userDto = Mapper.Map(user);
return userDto;
}
public UserDto GetUserByName(string userName)
{
if (string.IsNullOrEmpty(userName))
throw new ArgumentException("userName");
var user = _userRepository.GetByExpression(u => u.UserName == userName);
var userDto = Mapper.Map(user);
return userDto;
}
public IList GetUsers()
{
var users = _userRepository.GetAll();
if (users == null)
return null;
var result = new List();
foreach (var user in users)
{
var userDto = Mapper.Map(user);
var role = _userRoleRepository.GetRoleForUser(user);
if (role != null)
{
userDto.Role = Mapper.Map(role);
}
result.Add(userDto);
}
return result;
}
public IList GetRoles()
{
var roles = _roleRepository.GetAll();
if (roles == null)
return null;
var result = roles.Select(role => Mapper.Map(role)).ToList();
return result;
}
public RoleDto GetRoleByKey(Guid id)
{
return Mapper.Map(_roleRepository.GetByKey(id));
}
public IList CreateRoles(List roleDataObjects)
{
return PerformCreateObjects, RoleDto, Role>(roleDataObjects, _roleRepository);
}
public IList UpdateRoles(List roleDataObjects)
{
return PerformUpdateObjects, RoleDto, Role>(roleDataObjects,
_roleRepository,
roleDto => roleDto.Id,
(r, roleDto) =>
{
if (!string.IsNullOrEmpty(roleDto.Name))
r.Name = roleDto.Name;
if (!string.IsNullOrEmpty(roleDto.Description))
r.Description = roleDto.Description;
});
}
///
/// 删除角色
///
/// 需要删除的角色ID值列表
public void DeleteRoles(List roleList)
{
PerformDeleteObjects(roleList,
_roleRepository,
id =>
{
var userRole = _userRoleRepository.GetBySpecification(Specification.Eval(ur => ur.RoleId == id));
if (userRole != null)
_userRoleRepository.Remove(userRole);
});
}
public void AssignRole(Guid userId, Guid roleId)
{
var user = _userRepository.GetByKey(userId);
var role = _roleRepository.GetByKey(roleId);
_domainService.AssignRole(user, role);
}
public void UnassignRole(Guid userId)
{
var user = _userRepository.GetByKey(userId);
_domainService.UnassignRole(user);
}
// 根据指定的用户名,获取该用户所属的角色
public RoleDto GetRoleByUserName(string userName)
{
var user = _userRepository.GetByExpression(u=>u.UserName == userName);
var role = _userRoleRepository.GetRoleForUser(user);
return Mapper.Map(role);
}
public IList GetOrdersForUser(string userName)
{
var user = _userRepository.GetByExpression(u => u.UserName == userName);
var orders = user.Orders;
var result = new List();
if (orders == null) return result;
result = orders.Select(so => Mapper.Map(so)).ToList();
return result;
}
#endregion
}
}
================================================
FILE: OnlineStore.Application/UserService.svc
================================================
<%@ ServiceHost Language="C#" Debug="true" Service="OnlineStore.Application.UserService" CodeBehind="UserService.svc.cs" %>
================================================
FILE: OnlineStore.Application/UserService.svc.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using OnlineStore.Infrastructure;
using OnlineStore.ServiceContracts;
using OnlineStore.ServiceContracts.ModelDTOs;
namespace OnlineStore.Application
{
// UserService.svc, WCF服务
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class UserService : IUserService
{
private readonly IUserService _userServiceImp;
public UserService()
{
_userServiceImp = ServiceLocator.Instance.GetService();
}
public IList CreateUsers(List userDtos)
{
try
{
return _userServiceImp.CreateUsers(userDtos);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public bool ValidateUser(string userName, string password)
{
try
{
return _userServiceImp.ValidateUser(userName, password);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public bool DisableUser(UserDto userDto)
{
try
{
return _userServiceImp.DisableUser(userDto);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public bool EnableUser(UserDto userDto)
{
try
{
return _userServiceImp.EnableUser(userDto);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void DeleteUsers(List userDtos)
{
try
{
_userServiceImp.DeleteUsers(userDtos);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList UpdateUsers(List userDataObjects)
{
try
{
return _userServiceImp.UpdateUsers(userDataObjects);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public UserDto GetUserByKey(Guid id)
{
try
{
return _userServiceImp.GetUserByKey(id);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public UserDto GetUserByEmail(string email)
{
try
{
return _userServiceImp.GetUserByEmail(email);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public UserDto GetUserByName(string userName)
{
try
{
return _userServiceImp.GetUserByName(userName);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList GetUsers()
{
try
{
return _userServiceImp.GetUsers();
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList GetRoles()
{
try
{
return _userServiceImp.GetRoles();
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public RoleDto GetRoleByKey(Guid id)
{
try
{
return _userServiceImp.GetRoleByKey(id);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList CreateRoles(List roleDataObjects)
{
try
{
return _userServiceImp.CreateRoles(roleDataObjects);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList UpdateRoles(List roleDataObjects)
{
try
{
return _userServiceImp.UpdateRoles(roleDataObjects);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void DeleteRoles(List roleList)
{
try
{
_userServiceImp.DeleteRoles(roleList);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void AssignRole(Guid userId, Guid roleId)
{
try
{
_userServiceImp.AssignRole(userId, roleId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public void UnassignRole(Guid userId)
{
try
{
_userServiceImp.UnassignRole(userId);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public RoleDto GetRoleByUserName(string userName)
{
try
{
return _userServiceImp.GetRoleByUserName(userName);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
public IList GetOrdersForUser(string userName)
{
try
{
return _userServiceImp.GetOrdersForUser(userName);
}
catch (Exception ex)
{
throw new FaultException(FaultData.CreateFromException(ex), FaultData.CreateFaultReason(ex));
}
}
}
}
================================================
FILE: OnlineStore.Application/Web.Debug.config
================================================
================================================
FILE: OnlineStore.Application/Web.Release.config
================================================
================================================
FILE: OnlineStore.Application/Web.config
================================================
================================================
FILE: OnlineStore.Application/packages.config
================================================
================================================
FILE: OnlineStore.Domain/DomainException.cs
================================================
using System;
using System.Runtime.Serialization;
namespace OnlineStore.Domain
{
public class DomainException : Exception
{
#region Ctor
public DomainException() : base()
{
}
public DomainException(string message) : base(message)
{
}
public DomainException(string message, Exception innerException) : base(message, innerException) { }
public DomainException(string format, params object[] args) : base(string.Format(format, args)) { }
protected DomainException(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Events/DomainEvent.cs
================================================
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using OnlineStore.Events;
using OnlineStore.Infrastructure;
namespace OnlineStore.Domain.Events
{
[SuppressMessage("ReSharper", "AccessToForEachVariableInClosure")]
public class DomainEvent : IDomainEvent
{
#region Private Fields
private readonly IEntity _source;
private Guid _id = Guid.NewGuid();
private DateTime _timeStamp = DateTime.UtcNow;
#endregion
#region Ctor
public DomainEvent()
{
}
public DomainEvent(IEntity source)
{
_source = source;
}
#endregion
#region IDomainEvent Members
public IEntity Source
{
get { return _source; }
}
public Guid Id
{
get { return _id; }
set { _id = value; }
}
public DateTime TimeStamp
{
get { return _timeStamp; }
set { _timeStamp = value; }
}
#endregion
#region Public Static Methods
public static void Handle(TDomainEvent domainEvent)
where TDomainEvent : class, IDomainEvent
{
// 找到对应的事件处理器来对事件进行处理
var handlers = ServiceLocator.Instance.ResolveAll>();
foreach (var handler in handlers)
{
if (handler.GetType().IsDefined(typeof(HandlesAsynchronouslyAttribute), false))
Task.Factory.StartNew(() => handler.Handle(domainEvent));
else
handler.Handle(domainEvent);
}
}
public static void Handle(TDomainEvent domainEvent, Action callback, TimeSpan? timeout = null)
where TDomainEvent : class, IDomainEvent
{
var handlers = ServiceLocator.Instance.ResolveAll>();
if (handlers != null && handlers.Any())
{
var tasks = new List();
try
{
foreach (var handler in handlers)
{
if (handler.GetType().IsDefined(typeof(HandlesAsynchronouslyAttribute), false))
{
tasks.Add(Task.Factory.StartNew(() => handler.Handle(domainEvent)));
}
else
handler.Handle(domainEvent);
}
if (tasks.Count > 0)
{
if (timeout == null)
Task.WaitAll(tasks.ToArray());
else
Task.WaitAll(tasks.ToArray(), timeout.Value);
}
callback(domainEvent, true, null);
}
catch (Exception ex)
{
callback(domainEvent, false, ex);
}
}
else
callback(domainEvent, false, null);
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Events/EventHandlers/OrderConfirmedEventHandler.cs
================================================
using OnlineStore.Domain.Model;
using OnlineStore.Events.Bus;
namespace OnlineStore.Domain.Events.EventHandlers
{
// 订单确认事件处理器
public class OrderConfirmedEventHandler : IDomainEventHandler
{
private readonly IEventBus _bus;
public OrderConfirmedEventHandler(IEventBus bus)
{
_bus = bus;
}
#region IDomainEventHandler Member
// 事件处理器只对事件源的状态进行更新,事件状态的持久化而是在EventBus中进行处理的。
public void Handle(OrderConfirmedEvent @event)
{
// 获得事件源对象
var order = @event.Source as Order;
// 更新事件源对象的属性
if (order == null) return;
order.DeliveredDate = @event.ConfirmedDate;
order.Status = OrderStatus.Delivered;
// 把事件推送到EventBus中进行进一步处理
_bus.Publish(@event);
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Events/EventHandlers/OrderDispatchedEventHandler.cs
================================================
using OnlineStore.Domain.Model;
using OnlineStore.Domain.Repositories;
using OnlineStore.Events.Bus;
namespace OnlineStore.Domain.Events.EventHandlers
{
// 发货事件处理器
public class OrderDispatchedEventHandler : IDomainEventHandler
{
private readonly IEventBus _bus;
public OrderDispatchedEventHandler(IEventBus bus)
{
_bus = bus;
}
public void Handle(OrderDispatchedEvent @event)
{
// 获得事件源对象
var order = @event.Source as Order;
// 更新事件源对象的属性
if (order == null) return;
order.DispatchedDate = @event.DispatchedDate;
order.Status = OrderStatus.Dispatched;
// 这里把领域事件认为是一种消息,推送到EventBus中进行进一步处理。
_bus.Publish(@event);
}
}
}
================================================
FILE: OnlineStore.Domain/Events/IDomainEvent.cs
================================================
using OnlineStore.Events;
namespace OnlineStore.Domain.Events
{
public interface IDomainEvent : IEvent
{
// 获取产生领域事件的事件源对象
IEntity Source { get; }
}
}
================================================
FILE: OnlineStore.Domain/Events/IDomainEventHandler.cs
================================================
using OnlineStore.Events;
namespace OnlineStore.Domain.Events
{
///
/// 领域事件处理器
///
public interface IDomainEventHandler : IEventHandler
where TDomainEvent :class, IDomainEvent
{
}
}
================================================
FILE: OnlineStore.Domain/Events/OrderConfirmedEvent.cs
================================================
using System;
namespace OnlineStore.Domain.Events
{
[Serializable]
public class OrderConfirmedEvent : DomainEvent
{
#region Ctor
public OrderConfirmedEvent() { }
public OrderConfirmedEvent(IEntity source) : base(source) { }
#endregion
#region Public Properties
///
/// 获取或设置订单确认的日期。
///
public DateTime ConfirmedDate { get; set; }
public string UserEmailAddress { get; set; }
public Guid OrderId { get; set; }
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Events/OrderDispatchedEvent.cs
================================================
using System;
namespace OnlineStore.Domain.Events
{
[Serializable]
public class OrderDispatchedEvent : DomainEvent
{
#region Ctor
public OrderDispatchedEvent() { }
public OrderDispatchedEvent(IEntity source) : base(source) { }
#endregion
#region Public Properties
///
/// 获取或设置订单发货的日期。
///
public DateTime DispatchedDate { get; set; }
public string UserEmailAddress { get; set; }
public Guid OrderId { get; set; }
#endregion
}
}
================================================
FILE: OnlineStore.Domain/IAggregateRoot.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.Domain
{
// 聚合根接口,继承于该接口的对象是外部唯一操作的对象
public interface IAggregateRoot : IEntity
{
}
}
================================================
FILE: OnlineStore.Domain/IEntity.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.Domain
{
// 领域实体接口
public interface IEntity
{
// 当前领域实体的全局唯一标识
Guid Id { get; }
}
}
================================================
FILE: OnlineStore.Domain/Model/Address.cs
================================================
namespace OnlineStore.Domain.Model
{
// 值对象
public class Address
{
#region Properties
// 国家
public string Country { get; set; }
//省份
public string State { get; set; }
// 市
public string City { get; set; }
public string Street { get; set; }
public string Zip { get; set; }
#endregion
#region Object Member
public override bool Equals(object obj)
{
if (obj == null)
return false;
if (ReferenceEquals(this, obj))
return true;
Address another = obj as Address;
if (another == null)
return false;
return this.Country.Equals(another.Country) &&
this.State.Equals(another.State) &&
this.City.Equals(another.City) &&
this.Street.Equals(another.Street) &&
this.Zip.Equals(another.Zip);
}
public override int GetHashCode()
{
return this.Country.GetHashCode() ^
this.State.GetHashCode() ^
this.City.GetHashCode() ^
this.Street.GetHashCode() ^
this.Zip.GetHashCode();
}
public override string ToString()
{
return string.Format("{0} {1}, {2}, {3}, {4}", Zip, Street, City, State, Country);
}
#endregion
#region Public Static Operator Overrides
public static bool operator ==(Address a, Address b)
{
if (a == null)
{
return b == null;
}
return a.Equals(b);
}
public static bool operator !=(Address a, Address b)
{
return !(a == b);
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Model/AggregateRoot.cs
================================================
using System;
namespace OnlineStore.Domain.Model
{
public abstract class AggregateRoot : IAggregateRoot
{
public Guid Id
{
get;
set;
}
#region Object Member
public override bool Equals(object obj)
{
if (obj == null)
return false;
if (ReferenceEquals(this, obj))
return true;
IAggregateRoot ar = obj as IAggregateRoot;
if (ar == null)
return false;
return this.Id == ar.Id;
}
public override int GetHashCode()
{
return this.Id.GetHashCode();
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Model/Category.cs
================================================
namespace OnlineStore.Domain.Model
{
// 类别类
public class Category : AggregateRoot
{
public string Name { get; set; }
public string Description { get; set; }
public override string ToString()
{
return this.Name;
}
}
}
================================================
FILE: OnlineStore.Domain/Model/Order.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using OnlineStore.Domain.Events;
namespace OnlineStore.Domain.Model
{
public class Order : AggregateRoot
{
private List _orderItems = new List();
#region Public Properties
// 获取或设置订单的状态
public OrderStatus Status { get; set; }
///
/// 获取或设置订单的创建日期
///
public DateTime CreatedDate { get; set; }
///
/// 获取或设置订单的发货日期
///
public DateTime? DispatchedDate { get; set; }
///
/// 获取或设置订单的派送日期
///
public DateTime? DeliveredDate { get; set; }
public virtual List OrderItems
{
get
{
return _orderItems;
}
set
{
_orderItems = value;
}
}
public virtual User User { get; set; }
public Address DeliveryAddress
{
get
{
return User.DeliveryAddress;
}
}
// 在严格的业务系统中,金额往往以Money模式实现。有关Money模式,请参见:http://martinfowler.com/eaaCatalog/money.html
public decimal Subtotal
{
get
{
return this.OrderItems.Sum(p => p.ItemAmout);
}
}
#endregion
#region Ctor
public Order()
{
CreatedDate = DateTime.Now;
Status = OrderStatus.Created;
}
#endregion
#region Public Methods
///
/// 当客户完成收货后,对销售订单进行确认。
///
public void Confirm()
{
// 处理领域事件
DomainEvent.Handle(new OrderConfirmedEvent(this) { ConfirmedDate = DateTime.Now, OrderId = this.Id, UserEmailAddress = this.User.Email });
}
///
/// 处理发货。
///
public void Dispatch()
{
// 处理领域事件
DomainEvent.Handle(new OrderDispatchedEvent(this) { DispatchedDate = DateTime.Now, OrderId = this.Id, UserEmailAddress = this.User.Email });
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Model/OrderItem.cs
================================================
using System;
namespace OnlineStore.Domain.Model
{
public class OrderItem : IEntity
{
#region IEnity Member
public Guid Id { get; set; }
#endregion
public int Quantity { get; set; }
public virtual Product Product { get; set; }
// 包含当前订单项的订单对象
public virtual Order Order { get; set; }
public decimal ItemAmout
{
get
{
return this.Product.UnitPrice * this.Quantity;
}
}
#region Object Member
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
return true;
if (obj == null)
return false;
OrderItem other = obj as OrderItem;
if ((object)other == null)
return false;
return this.Id == other.Id;
}
public override int GetHashCode()
{
return this.Id.GetHashCode();
}
#endregion
#region Public Static Operator Overrides
public static bool operator ==(OrderItem a, OrderItem b)
{
if ((object)a == null)
{
return (object)b == null;
}
return a.Equals(b);
}
public static bool operator !=(OrderItem a, OrderItem b)
{
return !(a == b);
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Model/OrderStatus.cs
================================================
namespace OnlineStore.Domain.Model
{
public enum OrderStatus
{
Created = 0, // 订单已被创建
Paid, // 订单已付款
Picked, // 订单已仓库拣货
Dispatched, // 已发货
Delivered // 已派送
}
}
================================================
FILE: OnlineStore.Domain/Model/Product.cs
================================================
namespace OnlineStore.Domain.Model
{
// 商品类
public class Product : AggregateRoot
{
public string Name { get; set; }
public string Description { get; set; }
public decimal UnitPrice { get; set; }
public string ImageUrl { get; set; }
public bool IsNew{ get; set; }
public override string ToString()
{
return Name;
}
}
}
================================================
FILE: OnlineStore.Domain/Model/ProductCategorization.cs
================================================
using System;
namespace OnlineStore.Domain.Model
{
public class ProductCategorization : AggregateRoot
{
public ProductCategorization()
{ }
public ProductCategorization(Guid productId, Guid categoryId)
{
this.CategoryId = categoryId;
this.ProductId = productId;
}
public Guid CategoryId { get; set; }
public Guid ProductId { get; set; }
public override string ToString()
{
return string.Format("CategoryID: {0}, ProductID: {1}", this.CategoryId, this.ProductId);
}
// 通过商品对象和分类对象来创建商品分类对象
public static ProductCategorization CreateCategorization(Product product, Category category)
{
return new ProductCategorization(product.Id, category.Id);
}
}
}
================================================
FILE: OnlineStore.Domain/Model/Role.cs
================================================
namespace OnlineStore.Domain.Model
{
public class Role : AggregateRoot
{
public string Name { get; set; }
public string Description { get; set; }
}
}
================================================
FILE: OnlineStore.Domain/Model/ShoppingCart.cs
================================================
namespace OnlineStore.Domain.Model
{
public class ShoppingCart : AggregateRoot
{
public User User { get; set; }
}
}
================================================
FILE: OnlineStore.Domain/Model/ShoppingCartItem.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.Domain.Model
{
public class ShoppingCartItem : AggregateRoot
{
public int Quantity { get; set; }
public virtual Product Product { get; set; }
public virtual ShoppingCart ShoopingCart { get; set; }
public decimal ItemAmount
{
get
{
return this.Product.UnitPrice * this.Quantity;
}
}
#region Public Methods
// 将当前的购物车中的项目转换为订单项
public OrderItem ConvertToOrderItem()
{
var orderItem = new OrderItem
{
Id = Guid.NewGuid(),
Product = this.Product,
Quantity = this.Quantity
};
return orderItem;
}
public void UpdateQuantity(int quantity)
{
this.Quantity = quantity;
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Model/User.cs
================================================
using System;
using System.Collections.Generic;
namespace OnlineStore.Domain.Model
{
// 用户聚合根
public class User : AggregateRoot
{
public string UserName { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public bool IsDisabled { get; set; }
public DateTime RegisteredDate { get; set; }
public DateTime? LastLogonDate { get; set; }
public string Contact { get; set; }
//用户的联系地址
public Address ContactAddress { get; set; }
//用户的发货地址
public Address DeliveryAddress { get; set; }
public IEnumerable Orders
{
get
{
IEnumerable result = null;
//DomainEvent.Handle(new GetUserOrdersEvent(this),
// (e, ret, exc) =>
// {
// result = e.Orders;
// });
return result;
}
}
public override string ToString()
{
return this.UserName;
}
#region Public Methods
public void Disable()
{
this.IsDisabled = true;
}
public void Enable()
{
this.IsDisabled = false;
}
// 为当前用户创建购物篮。
public ShoppingCart CreateShoppingCart()
{
var shoppingCart = new ShoppingCart { User = this };
return shoppingCart;
}
#endregion
}
}
================================================
FILE: OnlineStore.Domain/Model/UserRole.cs
================================================
using System;
namespace OnlineStore.Domain.Model
{
public class UserRole : AggregateRoot
{
public Guid UserId { get; set; }
public Guid RoleId { get; set; }
public static UserRole CreateUserRole(User user, Role role)
{
return new UserRole() { UserId = user.Id, RoleId = role.Id };
}
}
}
================================================
FILE: OnlineStore.Domain/OnlineStore.Domain.csproj
================================================
Debug
AnyCPU
{1AE7732F-2FAF-407E-89DD-BAD81C4132E0}
Library
Properties
OnlineStore.Domain
OnlineStore.Domain
v4.5
512
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
pdbonly
true
bin\Release\
TRACE
prompt
4
{f165abc2-f76a-4fd7-8675-833264855221}
OnlineStore.Events
{9dde33cc-cf3c-436e-8a5f-4e1f0f8b603e}
OnlineStore.Infrastructure
================================================
FILE: OnlineStore.Domain/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OnlineStore.Domain")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("OnlineStore.Domain")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2e3e41cc-5c75-45ad-aac8-23bf93d1abe2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: OnlineStore.Domain/Repositories/ICategoryRepository.cs
================================================
using System.Collections;
using System.Collections.Generic;
using OnlineStore.Domain.Model;
namespace OnlineStore.Domain.Repositories
{
public interface ICategoryRepository : IRepository
{
}
}
================================================
FILE: OnlineStore.Domain/Repositories/IOrderRepository.cs
================================================
using OnlineStore.Domain.Model;
namespace OnlineStore.Domain.Repositories
{
// 订单仓储接口
public interface IOrderRepository : IRepository
{
}
}
================================================
FILE: OnlineStore.Domain/Repositories/IProductCategorizationRepository.cs
================================================
using System.Collections.Generic;
using OnlineStore.Domain.Model;
using OnlineStore.Infrastructure;
namespace OnlineStore.Domain.Repositories
{
public interface IProductCategorizationRepository : IRepository
{
// 获取指定分类下的所有商品信息
IEnumerable GetProductsForCategory(Category category);
///
/// 以分页的方式,获取指定分类下的所有商品信息
///
/// 指定的商品分类
/// 所请求的分页页码
/// 所请求的页大小
/// 指定分类下的某页的商品信息
PagedResult GetProductsForCategoryWithPagination(Category category, int pageNumber, int pageSize);
///
/// 获取商品所属的商品分类。
///
/// 商品信息。
/// 商品分类。
Category GetCategoryForProduct(Product product);
}
}
================================================
FILE: OnlineStore.Domain/Repositories/IProductRepository.cs
================================================
using OnlineStore.Domain.Model;
using System;
using System.Collections.Generic;
namespace OnlineStore.Domain.Repositories
{
public interface IProductRepository : IRepository
{
IEnumerable GetNewProducts(int count = 0);
}
}
================================================
FILE: OnlineStore.Domain/Repositories/IRepository.cs
================================================
using OnlineStore.Domain.Specifications;
using OnlineStore.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.Domain.Repositories
{
// 仓储接口
public interface IRepository
where TAggregateRoot :class, IAggregateRoot
{
#region Methods
void Add(TAggregateRoot aggregateRoot);
// 根据聚合根的ID值,从仓储中读取聚合根
TAggregateRoot GetByKey(Guid key);
TAggregateRoot GetBySpecification(ISpecification spec);
TAggregateRoot GetByExpression(Expression> expression);
// 读取所有聚合根。
IEnumerable GetAll();
// 以指定的排序字段和排序方式,从仓储中读取所有聚合根。
IEnumerable GetAll(Expression> sortPredicate, SortOrder sortOrder);
// 根据指定的规约获取聚合根
IEnumerable GetAll(ISpecification specification);
// 根据指定的规约,以指定的排序字段和排序方式,从仓储中读取聚合根
IEnumerable GetAll(ISpecification specification, Expression> sortPredicate, SortOrder sortOrder);
// 返回一个值,该值表示符合指定规约条件的聚合根是否存在。
bool Exists(ISpecification specification);
void Remove(TAggregateRoot aggregateRoot);
void Update(TAggregateRoot aggregateRoot);
#region 分页支持
#endregion
PagedResult GetAll(Expression> sortPredicate,
SortOrder sortOrder, int pageNumber, int pageSize);
PagedResult GetAll(
ISpecification specification,
Expression