Loading BusinessLayer/DTOs/CreateOrderDto.cs +1 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,5 @@ public class CreateOrderDto : BaseEntityDto public int UserId { get; set; } public int AddressId { get; set; } public IEnumerable<CartItemDetailDto> CartItems { get; set; } = []; public string? CouponCodeString { get; set; } } BusinessLayer/DTOs/OrderDetailDto.cs +1 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,5 @@ public class OrderDetailDto public int UserId { get; set; } public CouponCode? CouponCode { get; set; } public int AddressId { get; set; } public List<OrderProductDetailDto> OrderProducts { get; set; } = []; } PresentationLayer.Mvc/Areas/Admin/Controllers/GiftCardController.cs +24 −15 Original line number Diff line number Diff line using AutoMapper; using BusinessLayer.DTOs; using BusinessLayer.Services.Interfaces; using Infrastructure.QueryObjects; using Microsoft.AspNetCore.Mvc; using PresentationLayer.Mvc.ActionFilters; using PresentationLayer.Mvc.Models; namespace PresentationLayer.Mvc.Areas.Admin.Controllers; [Area(Constants.Areas.Admin)] [RedirectIfNotAdminActionFilter] public class GiftCardController(IGiftCardService giftCardService) : Controller public class GiftCardController(IGiftCardService giftCardService, IMapper mapper) : Controller { [HttpGet] public async Task<IActionResult> Index([FromQuery] GiftCardFilterDto manufacturerFilterDto) public async Task<IActionResult> Index([FromQuery] GiftCardFilterViewModel giftCardFilterViewModel) { var allGiftCards = await giftCardService.GetAllGiftCardsAsync(manufacturerFilterDto); return View(allGiftCards); var allGiftCards = await giftCardService.GetAllGiftCardsAsync(mapper.Map<GiftCardFilterDto>(giftCardFilterViewModel)); return View(mapper.Map<FilteredResult<GiftCardEditViewModel>>(allGiftCards)); } [HttpGet] public IActionResult Create() { return View(new GiftCardCreateDto return View(new GiftCardCreateViewModel { Name = "", Discount = 0, Loading @@ -30,11 +33,14 @@ public class GiftCardController(IGiftCardService giftCardService) : Controller } [HttpPost] public async Task<IActionResult> Create(GiftCardCreateDto viewModel) public async Task<IActionResult> Create(GiftCardCreateViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var createdManufacturer = await giftCardService.CreateGiftCardAsync(viewModel); var createdManufacturer = await giftCardService.CreateGiftCardAsync(mapper.Map<GiftCardCreateDto>(viewModel)); if (createdManufacturer == null) { ModelState.AddModelError("Id", "Failed to create gift-card."); Loading @@ -51,18 +57,21 @@ public class GiftCardController(IGiftCardService giftCardService) : Controller if (giftCard == null) { ModelState.AddModelError("Id", "Manufacturer not found."); return View(new GiftCardEditDto()); return View(new GiftCardEditViewModel()); } return View(new GiftCardEditDto { Name = giftCard.Name }); return View(new GiftCardEditViewModel { Name = giftCard.Name }); } [HttpPost] public async Task<IActionResult> Edit(GiftCardEditDto viewModel) public async Task<IActionResult> Edit(GiftCardEditViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var updatedManufacturer = await giftCardService.UpdateGiftCardAsync(viewModel); var updatedManufacturer = await giftCardService.UpdateGiftCardAsync(mapper.Map<GiftCardEditDto>(viewModel)); if (updatedManufacturer == null) { ModelState.AddModelError("Id", "Failed to update manufacturer."); Loading @@ -82,7 +91,7 @@ public class GiftCardController(IGiftCardService giftCardService) : Controller return RedirectToAction(nameof(Index)); } return View(giftCard); return View(mapper.Map<GiftCardDetailViewModel>(giftCard)); } [HttpPost] Loading PresentationLayer.Mvc/Areas/Admin/Controllers/ManufacturerController.cs +22 −13 Original line number Diff line number Diff line using AutoMapper; using BusinessLayer.DTOs; using BusinessLayer.Services.Interfaces; using Infrastructure.QueryObjects; using Microsoft.AspNetCore.Mvc; using PresentationLayer.Mvc.ActionFilters; using PresentationLayer.Mvc.Models; namespace PresentationLayer.Mvc.Areas.Admin.Controllers; [Area(Constants.Areas.Admin)] [RedirectIfNotAdminActionFilter] public class ManufacturerController(IManufacturerService manufacturerService) : Controller public class ManufacturerController(IManufacturerService manufacturerService, IMapper mapper) : Controller { [HttpGet] public async Task<IActionResult> Index([FromQuery] ManufacturerFilterDto manufacturerFilterDto) public async Task<IActionResult> Index([FromQuery] ManufacturerFilterViewModel manufacturerFilterDto) { var manufacturers = await manufacturerService.GetManufacturersAsync(manufacturerFilterDto); return View(manufacturers); var manufacturers = await manufacturerService.GetManufacturersAsync(mapper.Map<ManufacturerFilterDto>(manufacturerFilterDto)); return View(mapper.Map<FilteredResult<ManufacturerViewModel>>(manufacturers)); } [HttpGet] public IActionResult Create() { return View(new ManufacturerDto { Name = "" }); return View(new ManufacturerViewModel { Name = "" }); } [HttpPost] public async Task<IActionResult> Create(ManufacturerDto viewModel) public async Task<IActionResult> Create(ManufacturerViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var createdManufacturer = await manufacturerService.CreateManufacturerAsync(viewModel); var createdManufacturer = await manufacturerService.CreateManufacturerAsync(mapper.Map<ManufacturerDto>(viewModel)); if (createdManufacturer == null) { ModelState.AddModelError("Id", "Failed to create manufacturer."); Loading @@ -40,7 +46,7 @@ public class ManufacturerController(IManufacturerService manufacturerService) : [HttpGet] public async Task<IActionResult> Edit(int id) { var manufacturer = await manufacturerService.GetManufacturerByIdAsync(id); var manufacturer = mapper.Map<ManufacturerViewModel>(await manufacturerService.GetManufacturerByIdAsync(id)); if (manufacturer == null) { ModelState.AddModelError("Id", "Manufacturer not found."); Loading @@ -51,11 +57,14 @@ public class ManufacturerController(IManufacturerService manufacturerService) : } [HttpPost] public async Task<IActionResult> Edit(ManufacturerDto viewModel) public async Task<IActionResult> Edit(ManufacturerViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var updatedManufacturer = await manufacturerService.UpdateManufacturerAsync(viewModel); var updatedManufacturer = await manufacturerService.UpdateManufacturerAsync(mapper.Map<ManufacturerDto>(viewModel)); if (updatedManufacturer == null) { ModelState.AddModelError("Id", "Failed to update manufacturer."); Loading PresentationLayer.Mvc/Areas/Admin/Controllers/OrderController.cs +15 −9 Original line number Diff line number Diff line using AutoMapper; using BusinessLayer.DTOs; using BusinessLayer.Services.Interfaces; using Infrastructure.QueryObjects; using Microsoft.AspNetCore.Mvc; using PresentationLayer.Mvc.ActionFilters; using PresentationLayer.Mvc.Models; namespace PresentationLayer.Mvc.Areas.Admin.Controllers; [Area(Constants.Areas.Admin)] [RedirectIfNotAdminActionFilter] public class OrderController(IOrderService orderService) : Controller public class OrderController(IOrderService orderService, IMapper mapper) : Controller { [HttpGet] public async Task<IActionResult> Index([FromQuery] PaginationDto pagination) public async Task<IActionResult> Index([FromQuery] PaginationViewModel pagination) { var orders = await orderService.GetOrdersAsync(pagination); return View(orders); var orders = await orderService.GetOrdersAsync(mapper.Map<PaginationDto>(pagination)); return View(mapper.Map<FilteredResult<OrderDetailViewModel>>(orders)); } [HttpGet] public async Task<IActionResult> Edit(int id) { var order = await orderService.GetOrderDetailByIdAsync(id); var order = mapper.Map<OrderDetailViewModel>(await orderService.GetOrderByIdAsync(id)); if (order == null) { ModelState.AddModelError("Id", "Order not found."); Loading @@ -30,11 +33,14 @@ public class OrderController(IOrderService orderService) : Controller } [HttpPost] public async Task<IActionResult> Edit(OrderDetailDto viewModel) public async Task<IActionResult> Edit(OrderDetailViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var updatedOrder = await orderService.UpdateOrderAsync(viewModel); var updatedOrder = await orderService.UpdateOrderAsync(mapper.Map<OrderDetailDto>(viewModel)); if (updatedOrder == null) { ModelState.AddModelError(nameof(OrderDetailDto.Status), "Failed to update order."); Loading Loading
BusinessLayer/DTOs/CreateOrderDto.cs +1 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,5 @@ public class CreateOrderDto : BaseEntityDto public int UserId { get; set; } public int AddressId { get; set; } public IEnumerable<CartItemDetailDto> CartItems { get; set; } = []; public string? CouponCodeString { get; set; } }
BusinessLayer/DTOs/OrderDetailDto.cs +1 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,5 @@ public class OrderDetailDto public int UserId { get; set; } public CouponCode? CouponCode { get; set; } public int AddressId { get; set; } public List<OrderProductDetailDto> OrderProducts { get; set; } = []; }
PresentationLayer.Mvc/Areas/Admin/Controllers/GiftCardController.cs +24 −15 Original line number Diff line number Diff line using AutoMapper; using BusinessLayer.DTOs; using BusinessLayer.Services.Interfaces; using Infrastructure.QueryObjects; using Microsoft.AspNetCore.Mvc; using PresentationLayer.Mvc.ActionFilters; using PresentationLayer.Mvc.Models; namespace PresentationLayer.Mvc.Areas.Admin.Controllers; [Area(Constants.Areas.Admin)] [RedirectIfNotAdminActionFilter] public class GiftCardController(IGiftCardService giftCardService) : Controller public class GiftCardController(IGiftCardService giftCardService, IMapper mapper) : Controller { [HttpGet] public async Task<IActionResult> Index([FromQuery] GiftCardFilterDto manufacturerFilterDto) public async Task<IActionResult> Index([FromQuery] GiftCardFilterViewModel giftCardFilterViewModel) { var allGiftCards = await giftCardService.GetAllGiftCardsAsync(manufacturerFilterDto); return View(allGiftCards); var allGiftCards = await giftCardService.GetAllGiftCardsAsync(mapper.Map<GiftCardFilterDto>(giftCardFilterViewModel)); return View(mapper.Map<FilteredResult<GiftCardEditViewModel>>(allGiftCards)); } [HttpGet] public IActionResult Create() { return View(new GiftCardCreateDto return View(new GiftCardCreateViewModel { Name = "", Discount = 0, Loading @@ -30,11 +33,14 @@ public class GiftCardController(IGiftCardService giftCardService) : Controller } [HttpPost] public async Task<IActionResult> Create(GiftCardCreateDto viewModel) public async Task<IActionResult> Create(GiftCardCreateViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var createdManufacturer = await giftCardService.CreateGiftCardAsync(viewModel); var createdManufacturer = await giftCardService.CreateGiftCardAsync(mapper.Map<GiftCardCreateDto>(viewModel)); if (createdManufacturer == null) { ModelState.AddModelError("Id", "Failed to create gift-card."); Loading @@ -51,18 +57,21 @@ public class GiftCardController(IGiftCardService giftCardService) : Controller if (giftCard == null) { ModelState.AddModelError("Id", "Manufacturer not found."); return View(new GiftCardEditDto()); return View(new GiftCardEditViewModel()); } return View(new GiftCardEditDto { Name = giftCard.Name }); return View(new GiftCardEditViewModel { Name = giftCard.Name }); } [HttpPost] public async Task<IActionResult> Edit(GiftCardEditDto viewModel) public async Task<IActionResult> Edit(GiftCardEditViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var updatedManufacturer = await giftCardService.UpdateGiftCardAsync(viewModel); var updatedManufacturer = await giftCardService.UpdateGiftCardAsync(mapper.Map<GiftCardEditDto>(viewModel)); if (updatedManufacturer == null) { ModelState.AddModelError("Id", "Failed to update manufacturer."); Loading @@ -82,7 +91,7 @@ public class GiftCardController(IGiftCardService giftCardService) : Controller return RedirectToAction(nameof(Index)); } return View(giftCard); return View(mapper.Map<GiftCardDetailViewModel>(giftCard)); } [HttpPost] Loading
PresentationLayer.Mvc/Areas/Admin/Controllers/ManufacturerController.cs +22 −13 Original line number Diff line number Diff line using AutoMapper; using BusinessLayer.DTOs; using BusinessLayer.Services.Interfaces; using Infrastructure.QueryObjects; using Microsoft.AspNetCore.Mvc; using PresentationLayer.Mvc.ActionFilters; using PresentationLayer.Mvc.Models; namespace PresentationLayer.Mvc.Areas.Admin.Controllers; [Area(Constants.Areas.Admin)] [RedirectIfNotAdminActionFilter] public class ManufacturerController(IManufacturerService manufacturerService) : Controller public class ManufacturerController(IManufacturerService manufacturerService, IMapper mapper) : Controller { [HttpGet] public async Task<IActionResult> Index([FromQuery] ManufacturerFilterDto manufacturerFilterDto) public async Task<IActionResult> Index([FromQuery] ManufacturerFilterViewModel manufacturerFilterDto) { var manufacturers = await manufacturerService.GetManufacturersAsync(manufacturerFilterDto); return View(manufacturers); var manufacturers = await manufacturerService.GetManufacturersAsync(mapper.Map<ManufacturerFilterDto>(manufacturerFilterDto)); return View(mapper.Map<FilteredResult<ManufacturerViewModel>>(manufacturers)); } [HttpGet] public IActionResult Create() { return View(new ManufacturerDto { Name = "" }); return View(new ManufacturerViewModel { Name = "" }); } [HttpPost] public async Task<IActionResult> Create(ManufacturerDto viewModel) public async Task<IActionResult> Create(ManufacturerViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var createdManufacturer = await manufacturerService.CreateManufacturerAsync(viewModel); var createdManufacturer = await manufacturerService.CreateManufacturerAsync(mapper.Map<ManufacturerDto>(viewModel)); if (createdManufacturer == null) { ModelState.AddModelError("Id", "Failed to create manufacturer."); Loading @@ -40,7 +46,7 @@ public class ManufacturerController(IManufacturerService manufacturerService) : [HttpGet] public async Task<IActionResult> Edit(int id) { var manufacturer = await manufacturerService.GetManufacturerByIdAsync(id); var manufacturer = mapper.Map<ManufacturerViewModel>(await manufacturerService.GetManufacturerByIdAsync(id)); if (manufacturer == null) { ModelState.AddModelError("Id", "Manufacturer not found."); Loading @@ -51,11 +57,14 @@ public class ManufacturerController(IManufacturerService manufacturerService) : } [HttpPost] public async Task<IActionResult> Edit(ManufacturerDto viewModel) public async Task<IActionResult> Edit(ManufacturerViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var updatedManufacturer = await manufacturerService.UpdateManufacturerAsync(viewModel); var updatedManufacturer = await manufacturerService.UpdateManufacturerAsync(mapper.Map<ManufacturerDto>(viewModel)); if (updatedManufacturer == null) { ModelState.AddModelError("Id", "Failed to update manufacturer."); Loading
PresentationLayer.Mvc/Areas/Admin/Controllers/OrderController.cs +15 −9 Original line number Diff line number Diff line using AutoMapper; using BusinessLayer.DTOs; using BusinessLayer.Services.Interfaces; using Infrastructure.QueryObjects; using Microsoft.AspNetCore.Mvc; using PresentationLayer.Mvc.ActionFilters; using PresentationLayer.Mvc.Models; namespace PresentationLayer.Mvc.Areas.Admin.Controllers; [Area(Constants.Areas.Admin)] [RedirectIfNotAdminActionFilter] public class OrderController(IOrderService orderService) : Controller public class OrderController(IOrderService orderService, IMapper mapper) : Controller { [HttpGet] public async Task<IActionResult> Index([FromQuery] PaginationDto pagination) public async Task<IActionResult> Index([FromQuery] PaginationViewModel pagination) { var orders = await orderService.GetOrdersAsync(pagination); return View(orders); var orders = await orderService.GetOrdersAsync(mapper.Map<PaginationDto>(pagination)); return View(mapper.Map<FilteredResult<OrderDetailViewModel>>(orders)); } [HttpGet] public async Task<IActionResult> Edit(int id) { var order = await orderService.GetOrderDetailByIdAsync(id); var order = mapper.Map<OrderDetailViewModel>(await orderService.GetOrderByIdAsync(id)); if (order == null) { ModelState.AddModelError("Id", "Order not found."); Loading @@ -30,11 +33,14 @@ public class OrderController(IOrderService orderService) : Controller } [HttpPost] public async Task<IActionResult> Edit(OrderDetailDto viewModel) public async Task<IActionResult> Edit(OrderDetailViewModel viewModel) { if (!ModelState.IsValid) return View(viewModel); if (!ModelState.IsValid) { return View(viewModel); } var updatedOrder = await orderService.UpdateOrderAsync(viewModel); var updatedOrder = await orderService.UpdateOrderAsync(mapper.Map<OrderDetailDto>(viewModel)); if (updatedOrder == null) { ModelState.AddModelError(nameof(OrderDetailDto.Status), "Failed to update order."); Loading