diff --git a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Controllers/BrandApiController.cs b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Controllers/BrandApiController.cs index 2576aaa177..a94f808b14 100644 --- a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Controllers/BrandApiController.cs +++ b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Controllers/BrandApiController.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -13,7 +14,8 @@ namespace SimplCommerce.Module.Catalog.Areas.Catalog.Controllers [Area("Catalog")] [Authorize(Roles = "admin, vendor")] [Route("api/brands")] - public class BrandApiController : Controller + [ApiController] + public class BrandApiController : ControllerBase { private readonly IRepository _brandRepository; private readonly IBrandService _brandService; @@ -25,18 +27,31 @@ public BrandApiController(IRepository brandRepository, IBrandService bran } [HttpGet] - public async Task Get() + public async Task>> Get() { - var brandList = await _brandRepository.Query().Where(x => !x.IsDeleted).ToListAsync(); + var brands = await _brandRepository.Query() + .Where(x => !x.IsDeleted) + .Select(x => new BrandVm + { + Id = x.Id, + Name = x.Name, + Slug = x.Slug, + IsPublished = x.IsPublished + }).ToListAsync(); - return Json(brandList); + return brands; } [HttpGet("{id}")] - public async Task Get(long id) + public async Task> Get(long id) { var brand = await _brandRepository.Query().FirstOrDefaultAsync(x => x.Id == id); - var model = new BrandForm + if(brand == null) + { + return NotFound(); + } + + var model = new BrandVm { Id = brand.Id, Name = brand.Name, @@ -44,49 +59,40 @@ public async Task Get(long id) IsPublished = brand.IsPublished }; - return Json(model); + return model; } [HttpPost] [Authorize(Roles = "admin")] public async Task Post([FromBody] BrandForm model) { - if (ModelState.IsValid) + var brand = new Brand { - var brand = new Brand - { - Name = model.Name, - Slug = model.Slug, - IsPublished = model.IsPublished - }; + Name = model.Name, + Slug = model.Slug, + IsPublished = model.IsPublished + }; - await _brandService.Create(brand); - return CreatedAtAction(nameof(Get), new { id = brand.Id }, null); - } - return BadRequest(ModelState); + await _brandService.Create(brand); + return CreatedAtAction(nameof(Get), new { id = brand.Id }, null); } [HttpPut("{id}")] [Authorize(Roles = "admin")] public async Task Put(long id, [FromBody] BrandForm model) { - if (ModelState.IsValid) + var brand = _brandRepository.Query().FirstOrDefault(x => x.Id == id); + if(brand == null) { - var brand = _brandRepository.Query().FirstOrDefault(x => x.Id == id); - if(brand == null) - { - return NotFound(); - } - - brand.Name = model.Name; - brand.Slug = model.Slug; - brand.IsPublished = model.IsPublished; - - await _brandService.Update(brand); - return Accepted(); + return NotFound(); } - return BadRequest(ModelState); + brand.Name = model.Name; + brand.Slug = model.Slug; + brand.IsPublished = model.IsPublished; + + await _brandService.Update(brand); + return Accepted(); } [HttpDelete("{id}")] diff --git a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/BrandForm.cs b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/BrandForm.cs index 92c4eff8c2..0c813c0173 100644 --- a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/BrandForm.cs +++ b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/BrandForm.cs @@ -9,8 +9,6 @@ public BrandForm() IsPublished = true; } - public long Id { get; set; } - [Required(ErrorMessage = "The {0} field is required.")] public string Slug { get; set; } diff --git a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/BrandVm.cs b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/BrandVm.cs new file mode 100644 index 0000000000..0fd6dd25df --- /dev/null +++ b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/BrandVm.cs @@ -0,0 +1,7 @@ +namespace SimplCommerce.Module.Catalog.Areas.Catalog.ViewModels +{ + public class BrandVm : BrandForm + { + public long Id { get; set; } + } +} diff --git a/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.html b/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.html index cf61567ad5..8a6048bc28 100644 --- a/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.html +++ b/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.html @@ -22,6 +22,15 @@

{{::vm.translate.get('Edit Brand')}}

+
+
+
+ +
+
+
@@ -30,4 +39,4 @@

{{::vm.translate.get('Edit Brand')}}

- \ No newline at end of file + diff --git a/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.js b/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.js index f0defcf5c9..61be43cb76 100644 --- a/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.js +++ b/src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.js @@ -7,7 +7,7 @@ function BrandFormCtrl($state, $stateParams, brandService, translateService) { var vm = this; vm.translate = translateService; - vm.brand = {}; + vm.brand = { isPublished: true }; vm.brandId = $stateParams.id; vm.isEditMode = vm.brandId > 0; diff --git a/src/Modules/SimplCommerce.Module.Core/Areas/Core/Controllers/AppSettingApiController.cs b/src/Modules/SimplCommerce.Module.Core/Areas/Core/Controllers/AppSettingApiController.cs index 569f39cdb4..d4e590bd2e 100644 --- a/src/Modules/SimplCommerce.Module.Core/Areas/Core/Controllers/AppSettingApiController.cs +++ b/src/Modules/SimplCommerce.Module.Core/Areas/Core/Controllers/AppSettingApiController.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using SimplCommerce.Infrastructure.Data; +using SimplCommerce.Module.Core.Areas.Core.ViewModels; using SimplCommerce.Module.Core.Models; namespace SimplCommerce.Module.Core.Areas.Core.Controllers @@ -13,7 +14,8 @@ namespace SimplCommerce.Module.Core.Areas.Core.Controllers [Area("Core")] [Authorize(Roles = "admin")] [Route("api/appsettings")] - public class AppSettingApiController : Controller + [ApiController] + public class AppSettingApiController : ControllerBase { private readonly IRepositoryWithTypedId _appSettingRepository; private readonly IConfigurationRoot _configurationRoot; @@ -25,21 +27,24 @@ public AppSettingApiController(IRepositoryWithTypedId appSet } [HttpGet] - public async Task Get() + public async Task>> Get() { - var settings = await _appSettingRepository.Query().Where(x => x.IsVisibleInCommonSettingPage).ToListAsync(); - return Json(settings); + var settings = await _appSettingRepository.Query() + .Where(x => x.IsVisibleInCommonSettingPage) + .Select(x => new AppSettingVm { Key = x.Id, Value = x.Value }) + .ToListAsync(); + return settings; } [HttpPut] - public async Task Put([FromBody] IList model) + public async Task Put([FromBody] IList model) { if (ModelState.IsValid) { var settings = await _appSettingRepository.Query().Where(x => x.IsVisibleInCommonSettingPage).ToListAsync(); foreach(var item in settings) { - var vm = model.FirstOrDefault(x => x.Id == item.Id); + var vm = model.FirstOrDefault(x => x.Key == item.Id); if (vm != null) { item.Value = vm.Value; diff --git a/src/Modules/SimplCommerce.Module.Core/Areas/Core/ViewModels/AppSettingVm.cs b/src/Modules/SimplCommerce.Module.Core/Areas/Core/ViewModels/AppSettingVm.cs new file mode 100644 index 0000000000..531834b8b5 --- /dev/null +++ b/src/Modules/SimplCommerce.Module.Core/Areas/Core/ViewModels/AppSettingVm.cs @@ -0,0 +1,9 @@ +namespace SimplCommerce.Module.Core.Areas.Core.ViewModels +{ + public class AppSettingVm + { + public string Key { get; set; } + + public string Value { get; set; } + } +} diff --git a/src/Modules/SimplCommerce.Module.Core/wwwroot/admin/configuration/configuration.html b/src/Modules/SimplCommerce.Module.Core/wwwroot/admin/configuration/configuration.html index acd6d12cef..9b218b8dbb 100644 --- a/src/Modules/SimplCommerce.Module.Core/wwwroot/admin/configuration/configuration.html +++ b/src/Modules/SimplCommerce.Module.Core/wwwroot/admin/configuration/configuration.html @@ -10,7 +10,7 @@

{{::vm.translate.get('Application Settings')}}

- +
diff --git a/src/Modules/SimplCommerce.Module.PaymentBraintree/Areas/PaymentBraintree/Controllers/BraintreeApiController.cs b/src/Modules/SimplCommerce.Module.PaymentBraintree/Areas/PaymentBraintree/Controllers/BraintreeApiController.cs index 04e9976b98..cf12b7e0e7 100644 --- a/src/Modules/SimplCommerce.Module.PaymentBraintree/Areas/PaymentBraintree/Controllers/BraintreeApiController.cs +++ b/src/Modules/SimplCommerce.Module.PaymentBraintree/Areas/PaymentBraintree/Controllers/BraintreeApiController.cs @@ -13,6 +13,7 @@ namespace SimplCommerce.Module.PaymentBraintree.Areas.PaymentBraintree.Controlle [Area("PaymentBraintree")] [Authorize(Roles = "admin")] [Route("api/braintree")] + [ApiExplorerSettings(IgnoreApi = true)] public class BraintreeApiController : Controller { private readonly IRepositoryWithTypedId _paymentProviderRepository;