├── Categories.md ├── Customers.md ├── LICENSE ├── Nop.Plugin.Api.Tests ├── ControllersTests │ ├── Categories │ │ ├── CategoriesControllerTests_CreateCategory.cs │ │ ├── CategoriesControllerTests_GetCategories.cs │ │ ├── CategoriesControllerTests_GetCategoriesById.cs │ │ └── CategoriesControllerTests_GetCategoriesCount.cs │ ├── Customers │ │ ├── CustomersControllerTests_GetCustomerById.cs │ │ ├── CustomersControllerTests_GetCustomers.cs │ │ ├── CustomersControllerTests_GetCustomersCount.cs │ │ └── CustomersControllerTests_Search.cs │ ├── Orders │ │ ├── OrdersControllerTests_GetOrderById.cs │ │ ├── OrdersControllerTests_GetOrders.cs │ │ ├── OrdersControllerTests_GetOrdersByCustomerId.cs │ │ └── OrdersControllerTests_GetOrdersCount.cs │ ├── ProductCategoryMappings │ │ ├── ProductCategoryMappingsControllerTests_GetMappingById.cs │ │ ├── ProductCategoryMappingsControllerTests_GetMappings.cs │ │ └── ProductCategoryMappingsControllerTests_GetMappingsCount.cs │ ├── Products │ │ ├── ProductsControllerTests_GetProductById.cs │ │ ├── ProductsControllerTests_GetProducts.cs │ │ └── ProductsControllerTests_GetProductsCount.cs │ └── ShoppingCartItems │ │ ├── ShoppingCartItemsControllerTests_GetShoppingCartItems.cs │ │ └── ShoppingCartItemsControllerTests_GetShoppingCartItemsByCustomerId.cs ├── ConvertersTests │ ├── ApiTypeConverter │ │ ├── ApiTypeConverterTests_ToDateTimeNullable.cs │ │ ├── ApiTypeConverterTests_ToEnumNullable.cs │ │ ├── ApiTypeConverterTests_ToInt.cs │ │ ├── ApiTypeConverterTests_ToIntNullable.cs │ │ ├── ApiTypeConverterTests_ToListOfInts.cs │ │ └── ApiTypeConverterTests_ToStatus.cs │ └── ObjectConverter │ │ ├── DummyObjects │ │ └── SomeTestingObject.cs │ │ └── ObjectConverterTests_ToObject.cs ├── Helpers │ └── ActionResultExecutor.cs ├── MappingTests │ └── CategoryMappings_Merge.cs ├── ModelBinderTests │ ├── DummyObjects │ │ └── DummyModel.cs │ ├── JsonModelBinderTests_BindModel.cs │ └── ParametersModelBinderTests_BindModel.cs ├── Nop.Plugin.Api.Tests.csproj ├── SerializersTests │ ├── DummyObjects │ │ ├── DummyObjectWithComplexTypes.cs │ │ ├── DummyObjectWithSimpleTypes.cs │ │ ├── SerializableDummyObjectWithComplexTypes.cs │ │ └── SerializableDummyObjectWithSimpleTypes.cs │ └── JsonFieldsSerializerTests_Serialize.cs ├── ServicesTests │ ├── Categories │ │ ├── GetCategories │ │ │ ├── CategoriesApiServiceTests_GetCategories_ProductIdParameter.cs │ │ │ ├── CategoriesApiServiceTests_GetCategories_SinceIdParameter.cs │ │ │ ├── CategoryApiServiceTests_GetCategories_CreatedParameters.cs │ │ │ ├── CategoryApiServiceTests_GetCategories_DefaultParameters.cs │ │ │ ├── CategoryApiServiceTests_GetCategories_IdsParameter.cs │ │ │ ├── CategoryApiServiceTests_GetCategories_LimitParameter.cs │ │ │ ├── CategoryApiServiceTests_GetCategories_PageParameter.cs │ │ │ ├── CategoryApiServiceTests_GetCategories_PublishedStatusParameter.cs │ │ │ └── CategoryApiServiceTests_GetCategories_UpdatedParameters.cs │ │ ├── GetCategoriesCount │ │ │ ├── CategoryApiServiceTests_GetCategoriesCount_CreatedParameters.cs │ │ │ ├── CategoryApiServiceTests_GetCategoriesCount_DefaultParameters.cs │ │ │ ├── CategoryApiServiceTests_GetCategoriesCount_ProductIdParameter.cs │ │ │ ├── CategoryApiServiceTests_GetCategoriesCount_PublishedStatusParameter.cs │ │ │ └── CategoryApiServiceTests_GetCategoriesCount_UpdatedParameters.cs │ │ └── GetCategoryById │ │ │ └── CategoryApiServiceTests_GetCategoryById.cs │ ├── CountryApiServiceTests.cs │ ├── Customers │ │ └── CustomerApiServiceTests.cs │ ├── Orders │ │ ├── GetOrderById │ │ │ └── OrderApiServiceTests_GetOrderById.cs │ │ ├── GetOrders │ │ │ ├── OrderApiServiceTests_GetOrders_CreatedParameters.cs │ │ │ ├── OrderApiServiceTests_GetOrders_CustomerIdParameter.cs │ │ │ ├── OrderApiServiceTests_GetOrders_DefaultParameters.cs │ │ │ ├── OrderApiServiceTests_GetOrders_IdsParameter.cs │ │ │ ├── OrderApiServiceTests_GetOrders_LimitParameter.cs │ │ │ ├── OrderApiServiceTests_GetOrders_PageParameter.cs │ │ │ ├── OrderApiServiceTests_GetOrders_SinceIdParameter.cs │ │ │ └── OrderApiServiceTests_GetOrders_StatusesParameters.cs │ │ ├── GetOrdersByCustomerId │ │ │ └── OrderApiServiceTests_GetOrdersByCustomerId.cs │ │ └── GetOrdersCount │ │ │ ├── OrderApiServiceTests_GetOrdersCount_CreatedParameters.cs │ │ │ ├── OrderApiServiceTests_GetOrdersCount_CustomerIdParameter.cs │ │ │ ├── OrderApiServiceTests_GetOrdersCount_DefaultParameters.cs │ │ │ └── OrderApiServiceTests_GetOrdersCount_StatusesParameters.cs │ ├── ProductCategoryMappings │ │ ├── GetMappingById │ │ │ └── ProductCategoryMappingsApiServiceTests_GetById.cs │ │ ├── GetMappings │ │ │ ├── ProductCategoryMappingsApiServiceTests_GetMappings_CategoryIdParameter.cs │ │ │ ├── ProductCategoryMappingsApiServiceTests_GetMappings_DefaultParameters.cs │ │ │ ├── ProductCategoryMappingsApiServiceTests_GetMappings_LimitParameter.cs │ │ │ ├── ProductCategoryMappingsApiServiceTests_GetMappings_PageParameter.cs │ │ │ ├── ProductCategoryMappingsApiServiceTests_GetMappings_ProductIdParameter.cs │ │ │ └── ProductCategoryMappingsApiServiceTests_GetMappings_SinceIdParameter.cs │ │ └── GetMappingsCount │ │ │ └── ProductCategoryMappingsApiServiceTests_GetMappingsCount.cs │ ├── Products │ │ ├── GetProductById │ │ │ └── ProductApiServiceTests_GetProductById.cs │ │ ├── GetProducts │ │ │ ├── ProductApiServiceTests_GetProducts_CategoryIdParameter.cs │ │ │ ├── ProductApiServiceTests_GetProducts_CreatedParameters.cs │ │ │ ├── ProductApiServiceTests_GetProducts_DefaultParameters.cs │ │ │ ├── ProductApiServiceTests_GetProducts_IdsParameter.cs │ │ │ ├── ProductApiServiceTests_GetProducts_LimitParameter.cs │ │ │ ├── ProductApiServiceTests_GetProducts_PageParameter.cs │ │ │ ├── ProductApiServiceTests_GetProducts_PublishedStatusParameter.cs │ │ │ ├── ProductApiServiceTests_GetProducts_SinceIdParameter.cs │ │ │ ├── ProductApiServiceTests_GetProducts_UpdatedParameters.cs │ │ │ └── ProductApiServiceTests_GetProducts_VendorNameParameter.cs │ │ └── GetProductsCount │ │ │ ├── ProductApiServiceTests_GetProductsCount_CategoryIdParameter.cs │ │ │ ├── ProductApiServiceTests_GetProductsCount_CreatedParameters.cs │ │ │ ├── ProductApiServiceTests_GetProductsCount_DefaultParameters.cs │ │ │ ├── ProductApiServiceTests_GetProductsCount_PublishedStatusParameter.cs │ │ │ ├── ProductApiServiceTests_GetProductsCount_UpdatedParameters.cs │ │ │ └── ProductApiServiceTests_GetProductsCount_VendorNameParameter.cs │ ├── ShoppingCartItems │ │ └── GetShoppingCartItems │ │ │ ├── ShoppingCartItemsTests_GetShoppingCartItems_CreatedParameters.cs │ │ │ ├── ShoppingCartItemsTests_GetShoppingCartItems_CustomerIdParameter.cs │ │ │ ├── ShoppingCartItemsTests_GetShoppingCartItems_LimitParameter.cs │ │ │ ├── ShoppingCartItemsTests_GetShoppingCartItems_PageParameters.cs │ │ │ └── ShoppingCartItemsTests_GetShoppingCartItems_UpdatedParameters.cs │ └── StateProvinceApiServiceTests.cs ├── SetUp.cs ├── ValidatorTests │ ├── FieldsValidatorTests_GetValidFields.cs │ └── TypeValidatorTests_IsValid.cs ├── app.config └── packages.config ├── Nop.Plugin.Api ├── Areas │ └── Admin │ │ ├── Controllers │ │ └── ApiAdminController.cs │ │ ├── Models │ │ └── ConfigurationModel.cs │ │ └── Views │ │ ├── ApiAdmin │ │ └── Settings.cshtml │ │ └── _ViewImports.cshtml ├── Attributes │ ├── BaseAttributeInvoker.cs │ ├── DoNotMap.cs │ ├── GetRequestsErrorInterceptorActionFilter.cs │ ├── ImageAttribute.cs │ ├── ImageCollectionAttribute.cs │ ├── ProductTypeValidationAttribute.cs │ └── ValidateVendor.cs ├── Authorization │ ├── Policies │ │ ├── ActiveApiPluginAuthorizationPolicy.cs │ │ ├── CustomerRoleAuthorizationPolicy.cs │ │ └── ValidSchemeAuthorizationPolicy.cs │ └── Requirements │ │ ├── ActiveApiPluginRequirement.cs │ │ ├── AuthorizationSchemeRequirement.cs │ │ └── CustomerRoleRequirement.cs ├── AutoMapper │ ├── ApiMapperConfiguration.cs │ └── AutoMapperApiConfiguration.cs ├── Configuration │ ├── ApiConfiguration.cs │ └── ApplicationPartsLogger.cs ├── Controllers │ ├── BaseApiController.cs │ ├── CategoriesController.cs │ ├── CustomerRolesController.cs │ ├── CustomersController.cs │ ├── LanguagesController.cs │ ├── ManufacturersController.cs │ ├── NewsLetterSubscriptionController.cs │ ├── OrderItemsController.cs │ ├── OrdersController.cs │ ├── ProductAttributesController.cs │ ├── ProductCategoryMappingsController.cs │ ├── ProductManufacturerMappingsController.cs │ ├── ProductSpecificationAttributesController.cs │ ├── ProductsController.cs │ ├── ShoppingCartItemsController.cs │ ├── SpecificationAttributesController.cs │ ├── StoreController.cs │ └── TokenController.cs ├── Converters │ ├── ApiTypeConverter.cs │ ├── IApiTypeConverter.cs │ ├── IObjectConverter.cs │ └── ObjectConverter.cs ├── DTOs │ ├── AddressDto.cs │ ├── Base │ │ └── BaseDto.cs │ ├── Categories │ │ ├── CategoriesCountRootObject.cs │ │ ├── CategoriesRootObject.cs │ │ └── CategoryDto.cs │ ├── CustomerRoles │ │ ├── CustomerRoleDto.cs │ │ └── CustomerRolesRootObject.cs │ ├── Customers │ │ ├── BaseCustomerDto.cs │ │ ├── CustomerAttributeMappingDto.cs │ │ ├── CustomerDto.cs │ │ ├── CustomerForShoppingCartItemDto.cs │ │ ├── CustomersCountRootObject.cs │ │ ├── CustomersRootObject.cs │ │ └── OrderCustomerDto.cs │ ├── Errors │ │ └── ErrorsRootObject.cs │ ├── ISerializableObject.cs │ ├── Images │ │ ├── ImageDto.cs │ │ └── ImageMappingDto.cs │ ├── Languages │ │ ├── LanguageDto.cs │ │ ├── LanguagesRootObject.cs │ │ └── LocalizedNameDto.cs │ ├── Manufacturers │ │ ├── DiscountManufacturerMappingDto.cs │ │ ├── ManufacturerDto.cs │ │ ├── ManufacturersCountRootObject.cs │ │ └── ManufacturersRootObject.cs │ ├── NewsLetterSubscriptions │ │ ├── NewsLetterSubscriptionDto.cs │ │ └── NewsLetterSubscriptionsRootObject.cs │ ├── OrderItems │ │ ├── OrderItemDto.cs │ │ ├── OrderItemsCountRootObject.cs │ │ └── OrderItemsRootObject.cs │ ├── Orders │ │ ├── OrderDto.cs │ │ ├── OrdersCountRootObject.cs │ │ ├── OrdersRootObject.cs │ │ └── SingleOrderRootObject.cs │ ├── ProductAttributes │ │ ├── ProductAttributeDto.cs │ │ ├── ProductAttributesCountRootObject.cs │ │ └── ProductAttributesRootObjectDto.cs │ ├── ProductCategoryMappings │ │ ├── ProductCategoryMappingsCountRootObject.cs │ │ ├── ProductCategoryMappingsDto.cs │ │ └── ProductCategoryMappingsRootObject.cs │ ├── ProductItemAttributeDto.cs │ ├── ProductManufacturerMappings │ │ ├── ProductManufacturerMappingsCountRootObject.cs │ │ ├── ProductManufacturerMappingsDto.cs │ │ └── ProductManufacturerMappingsRootObject.cs │ ├── Products │ │ ├── ProductAttributeCombinationDto.cs │ │ ├── ProductAttributeMappingDto.cs │ │ ├── ProductAttributeValueDto.cs │ │ ├── ProductDto.cs │ │ ├── ProductsCountRootObject.cs │ │ └── ProductsRootObjectDto.cs │ ├── ShoppingCarts │ │ ├── ShoppingCartItemDto.cs │ │ └── ShoppingCartItemsRootObject.cs │ ├── SpecificationAttributes │ │ ├── ProductSpecificationAttributeDto.cs │ │ ├── ProductSpecificationAttributesCountRootObject.cs │ │ ├── ProductSpecificationAttributesRootObjectDto.cs │ │ ├── SpecificationAttributeDto.cs │ │ ├── SpecificationAttributeOptionDto.cs │ │ ├── SpecificationAttributesCountRootObject.cs │ │ └── SpecificationAttributesRootObjectDto.cs │ └── Stores │ │ ├── StoreDto.cs │ │ └── StoresRootObject.cs ├── DataStructures │ └── ApiList.cs ├── Delta │ └── Delta.cs ├── Domain │ └── ApiSettings.cs ├── Factories │ ├── AddressFactory.cs │ ├── CategoryFactory.cs │ ├── CustomerFactory.cs │ ├── IFactory.cs │ ├── ManufacturerFactory.cs │ ├── OrderFactory.cs │ ├── ProductFactory.cs │ └── ShoppingCartItemFactory.cs ├── Helpers │ ├── CustomerRolesHelper.cs │ ├── DTOHelper.cs │ ├── ICustomerRolesHelper.cs │ ├── IDTOHelper.cs │ ├── IJsonHelper.cs │ ├── IMappingHelper.cs │ ├── JTokenHelper.cs │ ├── JsonHelper.cs │ ├── MappingHelper.cs │ └── ReflectionHelper.cs ├── Infrastructure │ ├── ApiPlugin.cs │ ├── ApiStartup.cs │ ├── Constants.cs │ └── DependencyRegister.cs ├── JSON │ ├── ActionResults │ │ ├── ErrorActionResult.cs │ │ └── RawJsonActionResult.cs │ └── Serializers │ │ ├── IJsonFieldsSerializer.cs │ │ └── JsonFieldsSerializer.cs ├── MappingExtensions │ ├── AddressDtoMappings.cs │ ├── BaseMapping.cs │ ├── CategoryDtoMappings.cs │ ├── ConfigurationMappings.cs │ ├── CustomerDtoMappings.cs │ ├── CustomerRoleDtoMappings.cs │ ├── LanguageDtoMappings.cs │ ├── ManufacturerDtoMappings.cs │ ├── NewsLetterSubscriptoonDtoMappings.cs │ ├── OrderDtoMappings.cs │ ├── OrderItemDtoMappings.cs │ ├── ProductAttributeCombinationDtoMappings.cs │ ├── ProductAttributeDtoMappings.cs │ ├── ProductCategoryMappingDtoMappings.cs │ ├── ProductDtoMappings.cs │ ├── ProductManufacturerMappingDtoMappings.cs │ ├── ShoppingCartItemDtoMappings.cs │ ├── SpecificationAttributeDtoMapping.cs │ └── StoreDtoMappings.cs ├── Maps │ ├── IJsonPropertyMap.cs │ └── JsonPropertyMap.cs ├── ModelBinders │ ├── JsonModelBinder.cs │ └── ParametersModelBinder.cs ├── Models │ ├── Authentication │ │ ├── TokenRequest.cs │ │ └── TokenResponse.cs │ ├── CategoriesParameters │ │ ├── BaseCategoriesParametersModel.cs │ │ ├── CategoriesCountParametersModel.cs │ │ └── CategoriesParametersModel.cs │ ├── CustomersParameters │ │ ├── CustomersParametersModel.cs │ │ └── CustomersSearchParametersModel.cs │ ├── DefaultWebApiErrorsModel.cs │ ├── ManufacturersParameters │ │ ├── BaseManufacturersParametersModel.cs │ │ ├── ManufacturersCountParametersModel.cs │ │ └── ManufacturersParametersModel.cs │ ├── NewsLetterSubscriptionsParameters │ │ └── NewsLetterSubscriptionsParametersModel.cs │ ├── OrderItemsParameters │ │ └── OrderItemsParametersModel.cs │ ├── OrdersParameters │ │ ├── BaseOrdersParametersModel.cs │ │ ├── OrdersCountParametersModel.cs │ │ └── OrdersParametersModel.cs │ ├── ProductAttributesParameters │ │ └── ProductAttributesParametersModel.cs │ ├── ProductCategoryMappingsParameters │ │ ├── BaseCategoryMappingsParametersModel.cs │ │ ├── ProductCategoryMappingsCountParametersModel.cs │ │ └── ProductCategoryMappingsParametersModel.cs │ ├── ProductManufacturerMappingsParameters │ │ ├── BaseManufacturerMappingsParametersModel.cs │ │ ├── ProductManufacturerMappingsCountParametersModel.cs │ │ └── ProductManufacturerMappingsParametersModel.cs │ ├── ProductSpecificationAttributesParameters │ │ ├── ProductSpecificationAttributesCountParametersModel.cs │ │ └── ProductSpecificationAttributesParametersModel.cs │ ├── ProductsParameters │ │ ├── BaseProductsParametersModel.cs │ │ ├── ProductsCountParametersModel.cs │ │ └── ProductsParametersModel.cs │ ├── ShoppingCartsParameters │ │ ├── BaseShoppingCartItemsParametersModel.cs │ │ ├── ShoppingCartItemsForCustomerParametersModel.cs │ │ └── ShoppingCartItemsParametersModel.cs │ └── SpecificationAttributesParameters │ │ ├── SpecificationAttributesCountParametersModel.cs │ │ └── SpecificationAttributesParametersModel.cs ├── Nop.Plugin.Api.csproj ├── Services │ ├── CategoryApiService.cs │ ├── CustomerApiService.cs │ ├── ICategoryApiService.cs │ ├── ICustomerApiService.cs │ ├── IManufacturerApiService.cs │ ├── INewsLetterSubscriptionApiService.cs │ ├── IOrderApiService.cs │ ├── IOrderItemApiService.cs │ ├── IProductApiService.cs │ ├── IProductAttributeConverter.cs │ ├── IProductAttributesApiService.cs │ ├── IProductCategoryMappingsApiService.cs │ ├── IProductManufacturerMappingsApiService.cs │ ├── IProductPictureService.cs │ ├── IShoppingCartItemApiService.cs │ ├── ISpecificationAttributeApiService.cs │ ├── ManufacturerApiService.cs │ ├── NewsLetterSubscriptionApiService.cs │ ├── OrderApiService.cs │ ├── OrderItemApiService.cs │ ├── ProductApiService.cs │ ├── ProductAttributeConverter.cs │ ├── ProductAttributesApiService.cs │ ├── ProductCategoryMappingsApiService.cs │ ├── ProductManufacturerMappingsApiService.cs │ ├── ProductPictureService.cs │ ├── ShoppingCartItemApiService.cs │ └── SpecificationAttributesApiService.cs ├── Validators │ ├── AddressDtoValidator.cs │ ├── BaseDtoValidator.cs │ ├── CategoryDtoValidator.cs │ ├── CustomerDtoValidator.cs │ ├── FieldsValidator.cs │ ├── IFieldsValidator.cs │ ├── ManufacturerDtoValidator.cs │ ├── OrderDtoValidator.cs │ ├── OrderItemDtoValidator.cs │ ├── ProductAttributeCombinationDtoValidator.cs │ ├── ProductAttributeDtoValidator.cs │ ├── ProductCategoryMappingDtoValidator.cs │ ├── ProductDtoValidator.cs │ ├── ProductManufacturerMappingDtoValidator.cs │ ├── ProductSpecificationAttributeDtoValidator.cs │ ├── ShoppingCartItemDtoValidator.cs │ ├── SpecificationAttributeDtoValidator.cs │ ├── SpecificationAttributeOptionDtoValidator.cs │ └── TypeValidator.cs ├── logo.jpg └── plugin.json ├── OrderItems.md ├── Orders.md ├── ProductCategoryMappings.md ├── Products.md ├── README.md ├── ShoppingCartItems.md ├── WebHooks.md └── uploadedItems.json /Categories.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Nop-Templates.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ControllersTests/Categories/CategoriesControllerTests_CreateCategory.cs: -------------------------------------------------------------------------------- 1 | //using System.Collections.Generic; 2 | //using AutoMock; 3 | //using Nop.Plugin.Api.Controllers; 4 | //using NUnit.Framework; 5 | 6 | //namespace Nop.Plugin.Api.Tests.ControllersTests.Categories 7 | //{ 8 | // using Microsoft.AspNetCore.Mvc; 9 | 10 | // [TestFixture] 11 | // public class CategoriesControllerTests_CreateCategory 12 | // { 13 | // [Test] 14 | // public void WhenCategoryRootParameterIsNull_ShouldReturnBadRequest() 15 | // { 16 | // // Arrange 17 | // var autoMocker = new RhinoAutoMocker(); 18 | 19 | // // Act 20 | // IActionResult result = autoMocker.ClassUnderTest.CreateCategory(null); 21 | 22 | // // Assert 23 | // Assert.IsInstanceOf(result); 24 | // } 25 | 26 | // [Test] 27 | // public void WhenCategoryRootParameterIsEmpty_ShouldReturnBadRequest() 28 | // { 29 | // // Arrange 30 | // var autoMocker = new RhinoAutoMocker(); 31 | 32 | // // Act 33 | // IActionResult result = autoMocker.ClassUnderTest.CreateCategory(new Dictionary()); 34 | 35 | // // Assert 36 | // Assert.IsInstanceOf(result); 37 | // } 38 | 39 | // [Test] 40 | // public void WhenCategoryRootParameterDoesNotContainCategoryObjectOnRootLevel_ShouldReturnBadRequest() 41 | // { 42 | // // Arrange 43 | // var autoMocker = new RhinoAutoMocker(); 44 | 45 | // // Act 46 | // IActionResult result = autoMocker.ClassUnderTest.CreateCategory(new Dictionary() 47 | // { 48 | // { 49 | // "this should be category", 50 | // "collection of property-values" 51 | // } 52 | // }); 53 | 54 | // // Assert 55 | // Assert.IsInstanceOf(result); 56 | // } 57 | 58 | // // could not test anything with valid object because of the static extension methods that we are required to use when creating a new category 59 | // // and the limitation of Rhino Mocks. 60 | // } 61 | //} -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ControllersTests/Orders/OrdersControllerTests_GetOrdersByCustomerId.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AutoMock; 3 | using Nop.Core.Domain.Orders; 4 | using Nop.Plugin.Api.Controllers; 5 | using Nop.Plugin.Api.Services; 6 | using NUnit.Framework; 7 | using Rhino.Mocks; 8 | 9 | namespace Nop.Plugin.Api.Tests.ControllersTests.Orders 10 | { 11 | [TestFixture] 12 | public class OrdersControllerTests_GetOrdersByCustomerId 13 | { 14 | [Test] 15 | [TestCase(-5)] 16 | [TestCase(0)] 17 | [TestCase(10)] 18 | [TestCase(int.MaxValue)] 19 | public void WhenCustomerIdIsPassed_ShouldCallTheServiceWithThePassedParameters(int customerId) 20 | { 21 | // Arange 22 | var autoMocker = new RhinoAutoMocker(); 23 | 24 | autoMocker.Get().Expect(x => x.GetOrdersByCustomerId(customerId)).Return(new List()); 25 | 26 | // Act 27 | autoMocker.ClassUnderTest.GetOrdersByCustomerId(customerId); 28 | 29 | // Assert 30 | autoMocker.Get().VerifyAllExpectations(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ConvertersTests/ApiTypeConverter/ApiTypeConverterTests_ToInt.cs: -------------------------------------------------------------------------------- 1 | using Nop.Plugin.Api.Converters; 2 | using NUnit.Framework; 3 | 4 | namespace Nop.Plugin.Api.Tests.ConvertersTests.ApiTypeConverter 5 | { 6 | [TestFixture] 7 | public class ApiTypeConverterTests_ToInt 8 | { 9 | private IApiTypeConverter _apiTypeConverter; 10 | 11 | [SetUp] 12 | public void SetUp() 13 | { 14 | _apiTypeConverter = new Converters.ApiTypeConverter(); 15 | } 16 | 17 | [Test] 18 | [TestCase("3ed")] 19 | [TestCase("sd4")] 20 | [TestCase("675435345345345345345345343456546")] 21 | [TestCase("-675435345345345345345345343456546")] 22 | [TestCase("$%%^%^$#^&&%#)__(^&")] 23 | [TestCase("2015-02-12")] 24 | [TestCase("12:45")] 25 | public void WhenInvalidIntPassed_ShouldReturnZero(string invalidInt) 26 | { 27 | //Arange 28 | 29 | //Act 30 | int result = _apiTypeConverter.ToInt(invalidInt); 31 | 32 | //Assert 33 | Assert.AreEqual(0, result); 34 | } 35 | 36 | [Test] 37 | [TestCase("")] 38 | [TestCase(null)] 39 | public void WhenNullOrEmptyStringPassed_ShouldReturnZero(string nullOrEmpty) 40 | { 41 | //Arange 42 | 43 | //Act 44 | int result = _apiTypeConverter.ToInt(nullOrEmpty); 45 | 46 | //Assert 47 | Assert.AreEqual(0, result); 48 | } 49 | 50 | [Test] 51 | [TestCase("3")] 52 | [TestCase("234234")] 53 | [TestCase("0")] 54 | [TestCase("-44")] 55 | [TestCase("000000005")] 56 | public void WhenValidIntPassed_ShouldReturnThatInt(string validInt) 57 | { 58 | //Arange 59 | int valid = int.Parse(validInt); 60 | 61 | //Act 62 | int result = _apiTypeConverter.ToInt(validInt); 63 | 64 | //Assert 65 | Assert.AreEqual(valid, result); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ConvertersTests/ApiTypeConverter/ApiTypeConverterTests_ToIntNullable.cs: -------------------------------------------------------------------------------- 1 | using Nop.Plugin.Api.Converters; 2 | using NUnit.Framework; 3 | 4 | namespace Nop.Plugin.Api.Tests.ConvertersTests.ApiTypeConverter 5 | { 6 | [TestFixture] 7 | public class ApiTypeConverterTests_ToIntNullable 8 | { 9 | private IApiTypeConverter _apiTypeConverter; 10 | 11 | [SetUp] 12 | public void SetUp() 13 | { 14 | _apiTypeConverter = new Converters.ApiTypeConverter(); 15 | } 16 | 17 | [Test] 18 | [TestCase("3ed")] 19 | [TestCase("sd4")] 20 | [TestCase("675435345345345345345345343456546")] 21 | [TestCase("-675435345345345345345345343456546")] 22 | [TestCase("$%%^%^$#^&&%#)__(^&")] 23 | [TestCase("2015-02-12")] 24 | [TestCase("12:45")] 25 | public void WhenInvalidIntPassed_ShouldReturnNull(string invalidInt) 26 | { 27 | //Arange 28 | 29 | //Act 30 | int? result = _apiTypeConverter.ToIntNullable(invalidInt); 31 | 32 | //Assert 33 | Assert.IsNull(result); 34 | } 35 | 36 | [Test] 37 | [TestCase("")] 38 | [TestCase(null)] 39 | public void WhenNullOrEmptyStringPassed_ShouldReturnNull(string nullOrEmpty) 40 | { 41 | //Arange 42 | 43 | //Act 44 | int? result = _apiTypeConverter.ToIntNullable(nullOrEmpty); 45 | 46 | //Assert 47 | Assert.IsNull(result); 48 | } 49 | 50 | [Test] 51 | [TestCase("3")] 52 | [TestCase("234234")] 53 | [TestCase("0")] 54 | [TestCase("-44")] 55 | [TestCase("000000005")] 56 | public void WhenValidIntPassed_ShouldReturnThatInt(string validInt) 57 | { 58 | //Arange 59 | int valid = int.Parse(validInt); 60 | 61 | //Act 62 | int? result = _apiTypeConverter.ToIntNullable(validInt); 63 | 64 | //Assert 65 | Assert.AreEqual(valid, result); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ConvertersTests/ApiTypeConverter/ApiTypeConverterTests_ToStatus.cs: -------------------------------------------------------------------------------- 1 | using Nop.Plugin.Api.Converters; 2 | using NUnit.Framework; 3 | 4 | namespace Nop.Plugin.Api.Tests.ConvertersTests.ApiTypeConverter 5 | { 6 | [TestFixture] 7 | public class ApiTypeConverterTests_ToStatus 8 | { 9 | private IApiTypeConverter _apiTypeConverter; 10 | 11 | [SetUp] 12 | public void SetUp() 13 | { 14 | _apiTypeConverter = new Converters.ApiTypeConverter(); 15 | } 16 | 17 | [Test] 18 | [TestCase("invalid status")] 19 | [TestCase("publicshed")] 20 | [TestCase("un-published")] 21 | [TestCase("322345")] 22 | [TestCase("%^)@*%&*@_!+=")] 23 | [TestCase("1")] 24 | public void WhenInvalidStatusPassed_ShouldReturnNull(string invalidStatus) 25 | { 26 | //Arange 27 | 28 | //Act 29 | bool? result = _apiTypeConverter.ToStatus(invalidStatus); 30 | 31 | //Assert 32 | Assert.IsNull(result); 33 | } 34 | 35 | [Test] 36 | [TestCase("")] 37 | [TestCase(null)] 38 | public void WhenNullOrEmptyStringPassed_ShouldReturnNull(string nullOrEmpty) 39 | { 40 | //Arange 41 | 42 | //Act 43 | bool? result = _apiTypeConverter.ToStatus(nullOrEmpty); 44 | 45 | //Assert 46 | Assert.IsNull(result); 47 | } 48 | 49 | [Test] 50 | [TestCase("published")] 51 | [TestCase("Published")] 52 | [TestCase("PublisheD")] 53 | public void WhenValidPublishedStatusPassed_ShouldReturnTrue(string validPublishedStatus) 54 | { 55 | //Arange 56 | 57 | //Act 58 | bool? result = _apiTypeConverter.ToStatus(validPublishedStatus); 59 | 60 | //Assert 61 | Assert.IsTrue(result.Value); 62 | } 63 | 64 | [Test] 65 | [TestCase("unpublished")] 66 | [TestCase("Unpublished")] 67 | [TestCase("UnPubLished")] 68 | public void WhenValidUnpublishedStatusPassed_ShouldReturnFalse(string validUnpublishedStatus) 69 | { 70 | //Arange 71 | 72 | //Act 73 | bool? result = _apiTypeConverter.ToStatus(validUnpublishedStatus); 74 | 75 | //Assert 76 | Assert.IsFalse(result.Value); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ConvertersTests/ObjectConverter/DummyObjects/SomeTestingObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Nop.Core.Domain.Orders; 3 | using Nop.Core.Domain.Payments; 4 | using Nop.Core.Domain.Shipping; 5 | 6 | namespace Nop.Plugin.Api.Tests.ConvertersTests.ObjectConverter.DummyObjects 7 | { 8 | public class SomeTestingObject 9 | { 10 | public int IntProperty { get; set; } 11 | public string StringProperty { get; set; } 12 | public DateTime? DateTimeNullableProperty { get; set; } 13 | public bool? BooleanNullableStatusProperty { get; set; } 14 | public OrderStatus? OrderStatus { get; set; } 15 | public PaymentStatus? PaymentStatus { get; set; } 16 | public ShippingStatus? ShippingStatus { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/Helpers/ActionResultExecutor.cs: -------------------------------------------------------------------------------- 1 | namespace Nop.Plugin.Api.Tests.Helpers 2 | { 3 | using System.Net; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Rhino.Mocks; 7 | 8 | public static class ActionResultExecutor 9 | { 10 | public static HttpStatusCode ExecuteResult(IActionResult result) 11 | { 12 | var actionContext = MockRepository.GenerateStub(); 13 | actionContext.HttpContext = new DefaultHttpContext(); 14 | 15 | result.ExecuteResultAsync(actionContext); 16 | var statusCode = actionContext.HttpContext.Response.StatusCode; 17 | 18 | return (HttpStatusCode)statusCode; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ModelBinderTests/DummyObjects/DummyModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Nop.Plugin.Api.Tests.ModelBinderTests.DummyObjects 4 | { 5 | public class DummyModel 6 | { 7 | public string StringProperty { get; set; } 8 | public int IntProperty { get; set; } 9 | public int? IntNullableProperty { get; set; } 10 | public DateTime? DateTimeNullableProperty { get; set; } 11 | public bool? BooleanNullableStatusProperty { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/Nop.Plugin.Api.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net461 4 | 4.0.0.0 5 | Nop-Templates, Ltd 6 | Nop-Templates, Ltd 7 | The project contains a set of classes for testing of Nop.Plugin.Api 8 | Copyright © Nop-Templates, Ltd 9 | Git 10 | Nop.Plugin.Api.Tests 11 | 12 | 13 | 14 | 1.0.3.2 15 | 16 | 17 | 3.9.0 18 | 19 | 20 | 3.6.1 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/SerializersTests/DummyObjects/DummyObjectWithComplexTypes.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace Nop.Plugin.Api.Tests.SerializersTests.DummyObjects 5 | { 6 | public class DummyObjectWithComplexTypes 7 | { 8 | [JsonProperty("string_property")] 9 | public string StringProperty { get; set; } 10 | 11 | [JsonProperty("int_property")] 12 | public int IntProperty { get; set; } 13 | 14 | [JsonProperty("bool_property")] 15 | public bool BoolProperty { get; set; } 16 | 17 | [JsonProperty("list_of_dummy_object_with_simple_types")] 18 | public IList ListOfDummyObjectWithSimpleTypes { get; set; } 19 | 20 | [JsonProperty("dummy_object_with_simple_types")] 21 | public DummyObjectWithSimpleTypes DummyObjectWithSimpleTypes { get; set; } 22 | 23 | public override bool Equals(object obj) 24 | { 25 | if (obj is DummyObjectWithComplexTypes) 26 | { 27 | var that = obj as DummyObjectWithComplexTypes; 28 | 29 | return that.StringProperty.Equals(StringProperty) && 30 | that.IntProperty == IntProperty && 31 | that.BoolProperty == BoolProperty && 32 | that.ListOfDummyObjectWithSimpleTypes.Equals(ListOfDummyObjectWithSimpleTypes) && 33 | that.DummyObjectWithSimpleTypes.Equals(DummyObjectWithSimpleTypes); 34 | } 35 | 36 | return false; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/SerializersTests/DummyObjects/DummyObjectWithSimpleTypes.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.Tests.SerializersTests.DummyObjects 4 | { 5 | public class DummyObjectWithSimpleTypes 6 | { 7 | [JsonProperty("first_property")] 8 | public string FirstProperty { get; set; } 9 | 10 | [JsonProperty("second_property")] 11 | public string SecondProperty { get; set; } 12 | 13 | public override bool Equals(object obj) 14 | { 15 | if (obj is DummyObjectWithSimpleTypes) 16 | { 17 | var that = obj as DummyObjectWithSimpleTypes; 18 | 19 | return that.FirstProperty.Equals(FirstProperty) && that.SecondProperty.Equals(SecondProperty); 20 | } 21 | 22 | return false; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/SerializersTests/DummyObjects/SerializableDummyObjectWithComplexTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.DTOs; 5 | 6 | namespace Nop.Plugin.Api.Tests.SerializersTests.DummyObjects 7 | { 8 | public class SerializableDummyObjectWithComplexTypes : ISerializableObject 9 | { 10 | public SerializableDummyObjectWithComplexTypes() 11 | { 12 | Items = new List(); 13 | } 14 | 15 | [JsonProperty("primary_complex_property")] 16 | public IList Items { get; set; } 17 | 18 | public string GetPrimaryPropertyName() 19 | { 20 | return "primary_complex_property"; 21 | } 22 | 23 | public Type GetPrimaryPropertyType() 24 | { 25 | return typeof(DummyObjectWithComplexTypes); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/SerializersTests/DummyObjects/SerializableDummyObjectWithSimpleTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.DTOs; 5 | 6 | namespace Nop.Plugin.Api.Tests.SerializersTests.DummyObjects 7 | { 8 | public class SerializableDummyObjectWithSimpleTypes : ISerializableObject 9 | { 10 | public SerializableDummyObjectWithSimpleTypes() 11 | { 12 | Items = new List(); 13 | } 14 | 15 | [JsonProperty("primary_property")] 16 | public IList Items { get; set; } 17 | 18 | public string GetPrimaryPropertyName() 19 | { 20 | return "primary_property"; 21 | } 22 | 23 | public Type GetPrimaryPropertyType() 24 | { 25 | return typeof (DummyObjectWithSimpleTypes); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ServicesTests/CountryApiServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Nop.Core.Data; 4 | using Nop.Core.Domain.Directory; 5 | using Nop.Plugin.Api.Services; 6 | using NUnit.Framework; 7 | using Rhino.Mocks; 8 | 9 | namespace Nop.Plugin.Api.Tests.ServicesTests 10 | { 11 | //[TestFixture] 12 | //public class CountryApiServiceTests 13 | //{ 14 | // private ICountryApiService _countryApiService; 15 | 16 | // [SetUp] 17 | // public new void SetUp() 18 | // { 19 | // var countryRepositoryStub = MockRepository.GenerateStub>(); 20 | 21 | // countryRepositoryStub.Stub(x => x.Table).Return((new List() 22 | // { 23 | 24 | // new Country() 25 | // { 26 | // Name = "test country 1" 27 | // }, 28 | // new Country() 29 | // { 30 | // Name = "test country 2" 31 | // } 32 | 33 | // }).AsQueryable()); 34 | 35 | // _countryApiService = new CountryApiService(countryRepositoryStub); 36 | // } 37 | 38 | // [Test] 39 | // public void Get_country_by_existing_name() 40 | // { 41 | // var countryResult = _countryApiService.GetCountryByName("test country 1"); 42 | 43 | // Assert.IsNotNull(countryResult); 44 | // Assert.AreEqual("test country 1", countryResult.Name); 45 | // } 46 | 47 | // [Test] 48 | // public void Get_country_by_non_existing_name() 49 | // { 50 | // var countryResult = _countryApiService.GetCountryByName("non existing country name"); 51 | 52 | // Assert.IsNull(countryResult); 53 | // } 54 | //} 55 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ServicesTests/Orders/GetOrderById/OrderApiServiceTests_GetOrderById.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Nop.Core.Data; 4 | using Nop.Core.Domain.Orders; 5 | using Nop.Plugin.Api.Services; 6 | using NUnit.Framework; 7 | using Rhino.Mocks; 8 | 9 | namespace Nop.Plugin.Api.Tests.ServicesTests.Orders.GetOrderById 10 | { 11 | [TestFixture] 12 | public class OrderApiServiceTests_GetOrderById 13 | { 14 | [Test] 15 | public void WhenNullIsReturnedByTheRepository_ShouldReturnNull() 16 | { 17 | int orderId = 3; 18 | 19 | // Arange 20 | var orderRepo = MockRepository.GenerateStub>(); 21 | orderRepo.Stub(x => x.Table).Return((new List()).AsQueryable()); 22 | orderRepo.Stub(x => x.GetById(orderId)).Return(null); 23 | 24 | // Act 25 | var cut = new OrderApiService(orderRepo); 26 | var result = cut.GetOrderById(orderId); 27 | 28 | // Assert 29 | Assert.IsNull(result); 30 | } 31 | 32 | [Test] 33 | [TestCase(-2)] 34 | [TestCase(0)] 35 | public void WhenNegativeOrZeroOrderIdPassed_ShouldReturnNull(int negativeOrZeroOrderId) 36 | { 37 | // Aranges 38 | var orderRepoStub = MockRepository.GenerateStub>(); 39 | 40 | // Act 41 | var cut = new OrderApiService(orderRepoStub); 42 | var result = cut.GetOrderById(negativeOrZeroOrderId); 43 | 44 | // Assert 45 | Assert.IsNull(result); 46 | } 47 | 48 | [Test] 49 | public void WhenOrderIsReturnedByTheRepository_ShouldReturnTheSameOrder() 50 | { 51 | int orderId = 3; 52 | var order = new Order() { Id = 3 }; 53 | 54 | // Arange 55 | var orderRepo = MockRepository.GenerateStub>(); 56 | 57 | var list = new List(); 58 | list.Add(order); 59 | 60 | orderRepo.Stub(x => x.Table).Return(list.AsQueryable()); 61 | orderRepo.Stub(x => x.GetById(orderId)).Return(order); 62 | 63 | // Act 64 | var cut = new OrderApiService(orderRepo); 65 | var result = cut.GetOrderById(orderId); 66 | 67 | // Assert 68 | Assert.AreSame(order, result); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ServicesTests/ProductCategoryMappings/GetMappingById/ProductCategoryMappingsApiServiceTests_GetById.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Data; 2 | using Nop.Core.Domain.Catalog; 3 | using Nop.Plugin.Api.Services; 4 | using NUnit.Framework; 5 | using Rhino.Mocks; 6 | 7 | namespace Nop.Plugin.Api.Tests.ServicesTests.ProductCategoryMappings.GetMappingById 8 | { 9 | [TestFixture] 10 | public class ProductCategoryMappingsApiServiceTests_GetById 11 | { 12 | [Test] 13 | public void WhenNullIsReturnedByTheRepository_ShouldReturnNull() 14 | { 15 | int mappingId = 3; 16 | 17 | // Arange 18 | var productCategoryRepo = MockRepository.GenerateStub>(); 19 | productCategoryRepo.Stub(x => x.GetById(mappingId)).Return(null); 20 | 21 | // Act 22 | var cut = new ProductCategoryMappingsApiService(productCategoryRepo); 23 | var result = cut.GetById(mappingId); 24 | 25 | // Assert 26 | Assert.IsNull(result); 27 | } 28 | 29 | [Test] 30 | [TestCase(-2)] 31 | [TestCase(0)] 32 | public void WhenNegativeOrZeroMappingIdPassed_ShouldReturnNull(int negativeOrZeroOrderId) 33 | { 34 | // Aranges 35 | var mappingRepoMock = MockRepository.GenerateStub>(); 36 | 37 | // Act 38 | var cut = new ProductCategoryMappingsApiService(mappingRepoMock); 39 | var result = cut.GetById(negativeOrZeroOrderId); 40 | 41 | // Assert 42 | Assert.IsNull(result); 43 | } 44 | 45 | [Test] 46 | public void WhenMappingIsReturnedByTheRepository_ShouldReturnTheSameMapping() 47 | { 48 | int mappingId = 3; 49 | var mapping = new ProductCategory() { Id = 3 }; 50 | 51 | // Arange 52 | var mappingRepo = MockRepository.GenerateStub>(); 53 | mappingRepo.Stub(x => x.GetById(mappingId)).Return(mapping); 54 | 55 | // Act 56 | var cut = new ProductCategoryMappingsApiService(mappingRepo); 57 | var result = cut.GetById(mappingId); 58 | 59 | // Assert 60 | Assert.AreSame(mapping, result); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ServicesTests/ProductCategoryMappings/GetMappings/ProductCategoryMappingsApiServiceTests_GetMappings_DefaultParameters.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Nop.Core.Data; 5 | using Nop.Core.Domain.Catalog; 6 | using Nop.Plugin.Api.Constants; 7 | using Nop.Plugin.Api.Services; 8 | using NUnit.Framework; 9 | using Rhino.Mocks; 10 | 11 | namespace Nop.Plugin.Api.Tests.ServicesTests.ProductCategoryMappings.GetMappings 12 | { 13 | [TestFixture] 14 | public class ProductCategoryMappingsApiServiceTests_GetMappings_DefaultParameters 15 | { 16 | [Test] 17 | public void GivenNonEmptyValidRepositoryWithMoreThanTheMaxItems_ShouldReturnDefaultLimitItems() 18 | { 19 | var repo = new List(); 20 | 21 | var randomNumber = new Random(); 22 | 23 | var currentRepoSize = Configurations.MaxLimit * 2; 24 | 25 | for (int i = 0; i < currentRepoSize; i++) 26 | { 27 | repo.Add(new ProductCategory() 28 | { 29 | CategoryId = randomNumber.Next(10, 20), 30 | ProductId = randomNumber.Next(1, 2), 31 | }); 32 | } 33 | 34 | // Arange 35 | var mappingRepo = MockRepository.GenerateStub>(); 36 | mappingRepo.Stub(x => x.TableNoTracking).Return(repo.AsQueryable()); 37 | 38 | // Act 39 | var cut = new ProductCategoryMappingsApiService(mappingRepo); 40 | 41 | var result = cut.GetMappings(); 42 | 43 | // Assert 44 | Assert.IsNotEmpty(result); 45 | Assert.AreEqual(Configurations.DefaultLimit, result.Count); 46 | } 47 | 48 | [Test] 49 | public void GivenEmptyRepository_ShouldReturnEmptyCollection() 50 | { 51 | var repo = new List(); 52 | 53 | // Arange 54 | var mappingRepo = MockRepository.GenerateStub>(); 55 | mappingRepo.Stub(x => x.TableNoTracking).Return(repo.AsQueryable()); 56 | 57 | // Act 58 | var cut = new ProductCategoryMappingsApiService(mappingRepo); 59 | 60 | var result = cut.GetMappings(); 61 | 62 | // Assert 63 | Assert.IsEmpty(result); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ServicesTests/StateProvinceApiServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Nop.Core.Data; 4 | using Nop.Core.Domain.Directory; 5 | using Nop.Plugin.Api.Services; 6 | using NUnit.Framework; 7 | using Rhino.Mocks; 8 | 9 | namespace Nop.Plugin.Api.Tests.ServicesTests 10 | { 11 | //[TestFixture] 12 | //public class StateProvinceApiServiceTests 13 | //{ 14 | // private IStateProvinceApiService _stateProvinceApiService; 15 | 16 | // [SetUp] 17 | // public new void SetUp() 18 | // { 19 | // var stateProvinceRepositoryStub = MockRepository.GenerateStub>(); 20 | 21 | // stateProvinceRepositoryStub.Stub(x => x.Table).Return((new List() 22 | // { 23 | // new StateProvince() 24 | // { 25 | // Name = "test state 1" 26 | // }, 27 | // new StateProvince() 28 | // { 29 | // Name = "test state 2" 30 | // } 31 | // }).AsQueryable()); 32 | 33 | // _stateProvinceApiService = new StateProvinceApiService(stateProvinceRepositoryStub); 34 | // } 35 | 36 | // [Test] 37 | // public void Get_state_by_existing_name() 38 | // { 39 | // StateProvince state = _stateProvinceApiService.GetStateProvinceByName("test state 1"); 40 | 41 | // Assert.IsNotNull(state); 42 | // Assert.AreEqual("test state 1", state.Name); 43 | // } 44 | 45 | // [Test] 46 | // public void Get_state_by_non_existing_name() 47 | // { 48 | // StateProvince state = _stateProvinceApiService.GetStateProvinceByName("non existing state name"); 49 | 50 | // Assert.IsNull(state); 51 | // } 52 | //} 53 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/SetUp.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace Nop.Plugin.Api.Tests 4 | { 5 | [SetUpFixture] 6 | public class SetUp 7 | { 8 | [OneTimeSetUp] 9 | public void RunBeforeAnyTests() 10 | { 11 | // We need to create all the mappings before any of the test are run 12 | // All maps are created in the ApiMapperConfiguration constructor. 13 | ApiMapperConfiguration mapps = new ApiMapperConfiguration(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/ValidatorTests/TypeValidatorTests_IsValid.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Globalization; 3 | using System.Threading; 4 | using Nop.Plugin.Api.DTOs.Products; 5 | using NUnit.Framework; 6 | using Nop.Plugin.Api.Tests.SerializersTests.DummyObjects; 7 | using Nop.Plugin.Api.Validators; 8 | 9 | namespace Nop.Plugin.Api.Tests.ValidatorTests 10 | { 11 | public class TypeValidatorTests_IsValid 12 | { 13 | [Test] 14 | [SetCulture("de-de")] 15 | [Description("Regression test for issue #11 - https://github.com/SevenSpikes/api-plugin-for-nopcommerce/issues/11")] 16 | public void WhenCurrentCultureUsesCommaAsDecimalPoint_ShouldProperlyValidateProductPrice() 17 | { 18 | //Arange 19 | Dictionary properties = new Dictionary(); 20 | properties.Add("price", 33.33); 21 | 22 | var cut = new TypeValidator(); 23 | 24 | //Act 25 | bool result = cut.IsValid(properties); 26 | 27 | // Assert 28 | Assert.IsTrue(result); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Nop.Plugin.Api.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Areas/Admin/Models/ConfigurationModel.cs: -------------------------------------------------------------------------------- 1 | using Nop.Web.Framework.Mvc.ModelBinding; 2 | 3 | namespace Nop.Plugin.Api.Areas.Admin.Models 4 | { 5 | public class ConfigurationModel 6 | { 7 | [NopResourceDisplayName("Plugins.Api.Admin.EnableApi")] 8 | public bool EnableApi { get; set; } 9 | 10 | public bool EnableApi_OverrideForStore { get; set; } 11 | 12 | [NopResourceDisplayName("Plugins.Api.Admin.AllowRequestsFromSwagger")] 13 | public bool AllowRequestsFromSwagger { get; set; } 14 | 15 | public bool AllowRequestsFromSwagger_OverrideForStore { get; set; } 16 | 17 | [NopResourceDisplayName("Plugins.Api.Admin.EnableLogging")] 18 | public bool EnableLogging { get; set; } 19 | 20 | public bool EnableLogging_OverrideForStore { get; set; } 21 | 22 | public int ActiveStoreScopeConfiguration { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Areas/Admin/Views/ApiAdmin/Settings.cshtml: -------------------------------------------------------------------------------- 1 | @using Nop.Plugin.Api.Infrastructure 2 | @model Nop.Plugin.Api.Areas.Admin.Models.ConfigurationModel 3 | 4 | @{ 5 | Layout = Constants.ViewNames.AdminLayout; 6 | 7 | //page title 8 | ViewBag.Title = T("Plugins.Api.Admin.Page.Settings.Title").Text; 9 | 10 | //active menu item (system name) 11 | Html.SetActiveMenuItemSystemName("Api-Settings-Menu"); 12 | } 13 | 14 |
15 | @Html.AntiForgeryToken() 16 | 17 |
18 |

19 | @T("Plugins.Api.Admin.Page.Settings.Title") 20 |

21 |
22 | 26 |
27 |
28 | 29 |
30 |
31 | @await Component.InvokeAsync("StoreScopeConfiguration") 32 | @Html.ValidationSummary(false) 33 |
34 | 35 |
36 |
37 |
38 |
39 | 40 | 41 |
42 |
43 | 44 | 45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Areas/Admin/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage 2 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 3 | @addTagHelper *, Nop.Web.Framework 4 | 5 | @using Nop.Web.Framework.UI 6 | @using Nop.Plugin.Api.Models 7 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Attributes/BaseAttributeInvoker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Nop.Plugin.Api.Attributes 5 | { 6 | public abstract class BaseValidationAttribute : Attribute 7 | { 8 | public abstract void Validate(object instance); 9 | public abstract Dictionary GetErrors(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Attributes/DoNotMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Nop.Plugin.Api.Attributes 4 | { 5 | public class DoNotMapAttribute : Attribute 6 | { 7 | // just a marker 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Attributes/ImageCollectionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Plugin.Api.DTO.Images; 3 | 4 | namespace Nop.Plugin.Api.Attributes 5 | { 6 | public class ImageCollectionValidationAttribute : BaseValidationAttribute 7 | { 8 | private Dictionary _errors = new Dictionary(); 9 | 10 | public override void Validate(object instance) 11 | { 12 | // Images are not required so they could be null 13 | // and there is nothing to validate in this case 14 | 15 | if (instance is ICollection imagesCollection) 16 | { 17 | foreach (var image in imagesCollection) 18 | { 19 | var imageValidationAttribute = new ImageValidationAttribute(); 20 | 21 | imageValidationAttribute.Validate(image); 22 | 23 | var errorsForImage = imageValidationAttribute.GetErrors(); 24 | 25 | if (errorsForImage.Count > 0) 26 | { 27 | _errors = errorsForImage; 28 | break; 29 | } 30 | } 31 | } 32 | } 33 | 34 | public override Dictionary GetErrors() 35 | { 36 | return _errors; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Attributes/ProductTypeValidationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Catalog; 4 | 5 | namespace Nop.Plugin.Api.Attributes 6 | { 7 | public class ProductTypeValidationAttribute : BaseValidationAttribute 8 | { 9 | private readonly Dictionary _errors = new Dictionary(); 10 | 11 | public override void Validate(object instance) 12 | { 13 | // Product Type is not required so it could be null 14 | // and there is nothing to validate in this case 15 | if (instance == null) 16 | { 17 | return; 18 | } 19 | 20 | var isDefined = Enum.IsDefined(typeof(ProductType), instance); 21 | 22 | if (!isDefined) 23 | { 24 | _errors.Add("ProductType", "Invalid product type"); 25 | } 26 | } 27 | 28 | public override Dictionary GetErrors() 29 | { 30 | return _errors; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Attributes/ValidateVendor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Core.Infrastructure; 3 | using Nop.Services.Vendors; 4 | 5 | namespace Nop.Plugin.Api.Attributes 6 | { 7 | public class ValidateVendor : BaseValidationAttribute 8 | { 9 | private readonly Dictionary _errors; 10 | 11 | private IVendorService _vendorService; 12 | 13 | public ValidateVendor() 14 | { 15 | _errors = new Dictionary(); 16 | } 17 | 18 | private IVendorService VendorService => _vendorService ?? (_vendorService = EngineContext.Current.Resolve()); 19 | 20 | public override void Validate(object instance) 21 | { 22 | if (instance != null && int.TryParse(instance.ToString(), out var vendorId)) 23 | { 24 | if (vendorId > 0) 25 | { 26 | var vendor = VendorService.GetVendorById(vendorId); 27 | 28 | if (vendor == null) 29 | { 30 | _errors.Add("Invalid vendor id", "Non existing vendor"); 31 | } 32 | } 33 | } 34 | } 35 | 36 | public override Dictionary GetErrors() 37 | { 38 | return _errors; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Authorization/Policies/ActiveApiPluginAuthorizationPolicy.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.AspNetCore.Authorization; 3 | using Nop.Plugin.Api.Authorization.Requirements; 4 | 5 | namespace Nop.Plugin.Api.Authorization.Policies 6 | { 7 | public class ActiveApiPluginAuthorizationPolicy : AuthorizationHandler 8 | { 9 | protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ActiveApiPluginRequirement requirement) 10 | { 11 | if (requirement.IsActive()) 12 | { 13 | context.Succeed(requirement); 14 | } 15 | else 16 | { 17 | context.Fail(); 18 | } 19 | 20 | return Task.CompletedTask; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Authorization/Policies/CustomerRoleAuthorizationPolicy.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.AspNetCore.Authorization; 3 | using Nop.Plugin.Api.Authorization.Requirements; 4 | 5 | namespace Nop.Plugin.Api.Authorization.Policies 6 | { 7 | public class CustomerRoleAuthorizationPolicy : AuthorizationHandler 8 | { 9 | protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CustomerRoleRequirement requirement) 10 | { 11 | if (requirement.IsCustomerInRole()) 12 | { 13 | context.Succeed(requirement); 14 | } 15 | else 16 | { 17 | context.Fail(); 18 | } 19 | 20 | return Task.CompletedTask; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Authorization/Policies/ValidSchemeAuthorizationPolicy.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.AspNetCore.Authorization; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Mvc.Filters; 5 | using Nop.Plugin.Api.Authorization.Requirements; 6 | 7 | namespace Nop.Plugin.Api.Authorization.Policies 8 | { 9 | public class ValidSchemeAuthorizationPolicy : AuthorizationHandler 10 | { 11 | IHttpContextAccessor _httpContextAccessor = null; 12 | public ValidSchemeAuthorizationPolicy(IHttpContextAccessor httpContextAccessor) 13 | { 14 | _httpContextAccessor = httpContextAccessor; 15 | } 16 | protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AuthorizationSchemeRequirement requirement) 17 | { 18 | //var mvcContext = context.Resource as 19 | // AuthorizationFilterContext; 20 | //if (requirement.IsValid(mvcContext?.HttpContext.Request.Headers)) 21 | //{ 22 | // context.Succeed(requirement); 23 | //} 24 | //else 25 | //{ 26 | // context.Fail(); 27 | //} 28 | 29 | if (requirement.IsValid(_httpContextAccessor?.HttpContext.Request.Headers)) 30 | { 31 | context.Succeed(requirement); 32 | } 33 | else 34 | { 35 | context.Fail(); 36 | } 37 | 38 | return Task.CompletedTask; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Authorization/Requirements/ActiveApiPluginRequirement.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Nop.Core.Infrastructure; 3 | using Nop.Plugin.Api.Domain; 4 | 5 | namespace Nop.Plugin.Api.Authorization.Requirements 6 | { 7 | public class ActiveApiPluginRequirement : IAuthorizationRequirement 8 | { 9 | public bool IsActive() 10 | { 11 | var settings = EngineContext.Current.Resolve(); 12 | 13 | if (settings.EnableApi) 14 | { 15 | return true; 16 | } 17 | 18 | return false; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Authorization/Requirements/AuthorizationSchemeRequirement.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authentication.JwtBearer; 2 | using Microsoft.AspNetCore.Authorization; 3 | using Microsoft.AspNetCore.Http; 4 | 5 | namespace Nop.Plugin.Api.Authorization.Requirements 6 | { 7 | public class AuthorizationSchemeRequirement : IAuthorizationRequirement 8 | { 9 | public bool IsValid(IHeaderDictionary requestHeaders) 10 | { 11 | if (requestHeaders != null && 12 | requestHeaders.ContainsKey("Authorization") && 13 | requestHeaders["Authorization"].ToString().Contains(JwtBearerDefaults.AuthenticationScheme)) 14 | { 15 | return true; 16 | } 17 | 18 | return false; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Authorization/Requirements/CustomerRoleRequirement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Http; 7 | using Nop.Core.Domain.Customers; 8 | using Nop.Core.Infrastructure; 9 | using Nop.Plugin.Api.Infrastructure; 10 | using Nop.Services.Customers; 11 | 12 | namespace Nop.Plugin.Api.Authorization.Requirements 13 | { 14 | public class CustomerRoleRequirement : IAuthorizationRequirement 15 | { 16 | public bool IsCustomerInRole() 17 | { 18 | try 19 | { 20 | var httpContextAccessor = EngineContext.Current.Resolve(); 21 | 22 | var customerIdClaim = httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(m => m.Type == ClaimTypes.NameIdentifier); 23 | 24 | if (customerIdClaim != null && Guid.TryParse(customerIdClaim.Value, out var customerGuid)) 25 | { 26 | var customerService = EngineContext.Current.Resolve(); 27 | 28 | var customer = customerService.GetCustomerByGuid(customerGuid); 29 | 30 | if (customer != null) 31 | { 32 | var customerRoles = customerService.GetCustomerRoles(customer); 33 | return IsInApiRole(customerRoles); 34 | } 35 | } 36 | } 37 | catch 38 | { 39 | // best effort 40 | } 41 | 42 | return false; 43 | } 44 | 45 | private static bool IsInApiRole(IEnumerable customerRoles) 46 | { 47 | return customerRoles.FirstOrDefault(cr => cr.SystemName == Constants.Roles.ApiRoleSystemName) != null; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/AutoMapper/AutoMapperApiConfiguration.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AutoMapper.Configuration; 3 | 4 | namespace Nop.Plugin.Api.AutoMapper 5 | { 6 | public static class AutoMapperApiConfiguration 7 | { 8 | private static MapperConfigurationExpression s_mapperConfigurationExpression; 9 | private static IMapper s_mapper; 10 | private static readonly object s_mapperLockObject = new object(); 11 | 12 | public static MapperConfigurationExpression MapperConfigurationExpression => 13 | s_mapperConfigurationExpression ?? 14 | (s_mapperConfigurationExpression = new MapperConfigurationExpression()); 15 | 16 | public static IMapper Mapper 17 | { 18 | get 19 | { 20 | if (s_mapper == null) 21 | { 22 | lock (s_mapperLockObject) 23 | { 24 | if (s_mapper == null) 25 | { 26 | var mapperConfiguration = new MapperConfiguration(MapperConfigurationExpression); 27 | 28 | s_mapper = mapperConfiguration.CreateMapper(); 29 | } 30 | } 31 | } 32 | 33 | return s_mapper; 34 | } 35 | } 36 | 37 | public static TDestination MapTo(this TSource source) 38 | { 39 | return Mapper.Map(source); 40 | } 41 | 42 | public static TDestination MapTo(this TSource source, TDestination destination) 43 | { 44 | return Mapper.Map(source, destination); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Configuration/ApiConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Nop.Plugin.Api.Configuration 2 | { 3 | public class ApiConfiguration 4 | { 5 | public int AllowedClockSkewInMinutes { get; set; } = 5; 6 | 7 | public string SecurityKey { get; set; } = "NowIsTheTimeForAllGoodMenToComeToTheAideOfTheirCountry"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Configuration/ApplicationPartsLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Mvc.ApplicationParts; 8 | using Microsoft.AspNetCore.Mvc.Controllers; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace Nop.Plugin.Api.Configuration 13 | { 14 | public class ApplicationPartsLogger : IHostedService 15 | { 16 | private readonly ILogger _logger; 17 | private readonly ApplicationPartManager _partManager; 18 | 19 | public ApplicationPartsLogger(ILogger logger, ApplicationPartManager partManager) 20 | { 21 | _logger = logger; 22 | _partManager = partManager; 23 | } 24 | 25 | public Task StartAsync(CancellationToken cancellationToken) 26 | { 27 | // Get the names of all the application parts. This is the short assembly name for AssemblyParts 28 | var applicationParts = _partManager.ApplicationParts.Select(x => x.Name); 29 | 30 | // Create a controller feature, and populate it from the application parts 31 | var controllerFeature = new ControllerFeature(); 32 | _partManager.PopulateFeature(controllerFeature); 33 | 34 | // Get the names of all of the controllers 35 | var controllers = controllerFeature.Controllers.Select(x => x.Name); 36 | 37 | // Log the application parts and controllers 38 | _logger.LogInformation("Found the following application parts: '{ApplicationParts}' with the following controllers: '{Controllers}'", 39 | string.Join(", ", applicationParts), string.Join(", ", controllers)); 40 | 41 | return Task.CompletedTask; 42 | } 43 | 44 | // Required by the interface 45 | public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Converters/IApiTypeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Nop.Plugin.Api.Converters 5 | { 6 | public interface IApiTypeConverter 7 | { 8 | DateTime? ToUtcDateTimeNullable(string value); 9 | int ToInt(string value); 10 | int? ToIntNullable(string value); 11 | IList ToListOfInts(string value); 12 | bool? ToStatus(string value); 13 | object ToEnumNullable(string value, Type type); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Converters/IObjectConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Nop.Plugin.Api.Converters 4 | { 5 | public interface IObjectConverter 6 | { 7 | T ToObject(ICollection> source) 8 | where T : class, new(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Base/BaseDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.Base 4 | { 5 | public abstract class BaseDto 6 | { 7 | [JsonProperty("id")] 8 | public int Id { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Categories/CategoriesCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.Categories 4 | { 5 | public class CategoriesCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Categories/CategoriesRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Categories 6 | { 7 | public class CategoriesRootObject : ISerializableObject 8 | { 9 | public CategoriesRootObject() 10 | { 11 | Categories = new List(); 12 | } 13 | 14 | [JsonProperty("categories")] 15 | public IList Categories { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "categories"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(CategoryDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/CustomerRoles/CustomerRoleDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.DTO.Base; 3 | 4 | namespace Nop.Plugin.Api.DTO.CustomerRoles 5 | { 6 | [JsonObject(Title = "customer_role")] 7 | public class CustomerRoleDto : BaseDto 8 | { 9 | /// 10 | /// Gets or sets the customer role name 11 | /// 12 | [JsonProperty("name")] 13 | public string Name { get; set; } 14 | 15 | /// 16 | /// Gets or sets a value indicating whether the customer role is marked as free shiping 17 | /// 18 | [JsonProperty("free_shipping")] 19 | public bool? FreeShipping { get; set; } 20 | 21 | /// 22 | /// Gets or sets a value indicating whether the customer role is marked as tax exempt 23 | /// 24 | [JsonProperty("tax_exempt")] 25 | 26 | public bool? TaxExempt { get; set; } 27 | 28 | /// 29 | /// Gets or sets a value indicating whether the customer role is active 30 | /// 31 | [JsonProperty("active")] 32 | public bool? Active { get; set; } 33 | 34 | /// 35 | /// Gets or sets a value indicating whether the customer role is system 36 | /// 37 | [JsonProperty("is_system_role")] 38 | public bool? IsSystemRole { get; set; } 39 | 40 | /// 41 | /// Gets or sets the customer role system name 42 | /// 43 | [JsonProperty("system_name")] 44 | public string SystemName { get; set; } 45 | 46 | /// 47 | /// Gets or sets a value indicating whether the customers must change passwords after a specified time 48 | /// 49 | [JsonProperty("enable_password_lifetime")] 50 | public bool? EnablePasswordLifetime { get; set; } 51 | 52 | /// 53 | /// Gets or sets a product identifier that is required by this customer role. 54 | /// A customer is added to this customer role once a specified product is purchased. 55 | /// 56 | [JsonProperty("purchased_with_product_id")] 57 | public int? PurchasedWithProductId { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/CustomerRoles/CustomerRolesRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.CustomerRoles 6 | { 7 | public class CustomerRolesRootObject : ISerializableObject 8 | { 9 | public CustomerRolesRootObject() 10 | { 11 | CustomerRoles = new List(); 12 | } 13 | 14 | [JsonProperty("customer_roles")] 15 | public IList CustomerRoles { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "customer_roles"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(CustomerRoleDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Customers/CustomerAttributeMappingDto.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Common; 2 | using Nop.Core.Domain.Customers; 3 | 4 | namespace Nop.Plugin.Api.DTO.Customers 5 | { 6 | public class CustomerAttributeMappingDto 7 | { 8 | public Customer Customer { get; set; } 9 | public GenericAttribute Attribute { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Customers/CustomerDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Attributes; 4 | using Nop.Plugin.Api.DTO.ShoppingCarts; 5 | 6 | namespace Nop.Plugin.Api.DTO.Customers 7 | { 8 | [JsonObject(Title = "customer")] 9 | //[Validator(typeof(CustomerDtoValidator))] 10 | public class CustomerDto : BaseCustomerDto 11 | { 12 | private ICollection _addresses; 13 | private ICollection _shoppingCartItems; 14 | 15 | [JsonIgnore] 16 | [JsonProperty("password")] 17 | public string Password { get; set; } 18 | 19 | #region Navigation properties 20 | 21 | /// 22 | /// Gets or sets shopping cart items 23 | /// 24 | [JsonProperty("shopping_cart_items")] 25 | [DoNotMap] 26 | public ICollection ShoppingCartItems 27 | { 28 | get 29 | { 30 | if (_shoppingCartItems == null) 31 | { 32 | _shoppingCartItems = new List(); 33 | } 34 | 35 | return _shoppingCartItems; 36 | } 37 | set => _shoppingCartItems = value; 38 | } 39 | 40 | /// 41 | /// Default billing address 42 | /// 43 | [JsonProperty("billing_address")] 44 | public AddressDto BillingAddress { get; set; } 45 | 46 | /// 47 | /// Default shipping address 48 | /// 49 | [JsonProperty("shipping_address")] 50 | public AddressDto ShippingAddress { get; set; } 51 | 52 | /// 53 | /// Gets or sets customer addresses 54 | /// 55 | [JsonProperty("addresses")] 56 | public ICollection Addresses 57 | { 58 | get 59 | { 60 | if (_addresses == null) 61 | { 62 | _addresses = new List(); 63 | } 64 | 65 | return _addresses; 66 | } 67 | set => _addresses = value; 68 | } 69 | 70 | #endregion 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Customers/CustomerForShoppingCartItemDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace Nop.Plugin.Api.DTO.Customers 5 | { 6 | // We need this DTO object to avoid loop in the entity to dto mappings. The difference is the missing ShoppingCartItems collection. 7 | [JsonObject(Title = "customers")] 8 | public class CustomerForShoppingCartItemDto : BaseCustomerDto 9 | { 10 | #region Navigation properties 11 | 12 | /// 13 | /// Default billing address 14 | /// 15 | [JsonProperty("billing_address")] 16 | public AddressDto BillingAddress { get; set; } 17 | 18 | /// 19 | /// Default shipping address 20 | /// 21 | [JsonProperty("shipping_address")] 22 | public AddressDto ShippingAddress { get; set; } 23 | 24 | /// 25 | /// Gets or sets customer addresses 26 | /// 27 | [JsonProperty("addresses")] 28 | public ICollection Addresses { get; set; } 29 | 30 | #endregion 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Customers/CustomersCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.Customers 4 | { 5 | public class CustomersCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Customers/CustomersRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Customers 6 | { 7 | public class CustomersRootObject : ISerializableObject 8 | { 9 | public CustomersRootObject() 10 | { 11 | Customers = new List(); 12 | } 13 | 14 | [JsonProperty("customers")] 15 | public IList Customers { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "customers"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(CustomerDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Customers/OrderCustomerDto.cs: -------------------------------------------------------------------------------- 1 | namespace Nop.Plugin.Api.DTO.Customers 2 | { 3 | public class OrderCustomerDto : BaseCustomerDto 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Errors/ErrorsRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Errors 6 | { 7 | public class ErrorsRootObject : ISerializableObject 8 | { 9 | [JsonProperty("errors")] 10 | public Dictionary> Errors { get; set; } 11 | 12 | public string GetPrimaryPropertyName() 13 | { 14 | return "errors"; 15 | } 16 | 17 | public Type GetPrimaryPropertyType() 18 | { 19 | return Errors.GetType(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ISerializableObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Nop.Plugin.Api.DTO 4 | { 5 | public interface ISerializableObject 6 | { 7 | string GetPrimaryPropertyName(); 8 | Type GetPrimaryPropertyType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Images/ImageDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.Attributes; 3 | 4 | namespace Nop.Plugin.Api.DTO.Images 5 | { 6 | [ImageValidation] 7 | public class ImageDto 8 | { 9 | [JsonProperty("src")] 10 | public string Src { get; set; } 11 | 12 | [JsonProperty("attachment")] 13 | public string Attachment { get; set; } 14 | 15 | [JsonIgnore] 16 | public byte[] Binary { get; set; } 17 | 18 | [JsonIgnore] 19 | public string MimeType { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Images/ImageMappingDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.Attributes; 3 | 4 | namespace Nop.Plugin.Api.DTO.Images 5 | { 6 | [ImageValidation] 7 | public class ImageMappingDto : ImageDto 8 | { 9 | [JsonProperty("id")] 10 | public int Id { get; set; } 11 | 12 | [JsonProperty("picture_id")] 13 | public int PictureId { get; set; } 14 | 15 | [JsonProperty("position")] 16 | public int Position { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Languages/LanguagesRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Languages 6 | { 7 | public class LanguagesRootObject : ISerializableObject 8 | { 9 | public LanguagesRootObject() 10 | { 11 | Languages = new List(); 12 | } 13 | 14 | [JsonProperty("languages")] 15 | public IList Languages { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "languages"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(LanguageDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Languages/LocalizedNameDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.Languages 4 | { 5 | public class LocalizedNameDto 6 | { 7 | /// 8 | /// Gets or sets the language identifier 9 | /// 10 | [JsonProperty("language_id")] 11 | public int? LanguageId { get; set; } 12 | 13 | /// 14 | /// Gets or sets the localized name 15 | /// 16 | [JsonProperty("localized_name")] 17 | public string LocalizedName { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Manufacturers/DiscountManufacturerMappingDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.DTO.Base; 3 | 4 | namespace Nop.Plugin.Api.DTO.Manufacturers 5 | { 6 | [JsonObject(Title = "discount")] 7 | //[Validator(typeof(ProductDtoValidator))] 8 | public class DiscountManufacturerMappingDto : BaseDto 9 | { 10 | /// 11 | /// Gets or sets the discount identifier 12 | /// 13 | [JsonProperty("discount_id")] 14 | public int DiscountId { get; set; } 15 | 16 | 17 | [JsonProperty("discount_name")] 18 | public string DiscountName { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Manufacturers/ManufacturersCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.Manufacturers 4 | { 5 | public class ManufacturersCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Manufacturers/ManufacturersRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Manufacturers 6 | { 7 | public class ManufacturersRootObject : ISerializableObject 8 | { 9 | public ManufacturersRootObject() 10 | { 11 | Manufacturers = new List(); 12 | } 13 | 14 | [JsonProperty("manufacturers")] 15 | public IList Manufacturers { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "manufacturers"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(ManufacturerDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/NewsLetterSubscriptions/NewsLetterSubscriptionDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.DTO.Base; 4 | 5 | namespace Nop.Plugin.Api.DTO.NewsLetterSubscriptions 6 | { 7 | [JsonObject(Title = "news_letter_subscription")] 8 | public class NewsLetterSubscriptionDto : BaseDto 9 | { 10 | /// 11 | /// Gets or sets the email 12 | /// 13 | [JsonProperty("email")] 14 | public string Email { get; set; } 15 | 16 | /// 17 | /// Gets or sets whether the subscription is active 18 | /// 19 | [JsonProperty("active")] 20 | public bool Active { get; set; } 21 | 22 | /// 23 | /// Gets or sets whether the subscription is active 24 | /// 25 | [JsonProperty("store_id")] 26 | public int StoreId { get; set; } 27 | 28 | /// 29 | /// Gets or sets created on utc date 30 | /// 31 | [JsonProperty("created_on_utc")] 32 | public DateTime? CreatedOnUtc { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/NewsLetterSubscriptions/NewsLetterSubscriptionsRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.NewsLetterSubscriptions 6 | { 7 | public class NewsLetterSubscriptionsRootObject : ISerializableObject 8 | { 9 | public NewsLetterSubscriptionsRootObject() 10 | { 11 | NewsLetterSubscriptions = new List(); 12 | } 13 | 14 | [JsonProperty("news_letter_subscriptions")] 15 | public IList NewsLetterSubscriptions { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "news_letter_subscriptions"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(NewsLetterSubscriptionDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/OrderItems/OrderItemsCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.OrderItems 4 | { 5 | public class OrderItemsCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/OrderItems/OrderItemsRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.OrderItems 6 | { 7 | public class OrderItemsRootObject : ISerializableObject 8 | { 9 | public OrderItemsRootObject() 10 | { 11 | OrderItems = new List(); 12 | } 13 | 14 | [JsonProperty("order_items")] 15 | public IList OrderItems { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "order_items"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(OrderItemDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Orders/OrdersCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.Orders 4 | { 5 | public class OrdersCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Orders/OrdersRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Orders 6 | { 7 | public class OrdersRootObject : ISerializableObject 8 | { 9 | public OrdersRootObject() 10 | { 11 | Orders = new List(); 12 | } 13 | 14 | [JsonProperty("orders")] 15 | public IList Orders { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "orders"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(OrderDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Orders/SingleOrderRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.Orders 4 | { 5 | public class SingleOrderRootObject 6 | { 7 | [JsonProperty("order")] 8 | public OrderDto Order { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductAttributes/ProductAttributeDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.DTO.Base; 3 | 4 | namespace Nop.Plugin.Api.DTO.ProductAttributes 5 | { 6 | [JsonObject(Title = "product_attribute")] 7 | //[Validator(typeof(ProductAttributeDtoValidator))] 8 | public class ProductAttributeDto : BaseDto 9 | { 10 | /// 11 | /// Gets or sets the name 12 | /// 13 | [JsonProperty("name")] 14 | public string Name { get; set; } 15 | 16 | ///// 17 | ///// Gets or sets the localized names 18 | ///// 19 | //[JsonProperty("localized_names")] 20 | //public List LocalizedNames 21 | //{ 22 | // get 23 | // { 24 | // return _localizedNames; 25 | // } 26 | // set 27 | // { 28 | // _localizedNames = value; 29 | // } 30 | //} 31 | 32 | /// 33 | /// Gets or sets the description 34 | /// 35 | [JsonProperty("description")] 36 | public string Description { get; set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductAttributes/ProductAttributesCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.ProductAttributes 4 | { 5 | public class ProductAttributesCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductAttributes/ProductAttributesRootObjectDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.ProductAttributes 6 | { 7 | public class ProductAttributesRootObjectDto : ISerializableObject 8 | { 9 | public ProductAttributesRootObjectDto() 10 | { 11 | ProductAttributes = new List(); 12 | } 13 | 14 | [JsonProperty("product_attributes")] 15 | public IList ProductAttributes { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "product_attributes"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(ProductAttributeDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductCategoryMappings/ProductCategoryMappingsCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.ProductCategoryMappings 4 | { 5 | public class ProductCategoryMappingsCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductCategoryMappings/ProductCategoryMappingsDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.DTO.Base; 3 | 4 | namespace Nop.Plugin.Api.DTO.ProductCategoryMappings 5 | { 6 | [JsonObject(Title = "product_category_mapping")] 7 | //[Validator(typeof(ProductCategoryMappingDtoValidator))] 8 | public class ProductCategoryMappingDto : BaseDto 9 | { 10 | /// 11 | /// Gets or sets the product identifier 12 | /// 13 | [JsonProperty("product_id")] 14 | public int? ProductId { get; set; } 15 | 16 | /// 17 | /// Gets or sets the category identifier 18 | /// 19 | [JsonProperty("category_id")] 20 | public int? CategoryId { get; set; } 21 | 22 | /// 23 | /// Gets or sets a value indicating whether the product is featured 24 | /// 25 | [JsonProperty("is_featured_product")] 26 | public bool? IsFeaturedProduct { get; set; } 27 | 28 | /// 29 | /// Gets or sets the display order 30 | /// 31 | [JsonProperty("display_order")] 32 | public int? DisplayOrder { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductCategoryMappings/ProductCategoryMappingsRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.ProductCategoryMappings 6 | { 7 | public class ProductCategoryMappingsRootObject : ISerializableObject 8 | { 9 | public ProductCategoryMappingsRootObject() 10 | { 11 | ProductCategoryMappingDtos = new List(); 12 | } 13 | 14 | [JsonProperty("product_category_mappings")] 15 | public IList ProductCategoryMappingDtos { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "product_category_mappings"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(ProductCategoryMappingDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductItemAttributeDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.DTO.Base; 3 | 4 | namespace Nop.Plugin.Api.DTO 5 | { 6 | [JsonObject(Title = "attribute")] 7 | public class ProductItemAttributeDto : BaseDto 8 | { 9 | [JsonProperty("value")] 10 | public string Value { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductManufacturerMappings/ProductManufacturerMappingsCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.ProductManufacturerMappings 4 | { 5 | public class ProductManufacturerMappingsCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductManufacturerMappings/ProductManufacturerMappingsDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.DTO.Base; 3 | 4 | namespace Nop.Plugin.Api.DTO.ProductManufacturerMappings 5 | { 6 | [JsonObject(Title = "product_manufacturer_mapping")] 7 | //[Validator(typeof(ProductManufacturerMappingDtoValidator))] 8 | public class ProductManufacturerMappingsDto : BaseDto 9 | { 10 | /// 11 | /// Gets or sets the product identifier 12 | /// 13 | [JsonProperty("product_id")] 14 | public int? ProductId { get; set; } 15 | 16 | /// 17 | /// Gets or sets the manufacturer identifier 18 | /// 19 | [JsonProperty("manufacturer_id")] 20 | public int? ManufacturerId { get; set; } 21 | 22 | /// 23 | /// Gets or sets a value indicating whether the product is featured 24 | /// 25 | [JsonProperty("is_featured_product")] 26 | public bool? IsFeaturedProduct { get; set; } 27 | 28 | /// 29 | /// Gets or sets the display order 30 | /// 31 | [JsonProperty("display_order")] 32 | public int? DisplayOrder { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ProductManufacturerMappings/ProductManufacturerMappingsRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.ProductManufacturerMappings 6 | { 7 | public class ProductManufacturerMappingsRootObject : ISerializableObject 8 | { 9 | public ProductManufacturerMappingsRootObject() 10 | { 11 | ProductManufacturerMappingsDtos = new List(); 12 | } 13 | 14 | [JsonProperty("product_manufacturer_mappings")] 15 | public IList ProductManufacturerMappingsDtos { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "product_manufacturer_mappings"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(ProductManufacturerMappingsDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Products/ProductAttributeCombinationDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Nop.Plugin.Api.DTO.Base; 3 | 4 | namespace Nop.Plugin.Api.DTO.Products 5 | { 6 | [JsonObject(Title = "product_attribute_combination")] 7 | //[Validator(typeof(ProductAttributeCombinationDtoValidator))] 8 | public class ProductAttributeCombinationDto : BaseDto 9 | { 10 | /// 11 | /// Gets or sets the product identifier 12 | /// 13 | [JsonProperty("product_id")] 14 | public int ProductId { get; set; } 15 | 16 | /// 17 | /// Gets or sets the attributes 18 | /// 19 | [JsonProperty("attributes_xml")] 20 | public string AttributesXml { get; set; } 21 | 22 | /// 23 | /// Gets or sets the stock quantity 24 | /// 25 | [JsonProperty("stock_quantity")] 26 | public int StockQuantity { get; set; } 27 | 28 | /// 29 | /// Gets or sets the SKU 30 | /// 31 | [JsonProperty("sku")] 32 | public string Sku { get; set; } 33 | 34 | /// 35 | /// Gets or sets the manufacturer part number 36 | /// 37 | [JsonProperty("manufacturer_part_number")] 38 | public string ManufacturerPartNumber { get; set; } 39 | 40 | /// 41 | /// Gets or sets the Global Trade Item Number (GTIN). These identifiers include UPC (in North America), EAN (in 42 | /// Europe), JAN (in Japan), and ISBN (for books). 43 | /// 44 | [JsonProperty("gtin")] 45 | public string Gtin { get; set; } 46 | 47 | /// 48 | /// Gets or sets the attribute combination price. This way a store owner can override the default product price when 49 | /// this attribute combination is added to the cart. For example, you can give a discount this way. 50 | /// 51 | [JsonProperty("overridden_price")] 52 | public decimal? OverriddenPrice { get; set; } 53 | 54 | /// 55 | /// Gets or sets the identifier of picture associated with this combination 56 | /// 57 | [JsonProperty("picture_id")] 58 | public int PictureId { get; set; } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Products/ProductsCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Nop.Plugin.Api.DTO.Products 5 | { 6 | public class ProductsCountRootObject 7 | { 8 | [JsonProperty("count")] 9 | public int Count { get; set; } 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Products/ProductsRootObjectDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Products 6 | { 7 | public class ProductsRootObjectDto : ISerializableObject 8 | { 9 | public ProductsRootObjectDto() 10 | { 11 | Products = new List(); 12 | } 13 | 14 | [JsonProperty("products")] 15 | public IList Products { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "products"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(ProductDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/ShoppingCarts/ShoppingCartItemsRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.ShoppingCarts 6 | { 7 | public class ShoppingCartItemsRootObject : ISerializableObject 8 | { 9 | public ShoppingCartItemsRootObject() 10 | { 11 | ShoppingCartItems = new List(); 12 | } 13 | 14 | [JsonProperty("shopping_carts")] 15 | public IList ShoppingCartItems { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "shopping_carts"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(ShoppingCartItemDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/SpecificationAttributes/ProductSpecificationAttributesCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.SpecificationAttributes 4 | { 5 | public class ProductSpecificationAttributesCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/SpecificationAttributes/ProductSpecificationAttributesRootObjectDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.SpecificationAttributes 6 | { 7 | public class ProductSpecificationAttributesRootObjectDto : ISerializableObject 8 | { 9 | public ProductSpecificationAttributesRootObjectDto() 10 | { 11 | ProductSpecificationAttributes = new List(); 12 | } 13 | 14 | [JsonProperty("product_specification_attributes")] 15 | public IList ProductSpecificationAttributes { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "product_specification_attributes"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(ProductSpecificationAttributeDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/SpecificationAttributes/SpecificationAttributeDto.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace Nop.Plugin.Api.DTO.SpecificationAttributes 5 | { 6 | [JsonObject(Title = "specification_attribute")] 7 | //[Validator(typeof(SpecificationAttributeDtoValidator))] 8 | public class SpecificationAttributeDto 9 | { 10 | /// 11 | /// Gets or sets the id 12 | /// 13 | [JsonProperty("id")] 14 | public int Id { get; set; } 15 | 16 | /// 17 | /// Gets or sets the name 18 | /// 19 | [JsonProperty("name")] 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Gets or sets the display order 24 | /// 25 | [JsonProperty("display_order")] 26 | public int DisplayOrder { get; set; } 27 | 28 | /// 29 | /// Gets or sets the specification attribute options 30 | /// 31 | [JsonProperty("specification_attribute_options")] 32 | public List SpecificationAttributeOptions { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/SpecificationAttributes/SpecificationAttributeOptionDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.SpecificationAttributes 4 | { 5 | [JsonObject(Title = "specification_attribute_option")] 6 | //[Validator(typeof(SpecificationAttributeOptionDtoValidator))] 7 | public class SpecificationAttributeOptionDto 8 | { 9 | /// 10 | /// Gets or sets the id 11 | /// 12 | [JsonProperty("id")] 13 | public int Id { get; set; } 14 | 15 | /// 16 | /// Gets or sets the specification attribute identifier 17 | /// 18 | [JsonProperty("specification_attribute_id")] 19 | public int SpecificationAttributeId { get; set; } 20 | 21 | /// 22 | /// Gets or sets the name 23 | /// 24 | [JsonProperty("name")] 25 | public string Name { get; set; } 26 | 27 | /// 28 | /// Gets or sets the color RGB value (used when you want to display "Color squares" instead of text) 29 | /// 30 | [JsonProperty("color_squares_rgb")] 31 | public string ColorSquaresRgb { get; set; } 32 | 33 | /// 34 | /// Gets or sets the display order 35 | /// 36 | [JsonProperty("display_order")] 37 | public int DisplayOrder { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/SpecificationAttributes/SpecificationAttributesCountRootObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.DTO.SpecificationAttributes 4 | { 5 | public class SpecificationAttributesCountRootObject 6 | { 7 | [JsonProperty("count")] 8 | public int Count { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/SpecificationAttributes/SpecificationAttributesRootObjectDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.SpecificationAttributes 6 | { 7 | public class SpecificationAttributesRootObjectDto : ISerializableObject 8 | { 9 | public SpecificationAttributesRootObjectDto() 10 | { 11 | SpecificationAttributes = new List(); 12 | } 13 | 14 | [JsonProperty("specification_attributes")] 15 | public IList SpecificationAttributes { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "specification_attributes"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(SpecificationAttributeDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DTOs/Stores/StoresRootObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.DTO.Stores 6 | { 7 | public class StoresRootObject : ISerializableObject 8 | { 9 | public StoresRootObject() 10 | { 11 | Stores = new List(); 12 | } 13 | 14 | [JsonProperty("stores")] 15 | public IList Stores { get; set; } 16 | 17 | public string GetPrimaryPropertyName() 18 | { 19 | return "stores"; 20 | } 21 | 22 | public Type GetPrimaryPropertyType() 23 | { 24 | return typeof(StoreDto); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/DataStructures/ApiList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Nop.Plugin.Api.DataStructures 5 | { 6 | public class ApiList : List 7 | { 8 | public ApiList(IQueryable source, int pageIndex, int pageSize) 9 | { 10 | PageSize = pageSize; 11 | PageIndex = pageIndex; 12 | AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList()); 13 | } 14 | 15 | public int PageIndex { get; } 16 | public int PageSize { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Domain/ApiSettings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Configuration; 2 | 3 | namespace Nop.Plugin.Api.Domain 4 | { 5 | public class ApiSettings : ISettings 6 | { 7 | public bool EnableApi { get; set; } = true; 8 | 9 | public int TokenExpiryInDays { get; set; } = 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/AddressFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Nop.Core.Domain.Common; 3 | 4 | namespace Nop.Plugin.Api.Factories 5 | { 6 | public class AddressFactory : IFactory
7 | { 8 | public Address Initialize() 9 | { 10 | var address = new Address 11 | { 12 | CreatedOnUtc = DateTime.UtcNow 13 | }; 14 | 15 | return address; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/CategoryFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Nop.Core.Domain.Catalog; 4 | using Nop.Services.Catalog; 5 | 6 | namespace Nop.Plugin.Api.Factories 7 | { 8 | public class CategoryFactory : IFactory 9 | { 10 | private readonly CatalogSettings _catalogSettings; 11 | private readonly ICategoryTemplateService _categoryTemplateService; 12 | 13 | public CategoryFactory(ICategoryTemplateService categoryTemplateService, CatalogSettings catalogSettings) 14 | { 15 | _categoryTemplateService = categoryTemplateService; 16 | _catalogSettings = catalogSettings; 17 | } 18 | 19 | public Category Initialize() 20 | { 21 | // TODO: cache the default entity. 22 | var defaultCategory = new Category(); 23 | 24 | // Set the first template as the default one. 25 | var firstTemplate = _categoryTemplateService.GetAllCategoryTemplates().FirstOrDefault(); 26 | 27 | if (firstTemplate != null) 28 | { 29 | defaultCategory.CategoryTemplateId = firstTemplate.Id; 30 | } 31 | 32 | //default values 33 | defaultCategory.PageSize = _catalogSettings.DefaultCategoryPageSize; 34 | defaultCategory.PageSizeOptions = _catalogSettings.DefaultCategoryPageSizeOptions; 35 | defaultCategory.Published = true; 36 | defaultCategory.IncludeInTopMenu = true; 37 | defaultCategory.AllowCustomersToSelectPageSize = true; 38 | 39 | defaultCategory.CreatedOnUtc = DateTime.UtcNow; 40 | defaultCategory.UpdatedOnUtc = DateTime.UtcNow; 41 | 42 | return defaultCategory; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/CustomerFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Nop.Core.Domain.Customers; 3 | 4 | namespace Nop.Plugin.Api.Factories 5 | { 6 | public class CustomerFactory : IFactory 7 | { 8 | public Customer Initialize() 9 | { 10 | var defaultCustomer = new Customer 11 | { 12 | CustomerGuid = Guid.NewGuid(), 13 | CreatedOnUtc = DateTime.UtcNow, 14 | LastActivityDateUtc = DateTime.UtcNow, 15 | Active = true 16 | }; 17 | 18 | return defaultCustomer; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/IFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Nop.Plugin.Api.Factories 2 | { 3 | public interface IFactory 4 | { 5 | T Initialize(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/ManufacturerFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Nop.Core.Domain.Catalog; 3 | 4 | namespace Nop.Plugin.Api.Factories 5 | { 6 | public class ManufacturerFactory : IFactory 7 | { 8 | private readonly CatalogSettings _catalogSettings; 9 | 10 | public ManufacturerFactory(CatalogSettings catalogSettings) 11 | { 12 | _catalogSettings = catalogSettings; 13 | } 14 | 15 | public Manufacturer Initialize() 16 | { 17 | // TODO: cache the default entity. 18 | var defaultManufacturer = new Manufacturer(); 19 | 20 | //default values 21 | defaultManufacturer.PageSize = _catalogSettings.DefaultManufacturerPageSize; 22 | defaultManufacturer.PageSizeOptions = _catalogSettings.DefaultManufacturerPageSizeOptions; 23 | defaultManufacturer.Published = true; 24 | defaultManufacturer.AllowCustomersToSelectPageSize = true; 25 | 26 | defaultManufacturer.CreatedOnUtc = DateTime.UtcNow; 27 | defaultManufacturer.UpdatedOnUtc = DateTime.UtcNow; 28 | 29 | return defaultManufacturer; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/OrderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Nop.Core.Domain.Orders; 3 | using Nop.Core.Domain.Payments; 4 | using Nop.Core.Domain.Shipping; 5 | 6 | namespace Nop.Plugin.Api.Factories 7 | { 8 | public class OrderFactory : IFactory 9 | { 10 | public Order Initialize() 11 | { 12 | var order = new Order(); 13 | 14 | order.CreatedOnUtc = DateTime.UtcNow; 15 | order.OrderGuid = new Guid(); 16 | order.PaymentStatus = PaymentStatus.Pending; 17 | order.ShippingStatus = ShippingStatus.NotYetShipped; 18 | order.OrderStatus = OrderStatus.Pending; 19 | 20 | return order; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/ProductFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Nop.Core.Domain.Catalog; 3 | using Nop.Core.Domain.Directory; 4 | using Nop.Services.Directory; 5 | 6 | namespace Nop.Plugin.Api.Factories 7 | { 8 | public class ProductFactory : IFactory 9 | { 10 | private readonly IMeasureService _measureService; 11 | private readonly MeasureSettings _measureSettings; 12 | 13 | public ProductFactory(IMeasureService measureService, MeasureSettings measureSettings) 14 | { 15 | _measureService = measureService; 16 | _measureSettings = measureSettings; 17 | } 18 | 19 | public Product Initialize() 20 | { 21 | var defaultProduct = new Product(); 22 | 23 | defaultProduct.Weight = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Ratio; 24 | 25 | defaultProduct.CreatedOnUtc = DateTime.UtcNow; 26 | defaultProduct.UpdatedOnUtc = DateTime.UtcNow; 27 | 28 | defaultProduct.ProductType = ProductType.SimpleProduct; 29 | 30 | defaultProduct.MaximumCustomerEnteredPrice = 1000; 31 | defaultProduct.MaxNumberOfDownloads = 10; 32 | defaultProduct.RecurringCycleLength = 100; 33 | defaultProduct.RecurringTotalCycles = 10; 34 | defaultProduct.RentalPriceLength = 1; 35 | defaultProduct.StockQuantity = 10000; 36 | defaultProduct.NotifyAdminForQuantityBelow = 1; 37 | defaultProduct.OrderMinimumQuantity = 1; 38 | defaultProduct.OrderMaximumQuantity = 10000; 39 | 40 | defaultProduct.UnlimitedDownloads = true; 41 | defaultProduct.IsShipEnabled = true; 42 | defaultProduct.AllowCustomerReviews = true; 43 | defaultProduct.Published = true; 44 | defaultProduct.VisibleIndividually = true; 45 | 46 | return defaultProduct; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Factories/ShoppingCartItemFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Nop.Core.Domain.Orders; 3 | 4 | namespace Nop.Plugin.Api.Factories 5 | { 6 | public class ShoppingCartItemFactory : IFactory 7 | { 8 | public ShoppingCartItem Initialize() 9 | { 10 | var newShoppingCartItem = new ShoppingCartItem(); 11 | 12 | newShoppingCartItem.CreatedOnUtc = DateTime.UtcNow; 13 | newShoppingCartItem.UpdatedOnUtc = DateTime.UtcNow; 14 | 15 | return newShoppingCartItem; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Helpers/CustomerRolesHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Nop.Core.Caching; 4 | using Nop.Core.Domain.Customers; 5 | using Nop.Services.Customers; 6 | 7 | namespace Nop.Plugin.Api.Helpers 8 | { 9 | public class CustomerRolesHelper : ICustomerRolesHelper 10 | { 11 | private const string CUSTOMERROLES_ALL_KEY = "Nop.customerrole.all-{0}"; 12 | private readonly IStaticCacheManager _cacheManager; 13 | 14 | private readonly ICustomerService _customerService; 15 | 16 | public CustomerRolesHelper(ICustomerService customerService, IStaticCacheManager cacheManager) 17 | { 18 | _customerService = customerService; 19 | _cacheManager = cacheManager; 20 | } 21 | 22 | public IList GetValidCustomerRoles(List roleIds) 23 | { 24 | // This is needed because the caching messes up the entity framework context 25 | // and when you try to send something TO the database it throws an exception. 26 | _cacheManager.RemoveByPrefix(CUSTOMERROLES_ALL_KEY); 27 | 28 | var allCustomerRoles = _customerService.GetAllCustomerRoles(true); 29 | var newCustomerRoles = new List(); 30 | foreach (var customerRole in allCustomerRoles) 31 | { 32 | if (roleIds != null && roleIds.Contains(customerRole.Id)) 33 | { 34 | newCustomerRoles.Add(customerRole); 35 | } 36 | } 37 | 38 | return newCustomerRoles; 39 | } 40 | 41 | public bool IsInGuestsRole(IList customerRoles) 42 | { 43 | return customerRoles.FirstOrDefault(cr => cr.SystemName == NopCustomerDefaults.GuestsRoleName) != null; 44 | } 45 | 46 | public bool IsInRegisteredRole(IList customerRoles) 47 | { 48 | return customerRoles.FirstOrDefault(cr => cr.SystemName == NopCustomerDefaults.RegisteredRoleName) != null; 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Helpers/ICustomerRolesHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Core.Domain.Customers; 3 | 4 | namespace Nop.Plugin.Api.Helpers 5 | { 6 | public interface ICustomerRolesHelper 7 | { 8 | IList GetValidCustomerRoles(List roleIds); 9 | bool IsInGuestsRole(IList customerRoles); 10 | bool IsInRegisteredRole(IList customerRoles); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Helpers/IDTOHelper.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Core.Domain.Localization; 3 | using Nop.Core.Domain.Orders; 4 | using Nop.Core.Domain.Stores; 5 | using Nop.Plugin.Api.DTO.Categories; 6 | using Nop.Plugin.Api.DTO.Languages; 7 | using Nop.Plugin.Api.DTO.Manufacturers; 8 | using Nop.Plugin.Api.DTO.OrderItems; 9 | using Nop.Plugin.Api.DTO.Orders; 10 | using Nop.Plugin.Api.DTO.ProductAttributes; 11 | using Nop.Plugin.Api.DTO.Products; 12 | using Nop.Plugin.Api.DTO.ShoppingCarts; 13 | using Nop.Plugin.Api.DTO.SpecificationAttributes; 14 | using Nop.Plugin.Api.DTO.Stores; 15 | 16 | namespace Nop.Plugin.Api.Helpers 17 | { 18 | public interface IDTOHelper 19 | { 20 | ProductDto PrepareProductDTO(Product product); 21 | CategoryDto PrepareCategoryDTO(Category category); 22 | OrderDto PrepareOrderDTO(Order order); 23 | ShoppingCartItemDto PrepareShoppingCartItemDTO(ShoppingCartItem shoppingCartItem); 24 | OrderItemDto PrepareOrderItemDTO(OrderItem orderItem); 25 | StoreDto PrepareStoreDTO(Store store); 26 | LanguageDto PrepareLanguageDto(Language language); 27 | ProductAttributeDto PrepareProductAttributeDTO(ProductAttribute productAttribute); 28 | ProductSpecificationAttributeDto PrepareProductSpecificationAttributeDto(ProductSpecificationAttribute productSpecificationAttribute); 29 | SpecificationAttributeDto PrepareSpecificationAttributeDto(SpecificationAttribute specificationAttribute); 30 | ManufacturerDto PrepareManufacturerDto(Manufacturer manufacturer); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Helpers/IJsonHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | 4 | namespace Nop.Plugin.Api.Helpers 5 | { 6 | public interface IJsonHelper 7 | { 8 | Dictionary GetRequestJsonDictionaryFromStream(Stream stream, bool rewindStream); 9 | string GetRootPropertyName() where T : class, new(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Helpers/IMappingHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Nop.Plugin.Api.Helpers 5 | { 6 | public interface IMappingHelper 7 | { 8 | void SetValues( 9 | Dictionary propertyNameValuePairs, object objectToBeUpdated, Type objectToBeUpdatedType, 10 | Dictionary objectPropertyNameValuePairs, bool handleComplexTypeCollections = false); 11 | 12 | void Merge(object source, object destination); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Helpers/ReflectionHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using Newtonsoft.Json; 4 | 5 | namespace Nop.Plugin.Api.Helpers 6 | { 7 | public static class ReflectionHelper 8 | { 9 | public static bool HasProperty(string propertyName, Type type) 10 | { 11 | return type.GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null; 12 | } 13 | 14 | public static JsonObjectAttribute GetJsonObjectAttribute(Type objectType) 15 | { 16 | var jsonObject = objectType.GetCustomAttribute(typeof(JsonObjectAttribute)) as JsonObjectAttribute; 17 | 18 | return jsonObject; 19 | } 20 | 21 | public static Type GetGenericElementType(Type type) 22 | { 23 | return type.HasElementType 24 | ? type.GetElementType() 25 | : type.GetTypeInfo().GenericTypeArguments[0]; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Infrastructure/Constants.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Caching; 2 | 3 | namespace Nop.Plugin.Api.Infrastructure 4 | { 5 | public static class Constants 6 | { 7 | public static class Roles 8 | { 9 | public const string ApiRoleSystemName = "ApiUserRole"; 10 | 11 | public const string ApiRoleName = "Api Users"; 12 | } 13 | 14 | public static class ViewNames 15 | { 16 | public const string AdminLayout = "_AdminLayout"; 17 | } 18 | 19 | public static class Configurations 20 | { 21 | public const int DefaultAccessTokenExpirationInDays = 3650; // 10 years 22 | 23 | // time is in seconds (10 years = 315360000 seconds) and should not exceed 2038 year 24 | // https://stackoverflow.com/questions/43593074/jwt-validation-fails/43605820 25 | //public const int DefaultAccessTokenExpiration = 315360000; 26 | //public const int DefaultRefreshTokenExpiration = int.MaxValue; 27 | public const int DefaultLimit = 50; 28 | public const int DefaultPageValue = 1; 29 | public const int DefaultSinceId = 0; 30 | public const int DefaultCustomerId = 0; 31 | public const string DefaultOrder = "Id"; 32 | public const int MaxLimit = 250; 33 | 34 | public const int MinLimit = 1; 35 | 36 | //public const string PublishedStatus = "published"; 37 | //public const string UnpublishedStatus = "unpublished"; 38 | //public const string AnyStatus = "any"; 39 | public static CacheKey JsonTypeMapsPattern => new CacheKey("json.maps"); 40 | 41 | public static CacheKey NEWSLETTER_SUBSCRIBERS_KEY = new CacheKey("Nop.api.newslettersubscribers"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/JSON/ActionResults/ErrorActionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.AspNetCore.WebUtilities; 8 | 9 | namespace Nop.Plugin.Api.JSON.ActionResults 10 | { 11 | public class ErrorActionResult : ActionResult 12 | { 13 | private readonly string _jsonString; 14 | private readonly HttpStatusCode _statusCode; 15 | 16 | public ErrorActionResult(string jsonString, HttpStatusCode statusCode) 17 | { 18 | _jsonString = jsonString; 19 | _statusCode = statusCode; 20 | } 21 | 22 | public override void ExecuteResult(ActionContext context) 23 | { 24 | if (context == null) 25 | { 26 | throw new ArgumentNullException(nameof(context)); 27 | } 28 | 29 | var response = context.HttpContext.Response; 30 | response.StatusCode = (int) _statusCode; 31 | response.ContentType = "application/json"; 32 | using (TextWriter writer = new HttpResponseStreamWriter(response.Body, Encoding.UTF8)) 33 | { 34 | writer.Write(_jsonString); 35 | } 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/JSON/ActionResults/RawJsonActionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.AspNetCore.WebUtilities; 8 | 9 | namespace Nop.Plugin.Api.JSON.ActionResults 10 | { 11 | // TODO: Move to BaseApiController as method. 12 | public class RawJsonActionResult : ActionResult 13 | { 14 | private readonly string _jsonString; 15 | 16 | public RawJsonActionResult(object value) 17 | { 18 | if (value != null) 19 | { 20 | _jsonString = value.ToString(); 21 | } 22 | } 23 | 24 | public override async Task ExecuteResultAsync(ActionContext context) 25 | { 26 | if (context == null) 27 | { 28 | throw new ArgumentNullException(nameof(context)); 29 | } 30 | 31 | var response = context.HttpContext.Response; 32 | 33 | response.StatusCode = 200; 34 | response.ContentType = "application/json"; 35 | 36 | await response.WriteAsync(_jsonString); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/JSON/Serializers/IJsonFieldsSerializer.cs: -------------------------------------------------------------------------------- 1 | using Nop.Plugin.Api.DTO; 2 | 3 | namespace Nop.Plugin.Api.JSON.Serializers 4 | { 5 | public interface IJsonFieldsSerializer 6 | { 7 | string Serialize(ISerializableObject objectToSerialize, string fields); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/JSON/Serializers/JsonFieldsSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Newtonsoft.Json.Linq; 5 | using Nop.Plugin.Api.DTO; 6 | using Nop.Plugin.Api.Helpers; 7 | 8 | namespace Nop.Plugin.Api.JSON.Serializers 9 | { 10 | public class JsonFieldsSerializer : IJsonFieldsSerializer 11 | { 12 | public string Serialize(ISerializableObject objectToSerialize, string jsonFields) 13 | { 14 | if (objectToSerialize == null) 15 | { 16 | throw new ArgumentNullException(nameof(objectToSerialize)); 17 | } 18 | 19 | IList fieldsList = null; 20 | 21 | if (!string.IsNullOrEmpty(jsonFields)) 22 | { 23 | var primaryPropertyName = objectToSerialize.GetPrimaryPropertyName(); 24 | 25 | fieldsList = GetPropertiesIntoList(jsonFields); 26 | 27 | // Always add the root manually 28 | fieldsList.Add(primaryPropertyName); 29 | } 30 | 31 | var json = Serialize(objectToSerialize, fieldsList); 32 | 33 | return json; 34 | } 35 | 36 | private string Serialize(object objectToSerialize, IList jsonFields = null) 37 | { 38 | var jToken = JToken.FromObject(objectToSerialize); 39 | 40 | if (jsonFields != null) 41 | { 42 | jToken = jToken.RemoveEmptyChildrenAndFilterByFields(jsonFields); 43 | } 44 | 45 | var jTokenResult = jToken.ToString(); 46 | 47 | return jTokenResult; 48 | } 49 | 50 | private IList GetPropertiesIntoList(string fields) 51 | { 52 | IList properties = fields.ToLowerInvariant() 53 | .Split(new[] 54 | { 55 | ',' 56 | }, StringSplitOptions.RemoveEmptyEntries) 57 | .Select(x => x.Trim()) 58 | .Distinct() 59 | .ToList(); 60 | 61 | return properties; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/AddressDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Common; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class AddressDtoMappings 8 | { 9 | public static AddressDto ToDto(this Address address) 10 | { 11 | return address.MapTo(); 12 | } 13 | 14 | public static Address ToEntity(this AddressDto addressDto) 15 | { 16 | return addressDto.MapTo(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/BaseMapping.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using AutoMapper; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class BaseMapping 8 | { 9 | public static IMappingExpression IgnoreAllNonExisting( 10 | this IMappingExpression expression) 11 | { 12 | var flags = BindingFlags.Public | BindingFlags.Instance; 13 | var sourceType = typeof(TSource); 14 | var destinationProperties = typeof(TDestination).GetProperties(flags); 15 | 16 | foreach (var property in destinationProperties) 17 | { 18 | if (sourceType.GetProperty(property.Name, flags) == null) 19 | { 20 | expression.ForMember(property.Name, opt => opt.Ignore()); 21 | } 22 | } 23 | return expression; 24 | } 25 | 26 | public static TResult GetWithDefault( 27 | this TSource instance, 28 | Func getter, 29 | TResult defaultValue = default(TResult)) 30 | where TSource : class 31 | { 32 | return instance != null 33 | ? getter(instance) 34 | : defaultValue; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/CategoryDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Categories; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class CategoryDtoMappings 8 | { 9 | public static CategoryDto ToDto(this Category category) 10 | { 11 | return category.MapTo(); 12 | } 13 | 14 | public static Category ToEntity(this CategoryDto categoryDto) 15 | { 16 | return categoryDto.MapTo(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ConfigurationMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Plugin.Api.Areas.Admin.Models; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.Domain; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ConfigurationMappings 8 | { 9 | public static ConfigurationModel ToModel(this ApiSettings apiSettings) 10 | { 11 | return apiSettings.MapTo(); 12 | } 13 | 14 | public static ApiSettings ToEntity(this ConfigurationModel apiSettingsModel) 15 | { 16 | return apiSettingsModel.MapTo(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/CustomerDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Customers; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Customers; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class CustomerDtoMappings 8 | { 9 | public static CustomerDto ToDto(this Customer customer) 10 | { 11 | return customer.MapTo(); 12 | } 13 | 14 | public static OrderCustomerDto ToOrderCustomerDto(this Customer customer) 15 | { 16 | return customer.MapTo(); 17 | } 18 | 19 | public static OrderCustomerDto ToOrderCustomerDto(this CustomerDto customerDto) 20 | { 21 | return customerDto.MapTo(); 22 | } 23 | 24 | public static CustomerForShoppingCartItemDto ToCustomerForShoppingCartItemDto(this Customer customer) 25 | { 26 | return customer.MapTo(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/CustomerRoleDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Customers; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.CustomerRoles; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class CustomerRoleDtoMappings 8 | { 9 | public static CustomerRoleDto ToDto(this CustomerRole customerRole) 10 | { 11 | return customerRole.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/LanguageDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Localization; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Languages; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class LanguageDtoMappings 8 | { 9 | public static LanguageDto ToDto(this Language language) 10 | { 11 | return language.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ManufacturerDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Manufacturers; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ManufacturerDtoMappings 8 | { 9 | public static ManufacturerDto ToDto(this Manufacturer manufacturer) 10 | { 11 | return manufacturer.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/NewsLetterSubscriptoonDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Messages; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.NewsLetterSubscriptions; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class NewsLetterSubscriptoonDtoMappings 8 | { 9 | public static NewsLetterSubscriptionDto ToDto(this NewsLetterSubscription newsLetterSubscription) 10 | { 11 | return newsLetterSubscription.MapTo(); 12 | } 13 | 14 | public static NewsLetterSubscription ToEntity(this NewsLetterSubscriptionDto newsLetterSubscriptionDto) 15 | { 16 | return newsLetterSubscriptionDto.MapTo(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/OrderDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Orders; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Orders; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class OrderDtoMappings 8 | { 9 | public static OrderDto ToDto(this Order order) 10 | { 11 | return order.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/OrderItemDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Orders; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.OrderItems; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class OrderItemDtoMappings 8 | { 9 | public static OrderItemDto ToDto(this OrderItem orderItem) 10 | { 11 | return orderItem.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ProductAttributeCombinationDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Products; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ProductAttributeCombinationDtoMappings 8 | { 9 | public static ProductAttributeCombinationDto ToDto(this ProductAttributeCombination productAttributeCombination) 10 | { 11 | return productAttributeCombination.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ProductAttributeDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.ProductAttributes; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ProductAttributeDtoMappings 8 | { 9 | public static ProductAttributeDto ToDto(this ProductAttribute productAttribute) 10 | { 11 | return productAttribute.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ProductCategoryMappingDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.ProductCategoryMappings; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ProductCategoryMappingDtoMappings 8 | { 9 | public static ProductCategoryMappingDto ToDto(this ProductCategory mapping) 10 | { 11 | return mapping.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ProductDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Products; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ProductDtoMappings 8 | { 9 | public static ProductDto ToDto(this Product product) 10 | { 11 | return product.MapTo(); 12 | } 13 | 14 | public static ProductAttributeValueDto ToDto(this ProductAttributeValue productAttributeValue) 15 | { 16 | return productAttributeValue.MapTo(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ProductManufacturerMappingDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.ProductManufacturerMappings; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ProductManufacturerMappingDtoMappings 8 | { 9 | public static ProductManufacturerMappingsDto ToDto(this ProductManufacturer mapping) 10 | { 11 | return mapping.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/ShoppingCartItemDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Orders; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.ShoppingCarts; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class ShoppingCartItemDtoMappings 8 | { 9 | public static ShoppingCartItemDto ToDto(this ShoppingCartItem shoppingCartItem) 10 | { 11 | return shoppingCartItem.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/SpecificationAttributeDtoMapping.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.SpecificationAttributes; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class SpecificationAttributeDtoMappings 8 | { 9 | public static ProductSpecificationAttributeDto ToDto(this ProductSpecificationAttribute productSpecificationAttribute) 10 | { 11 | return productSpecificationAttribute.MapTo(); 12 | } 13 | 14 | public static SpecificationAttributeDto ToDto(this SpecificationAttribute specificationAttribute) 15 | { 16 | return specificationAttribute.MapTo(); 17 | } 18 | 19 | public static SpecificationAttributeOptionDto ToDto(this SpecificationAttributeOption specificationAttributeOption) 20 | { 21 | return specificationAttributeOption.MapTo(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/MappingExtensions/StoreDtoMappings.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Stores; 2 | using Nop.Plugin.Api.AutoMapper; 3 | using Nop.Plugin.Api.DTO.Stores; 4 | 5 | namespace Nop.Plugin.Api.MappingExtensions 6 | { 7 | public static class StoreDtoMappings 8 | { 9 | public static StoreDto ToDto(this Store store) 10 | { 11 | return store.MapTo(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Maps/IJsonPropertyMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Nop.Plugin.Api.Maps 5 | { 6 | public interface IJsonPropertyMapper 7 | { 8 | Dictionary> GetMap(Type type); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/ModelBinders/ParametersModelBinder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | using Microsoft.AspNetCore.Mvc.ModelBinding; 5 | using Nop.Plugin.Api.Converters; 6 | 7 | namespace Nop.Plugin.Api.ModelBinders 8 | { 9 | public class ParametersModelBinder : IModelBinder where T : class, new() 10 | { 11 | private readonly IObjectConverter _objectConverter; 12 | 13 | public ParametersModelBinder(IObjectConverter objectConverter) 14 | { 15 | _objectConverter = objectConverter; 16 | } 17 | 18 | public Task BindModelAsync(ModelBindingContext bindingContext) 19 | { 20 | if (bindingContext == null) 21 | { 22 | throw new ArgumentNullException(nameof(bindingContext)); 23 | } 24 | 25 | if (bindingContext.HttpContext.Request.QueryString.HasValue) 26 | { 27 | var queryParameters = bindingContext.HttpContext.Request.Query.ToDictionary(pair => pair.Key, pair => pair.Value.ToString()); 28 | 29 | bindingContext.Model = _objectConverter.ToObject(queryParameters); 30 | } 31 | else 32 | { 33 | bindingContext.Model = new T(); 34 | } 35 | 36 | bindingContext.Result = ModelBindingResult.Success(bindingContext.Model); 37 | 38 | // This should be true otherwise the model will be null. 39 | return Task.CompletedTask; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/Authentication/TokenRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Nop.Plugin.Api.Models.Authentication 2 | { 3 | public class TokenRequest 4 | { 5 | public string Username { get; set; } 6 | 7 | public string Password { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/Authentication/TokenResponse.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.Models.Authentication 4 | { 5 | public class TokenResponse 6 | { 7 | public TokenResponse(string errorDescription) 8 | { 9 | ErrorDescription = errorDescription; 10 | } 11 | 12 | public TokenResponse(string accessToken, long expiresInSeconds, string tokenType = "Bearer") 13 | { 14 | AccessToken = accessToken; 15 | ExpiresInSeconds = expiresInSeconds; 16 | TokenType = tokenType; 17 | } 18 | 19 | [JsonProperty("access_token")] 20 | public string AccessToken { get; set; } 21 | 22 | [JsonProperty("token_type")] 23 | public string TokenType { get; set; } = "Bearer"; 24 | 25 | [JsonProperty("expires_in")] 26 | public long ExpiresInSeconds { get; set; } 27 | 28 | [JsonProperty("error_description")] 29 | public string ErrorDescription { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/CategoriesParameters/BaseCategoriesParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Nop.Plugin.Api.Models.CategoriesParameters 5 | { 6 | // JsonProperty is used only for swagger 7 | public class BaseCategoriesParametersModel 8 | { 9 | public BaseCategoriesParametersModel() 10 | { 11 | ProductId = null; 12 | CreatedAtMin = null; 13 | CreatedAtMax = null; 14 | UpdatedAtMin = null; 15 | UpdatedAtMax = null; 16 | PublishedStatus = null; 17 | } 18 | 19 | /// 20 | /// Show categories created after date (format: 2008-12-31 03:00) 21 | /// 22 | [JsonProperty("created_at_min")] 23 | public DateTime? CreatedAtMin { get; set; } 24 | 25 | /// 26 | /// Show categories created before date (format: 2008-12-31 03:00) 27 | /// 28 | [JsonProperty("created_at_max")] 29 | public DateTime? CreatedAtMax { get; set; } 30 | 31 | /// 32 | /// Show categories last updated after date (format: 2008-12-31 03:00) 33 | /// 34 | [JsonProperty("updated_at_min")] 35 | public DateTime? UpdatedAtMin { get; set; } 36 | 37 | /// 38 | /// Show categories last updated before date (format: 2008-12-31 03:00) 39 | /// 40 | [JsonProperty("updated_at_max")] 41 | public DateTime? UpdatedAtMax { get; set; } 42 | 43 | /// 44 | ///
    45 | ///
  • published - Show only published categories
  • 46 | ///
  • unpublished - Show only unpublished categories
  • 47 | ///
  • any - Show all categories(default)
  • 48 | ///
49 | ///
50 | [JsonProperty("published_status")] 51 | public bool? PublishedStatus { get; set; } 52 | 53 | /// 54 | /// Show only the categories to which the product is mapped to 55 | /// 56 | [JsonProperty("product_id")] 57 | public int? ProductId { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/CategoriesParameters/CategoriesCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.CategoriesParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class CategoriesCountParametersModel : BaseCategoriesParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/CategoriesParameters/CategoriesParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.Infrastructure; 5 | using Nop.Plugin.Api.ModelBinders; 6 | 7 | namespace Nop.Plugin.Api.Models.CategoriesParameters 8 | { 9 | // JsonProperty is used only for swagger 10 | [ModelBinder(typeof(ParametersModelBinder))] 11 | public class CategoriesParametersModel : BaseCategoriesParametersModel 12 | { 13 | public CategoriesParametersModel() 14 | { 15 | Ids = null; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Page = Constants.Configurations.DefaultPageValue; 18 | SinceId = Constants.Configurations.DefaultSinceId; 19 | Fields = string.Empty; 20 | } 21 | 22 | /// 23 | /// A comma-separated list of category ids 24 | /// 25 | [JsonProperty("ids")] 26 | public List Ids { get; set; } 27 | 28 | /// 29 | /// Amount of results (default: 50) (maximum: 250) 30 | /// 31 | [JsonProperty("limit")] 32 | public int Limit { get; set; } 33 | 34 | /// 35 | /// Page to show (default: 1) 36 | /// 37 | [JsonProperty("page")] 38 | public int Page { get; set; } 39 | 40 | /// 41 | /// Restrict results to after the specified ID 42 | /// 43 | [JsonProperty("since_id")] 44 | public int SinceId { get; set; } 45 | 46 | /// 47 | /// comma-separated list of fields to include in the response 48 | /// 49 | [JsonProperty("fields")] 50 | public string Fields { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/CustomersParameters/CustomersParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.Infrastructure; 5 | using Nop.Plugin.Api.ModelBinders; 6 | 7 | namespace Nop.Plugin.Api.Models.CustomersParameters 8 | { 9 | // JsonProperty is used only for swagger 10 | [ModelBinder(typeof(ParametersModelBinder))] 11 | public class CustomersParametersModel 12 | { 13 | public CustomersParametersModel() 14 | { 15 | Limit = Constants.Configurations.DefaultLimit; 16 | Page = Constants.Configurations.DefaultPageValue; 17 | SinceId = 0; 18 | Fields = string.Empty; 19 | CreatedAtMax = null; 20 | CreatedAtMin = null; 21 | } 22 | 23 | /// 24 | /// Amount of results (default: 50) (maximum: 250) 25 | /// 26 | [JsonProperty("limit")] 27 | public int Limit { get; set; } 28 | 29 | /// 30 | /// Page to show (default: 1) 31 | /// 32 | [JsonProperty("page")] 33 | public int Page { get; set; } 34 | 35 | /// 36 | /// Restrict results to after the specified ID 37 | /// 38 | [JsonProperty("since_id")] 39 | public int SinceId { get; set; } 40 | 41 | /// 42 | /// Comma-separated list of fields to include in the response 43 | /// 44 | [JsonProperty("fields")] 45 | public string Fields { get; set; } 46 | 47 | /// 48 | /// Show customers created after date (format: 2008-12-31 03:00) 49 | /// 50 | [JsonProperty("created_at_min")] 51 | public DateTime? CreatedAtMin { get; set; } 52 | 53 | /// 54 | /// Show customers created before date (format: 2008-12-31 03:00) 55 | /// 56 | [JsonProperty("created_at_max")] 57 | public DateTime? CreatedAtMax { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/CustomersParameters/CustomersSearchParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Infrastructure; 4 | using Nop.Plugin.Api.ModelBinders; 5 | 6 | namespace Nop.Plugin.Api.Models.CustomersParameters 7 | { 8 | // JsonProperty is used only for swagger 9 | [ModelBinder(typeof(ParametersModelBinder))] 10 | public class CustomersSearchParametersModel 11 | { 12 | public CustomersSearchParametersModel() 13 | { 14 | Order = "Id"; 15 | Query = string.Empty; 16 | Page = Constants.Configurations.DefaultPageValue; 17 | Limit = Constants.Configurations.DefaultLimit; 18 | Fields = string.Empty; 19 | } 20 | 21 | /// 22 | /// Field and direction to order results by (default: id DESC) 23 | /// 24 | [JsonProperty("order")] 25 | public string Order { get; set; } 26 | 27 | /// 28 | /// Text to search customers 29 | /// 30 | [JsonProperty("query")] 31 | public string Query { get; set; } 32 | 33 | /// 34 | /// Page to show (default: 1) 35 | /// 36 | [JsonProperty("page")] 37 | public int Page { get; set; } 38 | 39 | /// 40 | /// Amount of results (default: 50) (maximum: 250) 41 | /// 42 | [JsonProperty("limit")] 43 | public int Limit { get; set; } 44 | 45 | /// 46 | /// Comma-separated list of fields to include in the response 47 | /// 48 | [JsonProperty("fields")] 49 | public string Fields { get; set; } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/DefaultWebApiErrorsModel.cs: -------------------------------------------------------------------------------- 1 | namespace Nop.Plugin.Api.Models 2 | { 3 | public class DefaultWebApiErrorsModel 4 | { 5 | public string Message { get; set; } 6 | 7 | public string MessageDetail { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ManufacturersParameters/BaseManufacturersParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Nop.Plugin.Api.Models.ManufacturersParameters 5 | { 6 | // JsonProperty is used only for swagger 7 | public class BaseManufacturersParametersModel 8 | { 9 | public BaseManufacturersParametersModel() 10 | { 11 | ProductId = null; 12 | CreatedAtMin = null; 13 | CreatedAtMax = null; 14 | UpdatedAtMin = null; 15 | UpdatedAtMax = null; 16 | PublishedStatus = null; 17 | } 18 | 19 | /// 20 | /// Show categories created after date (format: 2008-12-31 03:00) 21 | /// 22 | [JsonProperty("created_at_min")] 23 | public DateTime? CreatedAtMin { get; set; } 24 | 25 | /// 26 | /// Show categories created before date (format: 2008-12-31 03:00) 27 | /// 28 | [JsonProperty("created_at_max")] 29 | public DateTime? CreatedAtMax { get; set; } 30 | 31 | /// 32 | /// Show categories last updated after date (format: 2008-12-31 03:00) 33 | /// 34 | [JsonProperty("updated_at_min")] 35 | public DateTime? UpdatedAtMin { get; set; } 36 | 37 | /// 38 | /// Show categories last updated before date (format: 2008-12-31 03:00) 39 | /// 40 | [JsonProperty("updated_at_max")] 41 | public DateTime? UpdatedAtMax { get; set; } 42 | 43 | /// 44 | ///
    45 | ///
  • published - Show only published categories
  • 46 | ///
  • unpublished - Show only unpublished categories
  • 47 | ///
  • any - Show all categories(default)
  • 48 | ///
49 | ///
50 | [JsonProperty("published_status")] 51 | public bool? PublishedStatus { get; set; } 52 | 53 | /// 54 | /// Show only the categories to which the product is mapped to 55 | /// 56 | [JsonProperty("product_id")] 57 | public int? ProductId { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ManufacturersParameters/ManufacturersCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.ManufacturersParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class ManufacturersCountParametersModel : BaseManufacturersParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ManufacturersParameters/ManufacturersParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.Infrastructure; 5 | using Nop.Plugin.Api.ModelBinders; 6 | 7 | namespace Nop.Plugin.Api.Models.ManufacturersParameters 8 | { 9 | // JsonProperty is used only for swagger 10 | [ModelBinder(typeof(ParametersModelBinder))] 11 | public class ManufacturersParametersModel : BaseManufacturersParametersModel 12 | { 13 | public ManufacturersParametersModel() 14 | { 15 | Ids = null; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Page = Constants.Configurations.DefaultPageValue; 18 | SinceId = Constants.Configurations.DefaultSinceId; 19 | Fields = string.Empty; 20 | } 21 | 22 | /// 23 | /// A comma-separated list of manufacturer ids 24 | /// 25 | [JsonProperty("ids")] 26 | public List Ids { get; set; } 27 | 28 | /// 29 | /// Amount of results (default: 50) (maximum: 250) 30 | /// 31 | [JsonProperty("limit")] 32 | public int Limit { get; set; } 33 | 34 | /// 35 | /// Page to show (default: 1) 36 | /// 37 | [JsonProperty("page")] 38 | public int Page { get; set; } 39 | 40 | /// 41 | /// Restrict results to after the specified ID 42 | /// 43 | [JsonProperty("since_id")] 44 | public int SinceId { get; set; } 45 | 46 | /// 47 | /// comma-separated list of fields to include in the response 48 | /// 49 | [JsonProperty("fields")] 50 | public string Fields { get; set; } 51 | 52 | /// 53 | /// comma-separated list of fields to include in the response 54 | /// 55 | [JsonProperty("languageid")] 56 | public int? LanguageId { get; set; } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/NewsLetterSubscriptionsParameters/NewsLetterSubscriptionsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.Infrastructure; 5 | using Nop.Plugin.Api.ModelBinders; 6 | 7 | namespace Nop.Plugin.Api.Models.NewsLetterSubscriptionsParameters 8 | { 9 | // JsonProperty is used only for swagger 10 | [ModelBinder(typeof(ParametersModelBinder))] 11 | public class NewsLetterSubscriptionsParametersModel 12 | { 13 | public NewsLetterSubscriptionsParametersModel() 14 | { 15 | Limit = Constants.Configurations.DefaultLimit; 16 | Page = Constants.Configurations.DefaultPageValue; 17 | SinceId = 0; 18 | Fields = string.Empty; 19 | CreatedAtMax = null; 20 | CreatedAtMin = null; 21 | OnlyActive = true; 22 | } 23 | 24 | /// 25 | /// Amount of results (default: 50) (maximum: 250) 26 | /// 27 | [JsonProperty("limit")] 28 | public int Limit { get; set; } 29 | 30 | /// 31 | /// Page to show (default: 1) 32 | /// 33 | [JsonProperty("page")] 34 | public int Page { get; set; } 35 | 36 | /// 37 | /// Restrict results to after the specified ID 38 | /// 39 | [JsonProperty("since_id")] 40 | public int SinceId { get; set; } 41 | 42 | /// 43 | /// Comma-separated list of fields to include in the response 44 | /// 45 | [JsonProperty("fields")] 46 | public string Fields { get; set; } 47 | 48 | /// 49 | /// Show news letter subscriptions created after date (format: 2008-12-31 03:00) 50 | /// 51 | [JsonProperty("created_at_min")] 52 | public DateTime? CreatedAtMin { get; set; } 53 | 54 | /// 55 | /// Show news letter subscriptions created before date (format: 2008-12-31 03:00) 56 | /// 57 | [JsonProperty("created_at_max")] 58 | public DateTime? CreatedAtMax { get; set; } 59 | 60 | /// 61 | /// Whether should return only active news letter subscriptions 62 | /// 63 | [JsonProperty("only_active")] 64 | public bool? OnlyActive { get; set; } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/OrderItemsParameters/OrderItemsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Infrastructure; 4 | using Nop.Plugin.Api.ModelBinders; 5 | 6 | namespace Nop.Plugin.Api.Models.OrderItemsParameters 7 | { 8 | [ModelBinder(typeof(ParametersModelBinder))] 9 | public class OrderItemsParametersModel 10 | { 11 | public OrderItemsParametersModel() 12 | { 13 | Limit = Constants.Configurations.DefaultLimit; 14 | Page = Constants.Configurations.DefaultPageValue; 15 | SinceId = 0; 16 | Fields = string.Empty; 17 | } 18 | 19 | [JsonProperty("limit")] 20 | public int Limit { get; set; } 21 | 22 | [JsonProperty("page")] 23 | public int Page { get; set; } 24 | 25 | [JsonProperty("since_id")] 26 | public int SinceId { get; set; } 27 | 28 | [JsonProperty("fields")] 29 | public string Fields { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/OrdersParameters/OrdersCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.OrdersParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class OrdersCountParametersModel : BaseOrdersParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/OrdersParameters/OrdersParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.Infrastructure; 5 | using Nop.Plugin.Api.ModelBinders; 6 | 7 | namespace Nop.Plugin.Api.Models.OrdersParameters 8 | { 9 | // JsonProperty is used only for swagger 10 | [ModelBinder(typeof(ParametersModelBinder))] 11 | public class OrdersParametersModel : BaseOrdersParametersModel 12 | { 13 | public OrdersParametersModel() 14 | { 15 | Ids = null; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Page = Constants.Configurations.DefaultPageValue; 18 | SinceId = Constants.Configurations.DefaultSinceId; 19 | Fields = string.Empty; 20 | } 21 | 22 | /// 23 | /// A comma-separated list of order ids 24 | /// 25 | [JsonProperty("ids")] 26 | public List Ids { get; set; } 27 | 28 | /// 29 | /// Amount of results (default: 50) (maximum: 250) 30 | /// 31 | [JsonProperty("limit")] 32 | public int Limit { get; set; } 33 | 34 | /// 35 | /// Page to show (default: 1) 36 | /// 37 | [JsonProperty("page")] 38 | public int Page { get; set; } 39 | 40 | /// 41 | /// Restrict results to after the specified ID 42 | /// 43 | [JsonProperty("since_id")] 44 | public int SinceId { get; set; } 45 | 46 | /// 47 | /// comma-separated list of fields to include in the response 48 | /// 49 | [JsonProperty("fields")] 50 | public string Fields { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductAttributesParameters/ProductAttributesParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.Infrastructure; 5 | using Nop.Plugin.Api.ModelBinders; 6 | 7 | namespace Nop.Plugin.Api.Models.ProductAttributesParameters 8 | { 9 | // JsonProperty is used only for swagger 10 | [ModelBinder(typeof(ParametersModelBinder))] 11 | public class ProductAttributesParametersModel 12 | { 13 | public ProductAttributesParametersModel() 14 | { 15 | Ids = null; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Page = Constants.Configurations.DefaultPageValue; 18 | SinceId = Constants.Configurations.DefaultSinceId; 19 | Fields = string.Empty; 20 | } 21 | 22 | /// 23 | /// A comma-separated list of category ids 24 | /// 25 | [JsonProperty("ids")] 26 | public List Ids { get; set; } 27 | 28 | /// 29 | /// Amount of results (default: 50) (maximum: 250) 30 | /// 31 | [JsonProperty("limit")] 32 | public int Limit { get; set; } 33 | 34 | /// 35 | /// Page to show (default: 1) 36 | /// 37 | [JsonProperty("page")] 38 | public int Page { get; set; } 39 | 40 | /// 41 | /// Restrict results to after the specified ID 42 | /// 43 | [JsonProperty("since_id")] 44 | public int SinceId { get; set; } 45 | 46 | /// 47 | /// comma-separated list of fields to include in the response 48 | /// 49 | [JsonProperty("fields")] 50 | public string Fields { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductCategoryMappingsParameters/BaseCategoryMappingsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.Models.ProductCategoryMappingsParameters 4 | { 5 | // JsonProperty is used only for swagger 6 | public class BaseCategoryMappingsParametersModel 7 | { 8 | /// 9 | /// Show all the product-category mappings for this product 10 | /// 11 | [JsonProperty("product_id")] 12 | public int? ProductId { get; set; } 13 | 14 | /// 15 | /// Show all the product-category mappings for this category 16 | /// 17 | [JsonProperty("category_id")] 18 | public int? CategoryId { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductCategoryMappingsParameters/ProductCategoryMappingsCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.ProductCategoryMappingsParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class ProductCategoryMappingsCountParametersModel : BaseCategoryMappingsParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductCategoryMappingsParameters/ProductCategoryMappingsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Infrastructure; 4 | using Nop.Plugin.Api.ModelBinders; 5 | 6 | namespace Nop.Plugin.Api.Models.ProductCategoryMappingsParameters 7 | { 8 | // JsonProperty is used only for swagger 9 | [ModelBinder(typeof(ParametersModelBinder))] 10 | public class ProductCategoryMappingsParametersModel : BaseCategoryMappingsParametersModel 11 | { 12 | public ProductCategoryMappingsParametersModel() 13 | { 14 | SinceId = Constants.Configurations.DefaultSinceId; 15 | Page = Constants.Configurations.DefaultPageValue; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Fields = string.Empty; 18 | } 19 | 20 | /// 21 | /// Restrict results to after the specified ID 22 | /// 23 | [JsonProperty("since_id")] 24 | public int SinceId { get; set; } 25 | 26 | /// 27 | /// Page to show (default: 1) 28 | /// 29 | [JsonProperty("page")] 30 | public int Page { get; set; } 31 | 32 | /// 33 | /// Amount of results (default: 50) (maximum: 250) 34 | /// 35 | [JsonProperty("limit")] 36 | public int Limit { get; set; } 37 | 38 | /// 39 | /// comma-separated list of fields to include in the response 40 | /// 41 | [JsonProperty("fields")] 42 | public string Fields { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductManufacturerMappingsParameters/BaseManufacturerMappingsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Nop.Plugin.Api.Models.ProductManufacturerMappingsParameters 4 | { 5 | // JsonProperty is used only for swagger 6 | public class BaseManufacturerMappingsParametersModel 7 | { 8 | /// 9 | /// Show all the product-manufacturer mappings for this product 10 | /// 11 | [JsonProperty("product_id")] 12 | public int? ProductId { get; set; } 13 | 14 | /// 15 | /// Show all the product-manufacturer mappings for this manufacturer 16 | /// 17 | [JsonProperty("manufacturer_id")] 18 | public int? ManufacturerId { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductManufacturerMappingsParameters/ProductManufacturerMappingsCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.ProductManufacturerMappingsParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class ProductManufacturerMappingsCountParametersModel : BaseManufacturerMappingsParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductManufacturerMappingsParameters/ProductManufacturerMappingsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Infrastructure; 4 | using Nop.Plugin.Api.ModelBinders; 5 | 6 | namespace Nop.Plugin.Api.Models.ProductManufacturerMappingsParameters 7 | { 8 | // JsonProperty is used only for swagger 9 | [ModelBinder(typeof(ParametersModelBinder))] 10 | public class ProductManufacturerMappingsParametersModel : BaseManufacturerMappingsParametersModel 11 | { 12 | public ProductManufacturerMappingsParametersModel() 13 | { 14 | SinceId = Constants.Configurations.DefaultSinceId; 15 | Page = Constants.Configurations.DefaultPageValue; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Fields = string.Empty; 18 | } 19 | 20 | /// 21 | /// Restrict results to after the specified ID 22 | /// 23 | [JsonProperty("since_id")] 24 | public int SinceId { get; set; } 25 | 26 | /// 27 | /// Page to show (default: 1) 28 | /// 29 | [JsonProperty("page")] 30 | public int Page { get; set; } 31 | 32 | /// 33 | /// Amount of results (default: 50) (maximum: 250) 34 | /// 35 | [JsonProperty("limit")] 36 | public int Limit { get; set; } 37 | 38 | /// 39 | /// comma-separated list of fields to include in the response 40 | /// 41 | [JsonProperty("fields")] 42 | public string Fields { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductSpecificationAttributesParameters/ProductSpecificationAttributesCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.ModelBinders; 4 | 5 | namespace Nop.Plugin.Api.Models.ProductSpecificationAttributesParameters 6 | { 7 | // JsonProperty is used only for swagger 8 | [ModelBinder(typeof(ParametersModelBinder))] 9 | public class ProductSpecificationAttributesCountParametersModel 10 | { 11 | /// 12 | /// Product Id 13 | /// 14 | [JsonProperty("product_id")] 15 | public int ProductId { get; set; } 16 | 17 | /// 18 | /// Specification Attribute Option Id 19 | /// 20 | [JsonProperty("specification_attribute_option_id")] 21 | public int SpecificationAttributeOptionId { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductSpecificationAttributesParameters/ProductSpecificationAttributesParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Infrastructure; 4 | using Nop.Plugin.Api.ModelBinders; 5 | 6 | namespace Nop.Plugin.Api.Models.ProductSpecificationAttributesParameters 7 | { 8 | [ModelBinder(typeof(ParametersModelBinder))] 9 | public class ProductSpecificationAttributesParametersModel 10 | { 11 | public ProductSpecificationAttributesParametersModel() 12 | { 13 | Limit = Constants.Configurations.DefaultLimit; 14 | Page = Constants.Configurations.DefaultPageValue; 15 | SinceId = Constants.Configurations.DefaultSinceId; 16 | Fields = string.Empty; 17 | } 18 | 19 | /// 20 | /// Product Id 21 | /// 22 | [JsonProperty("product_id")] 23 | public int ProductId { get; set; } 24 | 25 | /// 26 | /// Specification Attribute Option Id 27 | /// 28 | [JsonProperty("specification_attribute_option_id")] 29 | public int SpecificationAttributeOptionId { get; set; } 30 | 31 | /// 32 | /// Allow Filtering 33 | /// 34 | [JsonProperty("allow_filtering")] 35 | public bool? AllowFiltering { get; set; } 36 | 37 | /// 38 | /// Show on Product Page 39 | /// 40 | [JsonProperty("show_on_product_page")] 41 | public bool? ShowOnProductPage { get; set; } 42 | 43 | /// 44 | /// Amount of results (default: 50) (maximum: 250) 45 | /// 46 | [JsonProperty("limit")] 47 | public int Limit { get; set; } 48 | 49 | /// 50 | /// Page to show (default: 1) 51 | /// 52 | [JsonProperty("page")] 53 | public int Page { get; set; } 54 | 55 | /// 56 | /// Restrict results to after the specified ID 57 | /// 58 | [JsonProperty("since_id")] 59 | public int SinceId { get; set; } 60 | 61 | /// 62 | /// comma-separated list of fields to include in the response 63 | /// 64 | [JsonProperty("fields")] 65 | public string Fields { get; set; } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductsParameters/BaseProductsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Nop.Plugin.Api.Models.ProductsParameters 5 | { 6 | // JsonProperty is used only for swagger 7 | public class BaseProductsParametersModel 8 | { 9 | public BaseProductsParametersModel() 10 | { 11 | CreatedAtMin = null; 12 | CreatedAtMax = null; 13 | UpdatedAtMin = null; 14 | UpdatedAtMax = null; 15 | PublishedStatus = null; 16 | VendorName = null; 17 | CategoryId = null; 18 | } 19 | 20 | /// 21 | /// Show products created after date (format: 2008-12-31 03:00) 22 | /// 23 | [JsonProperty("created_at_min")] 24 | public DateTime? CreatedAtMin { get; set; } 25 | 26 | /// 27 | /// Show products created before date (format: 2008-12-31 03:00) 28 | /// 29 | [JsonProperty("created_at_max")] 30 | public DateTime? CreatedAtMax { get; set; } 31 | 32 | /// 33 | /// Show products last updated after date (format: 2008-12-31 03:00) 34 | /// 35 | [JsonProperty("updated_at_min")] 36 | public DateTime? UpdatedAtMin { get; set; } 37 | 38 | /// 39 | /// Show products last updated before date (format: 2008-12-31 03:00) 40 | /// 41 | [JsonProperty("updated_at_max")] 42 | public DateTime? UpdatedAtMax { get; set; } 43 | 44 | /// 45 | ///
    46 | ///
  • published - Show only published products
  • 47 | ///
  • unpublished - Show only unpublished products
  • 48 | ///
  • any - Show all products (default)
  • 49 | ///
50 | ///
51 | [JsonProperty("published_status")] 52 | public bool? PublishedStatus { get; set; } 53 | 54 | /// 55 | /// Filter by product vendor 56 | /// 57 | [JsonProperty("vendor_name")] 58 | public string VendorName { get; set; } 59 | 60 | /// 61 | /// Show only the products mapped to the specified category 62 | /// 63 | [JsonProperty("category_id")] 64 | public int? CategoryId { get; set; } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductsParameters/ProductsCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.ProductsParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class ProductsCountParametersModel : BaseProductsParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ProductsParameters/ProductsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Newtonsoft.Json; 4 | using Nop.Plugin.Api.Infrastructure; 5 | using Nop.Plugin.Api.ModelBinders; 6 | 7 | namespace Nop.Plugin.Api.Models.ProductsParameters 8 | { 9 | // JsonProperty is used only for swagger 10 | [ModelBinder(typeof(ParametersModelBinder))] 11 | public class ProductsParametersModel : BaseProductsParametersModel 12 | { 13 | public ProductsParametersModel() 14 | { 15 | Ids = null; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Page = Constants.Configurations.DefaultPageValue; 18 | SinceId = Constants.Configurations.DefaultSinceId; 19 | Fields = string.Empty; 20 | } 21 | 22 | /// 23 | /// A comma-separated list of order ids 24 | /// 25 | [JsonProperty("ids")] 26 | public List Ids { get; set; } 27 | 28 | /// 29 | /// Amount of results (default: 50) (maximum: 250) 30 | /// 31 | [JsonProperty("limit")] 32 | public int Limit { get; set; } 33 | 34 | /// 35 | /// Page to show (default: 1) 36 | /// 37 | [JsonProperty("page")] 38 | public int Page { get; set; } 39 | 40 | /// 41 | /// Restrict results to after the specified ID 42 | /// 43 | [JsonProperty("since_id")] 44 | public int SinceId { get; set; } 45 | 46 | /// 47 | /// comma-separated list of fields to include in the response 48 | /// 49 | [JsonProperty("fields")] 50 | public string Fields { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ShoppingCartsParameters/BaseShoppingCartItemsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Infrastructure; 4 | 5 | namespace Nop.Plugin.Api.Models.ShoppingCartsParameters 6 | { 7 | // JsonProperty is used only for swagger 8 | public class BaseShoppingCartItemsParametersModel 9 | { 10 | public BaseShoppingCartItemsParametersModel() 11 | { 12 | CreatedAtMin = null; 13 | CreatedAtMax = null; 14 | UpdatedAtMin = null; 15 | UpdatedAtMax = null; 16 | Limit = Constants.Configurations.DefaultLimit; 17 | Page = Constants.Configurations.DefaultPageValue; 18 | Fields = string.Empty; 19 | } 20 | 21 | /// 22 | /// Show shopping cart items created after date (format: 2008-12-31 03:00) 23 | /// 24 | [JsonProperty("created_at_min")] 25 | public DateTime? CreatedAtMin { get; set; } 26 | 27 | /// 28 | /// Show shopping cart items created before date (format: 2008-12-31 03:00) 29 | /// 30 | [JsonProperty("created_at_max")] 31 | public DateTime? CreatedAtMax { get; set; } 32 | 33 | /// 34 | /// Show shopping cart items updated after date (format: 2008-12-31 03:00) 35 | /// 36 | [JsonProperty("updated_at_min")] 37 | public DateTime? UpdatedAtMin { get; set; } 38 | 39 | /// 40 | /// Show shopping cart items updated before date (format: 2008-12-31 03:00) 41 | /// 42 | [JsonProperty("updated_at_max")] 43 | public DateTime? UpdatedAtMax { get; set; } 44 | 45 | /// 46 | /// Amount of results (default: 50) (maximum: 250) 47 | /// 48 | [JsonProperty("limit")] 49 | public int Limit { get; set; } 50 | 51 | /// 52 | /// Page to show (default: 1) 53 | /// 54 | [JsonProperty("page")] 55 | public int Page { get; set; } 56 | 57 | /// 58 | /// comma-separated list of fields to include in the response 59 | /// 60 | [JsonProperty("fields")] 61 | public string Fields { get; set; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ShoppingCartsParameters/ShoppingCartItemsForCustomerParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.ShoppingCartsParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class ShoppingCartItemsForCustomerParametersModel : BaseShoppingCartItemsParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/ShoppingCartsParameters/ShoppingCartItemsParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.ShoppingCartsParameters 5 | { 6 | [ModelBinder(typeof(ParametersModelBinder))] 7 | public class ShoppingCartItemsParametersModel : BaseShoppingCartItemsParametersModel 8 | { 9 | // Nothing special here, created just for clarity. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/SpecificationAttributesParameters/SpecificationAttributesCountParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Nop.Plugin.Api.ModelBinders; 3 | 4 | namespace Nop.Plugin.Api.Models.SpecificationAttributesParameters 5 | { 6 | // JsonProperty is used only for swagger 7 | [ModelBinder(typeof(ParametersModelBinder))] 8 | public class SpecificationAttributesCountParametersModel 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Models/SpecificationAttributesParameters/SpecificationAttributesParametersModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json; 3 | using Nop.Plugin.Api.Infrastructure; 4 | using Nop.Plugin.Api.ModelBinders; 5 | 6 | namespace Nop.Plugin.Api.Models.SpecificationAttributesParameters 7 | { 8 | [ModelBinder(typeof(ParametersModelBinder))] 9 | public class SpecificationAttributesParametersModel 10 | { 11 | public SpecificationAttributesParametersModel() 12 | { 13 | Limit = Constants.Configurations.DefaultLimit; 14 | Page = Constants.Configurations.DefaultPageValue; 15 | SinceId = Constants.Configurations.DefaultSinceId; 16 | } 17 | 18 | /// 19 | /// Amount of results (default: 50) (maximum: 250) 20 | /// 21 | [JsonProperty("limit")] 22 | public int Limit { get; set; } 23 | 24 | /// 25 | /// Page to show (default: 1) 26 | /// 27 | [JsonProperty("page")] 28 | public int Page { get; set; } 29 | 30 | /// 31 | /// comma-separated list of fields to include in the response 32 | /// 33 | [JsonProperty("fields")] 34 | public string Fields { get; set; } 35 | 36 | /// 37 | /// Restrict results to after the specified ID 38 | /// 39 | [JsonProperty("since_id")] 40 | public int SinceId { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/ICategoryApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Catalog; 4 | using Nop.Plugin.Api.Infrastructure; 5 | 6 | namespace Nop.Plugin.Api.Services 7 | { 8 | public interface ICategoryApiService 9 | { 10 | Category GetCategoryById(int categoryId); 11 | 12 | IList GetCategories( 13 | IList ids = null, 14 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, DateTime? updatedAtMin = null, DateTime? updatedAtMax = null, 15 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 16 | int sinceId = Constants.Configurations.DefaultSinceId, 17 | int? productId = null, bool? publishedStatus = null); 18 | 19 | int GetCategoriesCount( 20 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, DateTime? updatedAtMin = null, DateTime? updatedAtMax = null, 21 | bool? publishedStatus = null, int? productId = null); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/ICustomerApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Customers; 4 | using Nop.Plugin.Api.DTO.Customers; 5 | using Nop.Plugin.Api.Infrastructure; 6 | 7 | namespace Nop.Plugin.Api.Services 8 | { 9 | public interface ICustomerApiService 10 | { 11 | int GetCustomersCount(); 12 | 13 | CustomerDto GetCustomerById(int id, bool showDeleted = false); 14 | 15 | Customer GetCustomerEntityById(int id); 16 | 17 | IList GetCustomersDtos( 18 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, 19 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 20 | int sinceId = Constants.Configurations.DefaultSinceId); 21 | 22 | IList Search( 23 | string query = "", string order = Constants.Configurations.DefaultOrder, 24 | int page = Constants.Configurations.DefaultPageValue, int limit = Constants.Configurations.DefaultLimit); 25 | 26 | Dictionary GetFirstAndLastNameByCustomerId(int customerId); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IManufacturerApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Catalog; 4 | using Nop.Plugin.Api.Infrastructure; 5 | 6 | namespace Nop.Plugin.Api.Services 7 | { 8 | public interface IManufacturerApiService 9 | { 10 | Manufacturer GetManufacturerById(int manufacturerId); 11 | 12 | IList GetManufacturers( 13 | IList ids = null, 14 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, DateTime? updatedAtMin = null, DateTime? updatedAtMax = null, 15 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 16 | int sinceId = Constants.Configurations.DefaultSinceId, 17 | int? productId = null, bool? publishedStatus = null, int? languageId = null); 18 | 19 | int GetManufacturersCount( 20 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, DateTime? updatedAtMin = null, DateTime? updatedAtMax = null, 21 | bool? publishedStatus = null, int? productId = null); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/INewsLetterSubscriptionApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Messages; 4 | using Nop.Plugin.Api.Infrastructure; 5 | 6 | namespace Nop.Plugin.Api.Services 7 | { 8 | public interface INewsLetterSubscriptionApiService 9 | { 10 | List GetNewsLetterSubscriptions( 11 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, 12 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 13 | int sinceId = Constants.Configurations.DefaultSinceId, 14 | bool? onlyActive = true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IOrderApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Orders; 4 | using Nop.Core.Domain.Payments; 5 | using Nop.Core.Domain.Shipping; 6 | using Nop.Plugin.Api.Infrastructure; 7 | 8 | namespace Nop.Plugin.Api.Services 9 | { 10 | public interface IOrderApiService 11 | { 12 | IList GetOrdersByCustomerId(int customerId); 13 | 14 | IList GetOrders( 15 | IList ids = null, DateTime? createdAtMin = null, DateTime? createdAtMax = null, 16 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 17 | int sinceId = Constants.Configurations.DefaultSinceId, OrderStatus? status = null, PaymentStatus? paymentStatus = null, 18 | ShippingStatus? shippingStatus = null, int? customerId = null, int? storeId = null); 19 | 20 | Order GetOrderById(int orderId); 21 | 22 | int GetOrdersCount( 23 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, OrderStatus? status = null, 24 | PaymentStatus? paymentStatus = null, ShippingStatus? shippingStatus = null, 25 | int? customerId = null, int? storeId = null); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IOrderItemApiService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Core.Domain.Orders; 3 | 4 | namespace Nop.Plugin.Api.Services 5 | { 6 | public interface IOrderItemApiService 7 | { 8 | IList GetOrderItemsForOrder(Order order, int limit, int page, int sinceId); 9 | int GetOrderItemsCount(Order order); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IProductApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Catalog; 4 | using Nop.Plugin.Api.Infrastructure; 5 | 6 | namespace Nop.Plugin.Api.Services 7 | { 8 | public interface IProductApiService 9 | { 10 | IList GetProducts( 11 | IList ids = null, 12 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, DateTime? updatedAtMin = null, DateTime? updatedAtMax = null, 13 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 14 | int sinceId = Constants.Configurations.DefaultSinceId, 15 | int? categoryId = null, string vendorName = null, bool? publishedStatus = null); 16 | 17 | int GetProductsCount( 18 | DateTime? createdAtMin = null, DateTime? createdAtMax = null, 19 | DateTime? updatedAtMin = null, DateTime? updatedAtMax = null, bool? publishedStatus = null, 20 | string vendorName = null, int? categoryId = null); 21 | 22 | Product GetProductById(int productId); 23 | 24 | Product GetProductByIdNoTracking(int productId); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IProductAttributeConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Plugin.Api.DTO; 3 | 4 | namespace Nop.Plugin.Api.Services 5 | { 6 | public interface IProductAttributeConverter 7 | { 8 | List Parse(string attributesXml); 9 | string ConvertToXml(List attributeDtos, int productId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IProductAttributesApiService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Core.Domain.Catalog; 3 | using Nop.Plugin.Api.Infrastructure; 4 | 5 | namespace Nop.Plugin.Api.Services 6 | { 7 | public interface IProductAttributesApiService 8 | { 9 | IList GetProductAttributes( 10 | int limit = Constants.Configurations.DefaultLimit, 11 | int page = Constants.Configurations.DefaultPageValue, int sinceId = Constants.Configurations.DefaultSinceId); 12 | 13 | int GetProductAttributesCount(); 14 | 15 | ProductAttribute GetById(int id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IProductCategoryMappingsApiService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Core.Domain.Catalog; 3 | using Nop.Plugin.Api.Infrastructure; 4 | 5 | namespace Nop.Plugin.Api.Services 6 | { 7 | public interface IProductCategoryMappingsApiService 8 | { 9 | IList GetMappings( 10 | int? productId = null, int? categoryId = null, int limit = Constants.Configurations.DefaultLimit, 11 | int page = Constants.Configurations.DefaultPageValue, int sinceId = Constants.Configurations.DefaultSinceId); 12 | 13 | int GetMappingsCount(int? productId = null, int? categoryId = null); 14 | 15 | ProductCategory GetById(int id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IProductManufacturerMappingsApiService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Core.Domain.Catalog; 3 | using Nop.Plugin.Api.Infrastructure; 4 | 5 | namespace Nop.Plugin.Api.Services 6 | { 7 | public interface IProductManufacturerMappingsApiService 8 | { 9 | IList GetMappings( 10 | int? productId = null, int? manufacturerId = null, int limit = Constants.Configurations.DefaultLimit, 11 | int page = Constants.Configurations.DefaultPageValue, int sinceId = Constants.Configurations.DefaultSinceId); 12 | 13 | int GetMappingsCount(int? productId = null, int? manufacturerId = null); 14 | 15 | ProductManufacturer GetById(int id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IProductPictureService.cs: -------------------------------------------------------------------------------- 1 | using Nop.Core.Domain.Catalog; 2 | 3 | namespace Nop.Plugin.Api.Services 4 | { 5 | public interface IProductPictureService 6 | { 7 | ProductPicture GetProductPictureByPictureId(int pictureId); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/IShoppingCartItemApiService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Nop.Core.Domain.Orders; 4 | using Nop.Plugin.Api.Infrastructure; 5 | 6 | namespace Nop.Plugin.Api.Services 7 | { 8 | public interface IShoppingCartItemApiService 9 | { 10 | List GetShoppingCartItems( 11 | int? customerId = null, DateTime? createdAtMin = null, DateTime? createdAtMax = null, 12 | DateTime? updatedAtMin = null, DateTime? updatedAtMax = null, int limit = Constants.Configurations.DefaultLimit, 13 | int page = Constants.Configurations.DefaultPageValue); 14 | 15 | ShoppingCartItem GetShoppingCartItem(int id); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/ISpecificationAttributeApiService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Nop.Core.Domain.Catalog; 3 | using Nop.Plugin.Api.Infrastructure; 4 | 5 | namespace Nop.Plugin.Api.Services 6 | { 7 | public interface ISpecificationAttributeApiService 8 | { 9 | IList GetProductSpecificationAttributes( 10 | int? productId = null, int? specificationAttributeOptionId = null, bool? allowFiltering = null, bool? showOnProductPage = null, 11 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 12 | int sinceId = Constants.Configurations.DefaultSinceId); 13 | 14 | IList GetSpecificationAttributes( 15 | int limit = Constants.Configurations.DefaultLimit, int page = Constants.Configurations.DefaultPageValue, 16 | int sinceId = Constants.Configurations.DefaultSinceId); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/OrderItemApiService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Nop.Core.Domain.Orders; 4 | using Nop.Plugin.Api.DataStructures; 5 | using Nop.Services.Catalog; 6 | using Nop.Services.Orders; 7 | 8 | namespace Nop.Plugin.Api.Services 9 | { 10 | public class OrderItemApiService : IOrderItemApiService 11 | { 12 | private readonly IOrderService _orderService; 13 | private readonly IProductService _productService; 14 | 15 | public OrderItemApiService(IOrderService orderService 16 | ,IProductService productService) 17 | { 18 | _orderService = orderService; 19 | _productService = productService; 20 | } 21 | public IList GetOrderItemsForOrder(Order order, int limit, int page, int sinceId) 22 | { 23 | var orderItems = _orderService.GetOrderItems(order.Id).AsQueryable(); 24 | 25 | return new ApiList(orderItems, page - 1, limit); 26 | } 27 | 28 | public int GetOrderItemsCount(Order order) 29 | { 30 | var orderItemsCount = _orderService.GetOrderItems(order.Id).Count(); 31 | 32 | return orderItemsCount; 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/ProductAttributesApiService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Nop.Data; 4 | using Nop.Core.Domain.Catalog; 5 | using Nop.Plugin.Api.DataStructures; 6 | using Nop.Plugin.Api.Infrastructure; 7 | 8 | namespace Nop.Plugin.Api.Services 9 | { 10 | public class ProductAttributesApiService : IProductAttributesApiService 11 | { 12 | private readonly IRepository _productAttributesRepository; 13 | 14 | public ProductAttributesApiService(IRepository productAttributesRepository) 15 | { 16 | _productAttributesRepository = productAttributesRepository; 17 | } 18 | 19 | public IList GetProductAttributes( 20 | int limit = Constants.Configurations.DefaultLimit, 21 | int page = Constants.Configurations.DefaultPageValue, int sinceId = Constants.Configurations.DefaultSinceId) 22 | { 23 | var query = GetProductAttributesQuery(sinceId); 24 | 25 | return new ApiList(query, page - 1, limit); 26 | } 27 | 28 | public int GetProductAttributesCount() 29 | { 30 | return GetProductAttributesQuery().Count(); 31 | } 32 | 33 | ProductAttribute IProductAttributesApiService.GetById(int id) 34 | { 35 | if (id <= 0) 36 | { 37 | return null; 38 | } 39 | 40 | return _productAttributesRepository.GetById(id); 41 | } 42 | 43 | private IQueryable GetProductAttributesQuery(int sinceId = Constants.Configurations.DefaultSinceId) 44 | { 45 | var query = _productAttributesRepository.Table; 46 | 47 | if (sinceId > 0) 48 | { 49 | query = query.Where(productAttribute => productAttribute.Id > sinceId); 50 | } 51 | 52 | query = query.OrderBy(productAttribute => productAttribute.Id); 53 | 54 | return query; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Services/ProductPictureService.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Nop.Data; 3 | using Nop.Core.Domain.Catalog; 4 | 5 | namespace Nop.Plugin.Api.Services 6 | { 7 | public class ProductPictureService : IProductPictureService 8 | { 9 | private readonly IRepository _productPictureRepository; 10 | 11 | public ProductPictureService(IRepository productPictureRepository) 12 | { 13 | _productPictureRepository = productPictureRepository; 14 | } 15 | 16 | public ProductPicture GetProductPictureByPictureId(int pictureId) 17 | { 18 | if (pictureId == 0) 19 | { 20 | return null; 21 | } 22 | 23 | var query = from pp in _productPictureRepository.Table 24 | where pp.PictureId == pictureId 25 | select pp; 26 | 27 | var productPictures = query.ToList(); 28 | 29 | return productPictures.FirstOrDefault(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/AddressDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Http; 3 | using Nop.Plugin.Api.DTO; 4 | using Nop.Plugin.Api.Helpers; 5 | 6 | namespace Nop.Plugin.Api.Validators 7 | { 8 | public class AddressDtoValidator : BaseDtoValidator 9 | { 10 | #region Constructors 11 | 12 | public AddressDtoValidator(IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : 13 | base(httpContextAccessor, jsonHelper, requestJsonDictionary) 14 | { 15 | SetFirstNameRule(); 16 | SetLastNameRule(); 17 | SetEmailRule(); 18 | 19 | SetAddress1Rule(); 20 | SetCityRule(); 21 | SetZipPostalCodeRule(); 22 | SetCountryIdRule(); 23 | SetPhoneNumberRule(); 24 | } 25 | 26 | #endregion 27 | 28 | #region Private Methods 29 | 30 | private void SetAddress1Rule() 31 | { 32 | SetNotNullOrEmptyCreateOrUpdateRule(a => a.Address1, "address1 required", "address1"); 33 | } 34 | 35 | private void SetCityRule() 36 | { 37 | SetNotNullOrEmptyCreateOrUpdateRule(a => a.City, "city required", "city"); 38 | } 39 | 40 | private void SetCountryIdRule() 41 | { 42 | SetGreaterThanZeroCreateOrUpdateRule(a => a.CountryId, "country_id required", "country_id"); 43 | } 44 | 45 | private void SetEmailRule() 46 | { 47 | SetNotNullOrEmptyCreateOrUpdateRule(a => a.Email, "email required", "email"); 48 | } 49 | 50 | private void SetFirstNameRule() 51 | { 52 | SetNotNullOrEmptyCreateOrUpdateRule(a => a.FirstName, "first_name required", "first_name"); 53 | } 54 | 55 | private void SetLastNameRule() 56 | { 57 | SetNotNullOrEmptyCreateOrUpdateRule(a => a.LastName, "first_name required", "last_name"); 58 | } 59 | 60 | private void SetPhoneNumberRule() 61 | { 62 | SetNotNullOrEmptyCreateOrUpdateRule(a => a.PhoneNumber, "phone_number required", "phone_number"); 63 | } 64 | 65 | private void SetZipPostalCodeRule() 66 | { 67 | SetNotNullOrEmptyCreateOrUpdateRule(a => a.ZipPostalCode, "zip_postal_code required", "zip_postal_code"); 68 | } 69 | 70 | #endregion 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/CategoryDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using JetBrains.Annotations; 3 | using Microsoft.AspNetCore.Http; 4 | using Nop.Plugin.Api.DTO.Categories; 5 | using Nop.Plugin.Api.Helpers; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class CategoryDtoValidator : BaseDtoValidator 11 | { 12 | #region Constructors 13 | 14 | public CategoryDtoValidator(IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : 15 | base(httpContextAccessor, jsonHelper, requestJsonDictionary) 16 | { 17 | SetNameRule(); 18 | } 19 | 20 | #endregion 21 | 22 | #region Private Methods 23 | 24 | private void SetNameRule() 25 | { 26 | SetNotNullOrEmptyCreateOrUpdateRule(c => c.Name, "invalid name", "name"); 27 | } 28 | 29 | #endregion 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/FieldsValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace Nop.Plugin.Api.Validators 7 | { 8 | public class FieldsValidator : IFieldsValidator 9 | { 10 | public Dictionary GetValidFields(string fields, Type type) 11 | { 12 | // This check ensures that the fields won't be null, because it can couse exception. 13 | fields = fields ?? string.Empty; 14 | // This is needed in case you pass the fields as you see them in the json representation of the objects. 15 | // By specification if the property consists of several words, each word should be separetate from the others with underscore. 16 | fields = fields.Replace("_", string.Empty); 17 | 18 | var validFields = new Dictionary(); 19 | var fieldsAsList = GetPropertiesIntoList(fields); 20 | 21 | foreach (var field in fieldsAsList) 22 | { 23 | var propertyExists = type.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null; 24 | 25 | if (propertyExists) 26 | { 27 | validFields.Add(field, true); 28 | } 29 | } 30 | 31 | return validFields; 32 | } 33 | 34 | private static IEnumerable GetPropertiesIntoList(string fields) 35 | { 36 | var properties = fields.ToLowerInvariant() 37 | .Split(new[] 38 | { 39 | ',' 40 | }, StringSplitOptions.RemoveEmptyEntries) 41 | .Select(x => x.Trim()) 42 | .Distinct() 43 | .ToList(); 44 | 45 | return properties; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/IFieldsValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Nop.Plugin.Api.Validators 5 | { 6 | public interface IFieldsValidator 7 | { 8 | //TODO: Why this needs to be dictionary??? 9 | Dictionary GetValidFields(string fields, Type type); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/ManufacturerDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using JetBrains.Annotations; 3 | using Microsoft.AspNetCore.Http; 4 | using Nop.Plugin.Api.DTO.Manufacturers; 5 | using Nop.Plugin.Api.Helpers; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class ManufacturerDtoValidator : BaseDtoValidator 11 | { 12 | #region Constructors 13 | 14 | public ManufacturerDtoValidator(IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : 15 | base(httpContextAccessor, jsonHelper, requestJsonDictionary) 16 | { 17 | SetNameRule(); 18 | } 19 | 20 | #endregion 21 | 22 | #region Private Methods 23 | 24 | private void SetNameRule() 25 | { 26 | SetNotNullOrEmptyCreateOrUpdateRule(m => m.Name, "invalid name", "name"); 27 | } 28 | 29 | #endregion 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/OrderItemDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.AspNetCore.Http; 3 | using Nop.Plugin.Api.DTO.OrderItems; 4 | using Nop.Plugin.Api.Helpers; 5 | 6 | namespace Nop.Plugin.Api.Validators 7 | { 8 | public class OrderItemDtoValidator : BaseDtoValidator 9 | { 10 | #region Constructors 11 | 12 | public OrderItemDtoValidator(IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : 13 | base(httpContextAccessor, jsonHelper, requestJsonDictionary) 14 | { 15 | SetProductIdRule(); 16 | SetQuantityRule(); 17 | } 18 | 19 | #endregion 20 | 21 | #region Private Methods 22 | 23 | private void SetProductIdRule() 24 | { 25 | SetGreaterThanZeroCreateOrUpdateRule(o => o.ProductId, "invalid product_id", "product_id"); 26 | } 27 | 28 | private void SetQuantityRule() 29 | { 30 | SetGreaterThanZeroCreateOrUpdateRule(o => o.Quantity, "invalid quanitty", "quantity"); 31 | } 32 | 33 | #endregion 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/ProductAttributeCombinationDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using JetBrains.Annotations; 3 | using Microsoft.AspNetCore.Http; 4 | using Nop.Plugin.Api.DTO.Products; 5 | using Nop.Plugin.Api.Helpers; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class ProductAttributeCombinationDtoValidator : BaseDtoValidator 11 | { 12 | #region Constructors 13 | 14 | public ProductAttributeCombinationDtoValidator( 15 | IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : base(httpContextAccessor, 16 | jsonHelper, 17 | requestJsonDictionary) 18 | { 19 | SetAttributesXmlRule(); 20 | SetProductIdRule(); 21 | } 22 | 23 | #endregion 24 | 25 | #region Private Methods 26 | 27 | private void SetAttributesXmlRule() 28 | { 29 | SetNotNullOrEmptyCreateOrUpdateRule(p => p.AttributesXml, "invalid attributes xml", "attributes_xml"); 30 | } 31 | 32 | private void SetProductIdRule() 33 | { 34 | SetGreaterThanZeroCreateOrUpdateRule(p => p.ProductId, "invalid product id", "product_id"); 35 | } 36 | 37 | #endregion 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/ProductAttributeDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using JetBrains.Annotations; 3 | using Microsoft.AspNetCore.Http; 4 | using Nop.Plugin.Api.DTO.ProductAttributes; 5 | using Nop.Plugin.Api.Helpers; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class ProductAttributeDtoValidator : BaseDtoValidator 11 | { 12 | #region Constructors 13 | 14 | public ProductAttributeDtoValidator(IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : 15 | base(httpContextAccessor, jsonHelper, requestJsonDictionary) 16 | { 17 | SetNameRule(); 18 | } 19 | 20 | #endregion 21 | 22 | #region Private Methods 23 | 24 | private void SetNameRule() 25 | { 26 | SetNotNullOrEmptyCreateOrUpdateRule(p => p.Name, "invalid name", "name"); 27 | } 28 | 29 | #endregion 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/ProductCategoryMappingDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using JetBrains.Annotations; 3 | using Microsoft.AspNetCore.Http; 4 | using Nop.Plugin.Api.DTO.ProductCategoryMappings; 5 | using Nop.Plugin.Api.Helpers; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class ProductCategoryMappingDtoValidator : BaseDtoValidator 11 | { 12 | #region Constructors 13 | 14 | public ProductCategoryMappingDtoValidator( 15 | IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : base(httpContextAccessor, 16 | jsonHelper, 17 | requestJsonDictionary) 18 | { 19 | SetCategoryIdRule(); 20 | SetProductIdRule(); 21 | } 22 | 23 | #endregion 24 | 25 | #region Private Methods 26 | 27 | private void SetCategoryIdRule() 28 | { 29 | SetGreaterThanZeroCreateOrUpdateRule(p => p.CategoryId, "invalid category_id", "category_id"); 30 | } 31 | 32 | private void SetProductIdRule() 33 | { 34 | SetGreaterThanZeroCreateOrUpdateRule(p => p.ProductId, "invalid product_id", "product_id"); 35 | } 36 | 37 | #endregion 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/ProductDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using JetBrains.Annotations; 3 | using Microsoft.AspNetCore.Http; 4 | using Nop.Plugin.Api.DTO.Products; 5 | using Nop.Plugin.Api.Helpers; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class ProductDtoValidator : BaseDtoValidator 11 | { 12 | #region Constructors 13 | 14 | public ProductDtoValidator(IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : 15 | base(httpContextAccessor, jsonHelper, requestJsonDictionary) 16 | { 17 | SetNameRule(); 18 | } 19 | 20 | #endregion 21 | 22 | #region Private Methods 23 | 24 | private void SetNameRule() 25 | { 26 | SetNotNullOrEmptyCreateOrUpdateRule(p => p.Name, "invalid name", "name"); 27 | } 28 | 29 | #endregion 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/ProductManufacturerMappingDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using JetBrains.Annotations; 3 | using Microsoft.AspNetCore.Http; 4 | using Nop.Plugin.Api.DTO.ProductManufacturerMappings; 5 | using Nop.Plugin.Api.Helpers; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class ProductManufacturerMappingDtoValidator : BaseDtoValidator 11 | { 12 | #region Constructors 13 | 14 | public ProductManufacturerMappingDtoValidator( 15 | IHttpContextAccessor httpContextAccessor, IJsonHelper jsonHelper, Dictionary requestJsonDictionary) : base(httpContextAccessor, 16 | jsonHelper, 17 | requestJsonDictionary) 18 | { 19 | SetManufacturerIdRule(); 20 | SetProductIdRule(); 21 | } 22 | 23 | #endregion 24 | 25 | #region Private Methods 26 | 27 | private void SetManufacturerIdRule() 28 | { 29 | SetGreaterThanZeroCreateOrUpdateRule(p => p.ManufacturerId, "invalid manufacturer_id", "manufacturer_id"); 30 | } 31 | 32 | private void SetProductIdRule() 33 | { 34 | SetGreaterThanZeroCreateOrUpdateRule(p => p.ProductId, "invalid product_id", "product_id"); 35 | } 36 | 37 | #endregion 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/SpecificationAttributeDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using FluentValidation; 4 | using JetBrains.Annotations; 5 | using Nop.Plugin.Api.DTO.SpecificationAttributes; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class SpecificationAttributeDtoValidator : AbstractValidator 11 | { 12 | public SpecificationAttributeDtoValidator(string httpMethod, Dictionary passedPropertyValuePairs) 13 | { 14 | if (string.IsNullOrEmpty(httpMethod) || httpMethod.Equals("post", StringComparison.InvariantCultureIgnoreCase)) 15 | { 16 | //apply "create" rules 17 | RuleFor(x => x.Id).Equal(0).WithMessage("id must be zero or null for new records"); 18 | 19 | ApplyNameRule(); 20 | } 21 | else if (httpMethod.Equals("put", StringComparison.InvariantCultureIgnoreCase)) 22 | { 23 | //apply "update" rules 24 | RuleFor(x => x.Id).GreaterThan(0).WithMessage("invalid id"); 25 | ApplyNameRule(); 26 | } 27 | } 28 | 29 | private void ApplyNameRule() 30 | { 31 | RuleFor(x => x.Name).NotEmpty().WithMessage("invalid name"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/Validators/SpecificationAttributeOptionDtoValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using FluentValidation; 4 | using JetBrains.Annotations; 5 | using Nop.Plugin.Api.DTO.SpecificationAttributes; 6 | 7 | namespace Nop.Plugin.Api.Validators 8 | { 9 | [UsedImplicitly] 10 | public class SpecificationAttributeOptionDtoValidator : AbstractValidator 11 | { 12 | public SpecificationAttributeOptionDtoValidator(string httpMethod, Dictionary passedPropertyValuePairs) 13 | { 14 | if (string.IsNullOrEmpty(httpMethod) || httpMethod.Equals("post", StringComparison.InvariantCultureIgnoreCase)) 15 | { 16 | //apply "create" rules 17 | RuleFor(x => x.Id).Equal(0).WithMessage("id must be zero or null for new records"); 18 | 19 | ApplyNameRule(); 20 | ApplySpecificationAttributeIdRule(); 21 | } 22 | else if (httpMethod.Equals("put", StringComparison.InvariantCultureIgnoreCase)) 23 | { 24 | //apply "update" rules 25 | RuleFor(x => x.Id).GreaterThan(0).WithMessage("invalid id"); 26 | 27 | if (passedPropertyValuePairs.ContainsKey("name")) 28 | { 29 | ApplyNameRule(); 30 | } 31 | 32 | if (passedPropertyValuePairs.ContainsKey("specification_attribute_id")) 33 | { 34 | ApplySpecificationAttributeIdRule(); 35 | } 36 | } 37 | } 38 | 39 | private void ApplyNameRule() 40 | { 41 | RuleFor(x => x.Name).NotEmpty().WithMessage("invalid name"); 42 | } 43 | 44 | private void ApplySpecificationAttributeIdRule() 45 | { 46 | RuleFor(x => x.SpecificationAttributeId).GreaterThan(0).WithMessage("invalid specification attribute id"); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Nop.Plugin.Api/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madewithfire/api-plugin-for-nopcommerce/a7d306c5259db031c2ce1498feebf622475c5f5b/Nop.Plugin.Api/logo.jpg -------------------------------------------------------------------------------- /Nop.Plugin.Api/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "Group": "Api", 3 | "FriendlyName": "Api plugin", 4 | "SystemName": "Nop.Plugin.Api", 5 | "Version": "4.2.0", 6 | "SupportedVersions": [ "4.30" ], 7 | "Author": "Nop-Templates team", 8 | "DisplayOrder": -1, 9 | "FileName": "Nop.Plugin.Api.dll", 10 | "Description": "This plugin is Restfull API for nopCommerce" 11 | } -------------------------------------------------------------------------------- /OrderItems.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Orders.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ProductCategoryMappings.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # API plugin for nopCommerce 4.3 2 | 3 | This plugin provides a RESTful API for managing resources in nopCommerce. 4 | 5 | ## What is a RESTful API? 6 | 7 | 8 | HTTP requests are often the way that you interact with a RESTful API. 9 | A client makes an HTTP request to a server and the server responds with an HTTP response. 10 | 11 | In a HTTP request, you need to define the type of action that you want to perform against a resource. There are four primary actions associated with any HTTP request (commonly referred to as CRUD): 12 | 13 | **POST** (Create) 14 | 15 | **GET** (Retrieve) 16 | 17 | **PUT** (Update) 18 | 19 | **DELETE** (Delete) 20 | 21 | A resource is a data object that can be accessed via an HTTP request. The API allows you to “access your nopCommerce site’s data (resources) through an easy-to-use HTTP REST API”. In the case of the most recent version of the API (nopCommerce version 4.30), the resources include the following 7 nopCommerce objects: 22 | 23 | [**Customers**](Customers.md) 24 | 25 | [**Products**](Products.md) 26 | 27 | [**Categories**](Categories.md) 28 | 29 | [**ProductCategoryMappings**](ProductCategoryMappings.md) 30 | 31 | [**Orders**](Orders.md) 32 | 33 | [**OrderItems**](OrderItems.md) 34 | 35 | [**ShoppingCartItems**](ShoppingCartItems.md) 36 | 37 | With the nopCommerce API, you can perform any of the four CRUD actions against any of your nopCommerce site’s resources listed above. For example, you can use the API to create a product, retrieve a product, update a product or delete a product associated with your nopCommerce website. 38 | 39 | ## What about security? 40 | 41 | ## The API plugin currently supports only JWT Bearer Authentication. Will add support of OAuth 2.0 Authorization Code grant type flow later. 42 | -------------------------------------------------------------------------------- /ShoppingCartItems.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /uploadedItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Type": "Plugin", 4 | "SupportedVersion": "4.00", 5 | "DirectoryPath": "Nop.Plugin.Api", 6 | "SystemName": "Nop.Plugin.Api" 7 | } 8 | ] --------------------------------------------------------------------------------