Commit c418c46b authored by Michal Bilanin's avatar Michal Bilanin 🙄
Browse files

fix: mappings

parent 9198ebbb
Loading
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ using BusinessLayer.Services.Interfaces;
using Infrastructure.QueryObjects;
using Microsoft.AspNetCore.Mvc;
using PresentationLayer.Mvc.ActionFilters;
using PresentationLayer.Mvc.Areas.Customer.Models;
using PresentationLayer.Mvc.Models;

namespace PresentationLayer.Mvc.Areas.Admin.Controllers;
@@ -16,13 +17,13 @@ public class OrderController(IOrderService orderService, IMapper mapper) : Contr
    public async Task<IActionResult> Index([FromQuery] PaginationViewModel pagination)
    {
        var orders = await orderService.GetOrdersAsync(mapper.Map<PaginationDto>(pagination));
        return View(mapper.Map<FilteredResult<OrderDetailViewModel>>(orders));
        return View(mapper.Map<FilteredResult<OrderViewModel>>(orders));
    }

    [HttpGet]
    public async Task<IActionResult> Edit(int id)
    {
        var order = mapper.Map<OrderDetailViewModel>(await orderService.GetOrderByIdAsync(id));
        var order = mapper.Map<OrderDetailViewModel>(await orderService.GetOrderDetailByIdAsync(id));
        if (order == null)
        {
            ModelState.AddModelError("Id", "Order not found.");
+4 −4
Original line number Diff line number Diff line
@@ -50,18 +50,18 @@ public class TagController(ITagService tagService, IMapper mapper) : Controller
        if (tag == null)
        {
            ModelState.AddModelError("Id", "Tag not found.");
            return View(tag);
            return View(mapper.Map<TagViewModel>(tag));
        }

        return View(tag);
        return View(mapper.Map<TagViewModel>(tag));
    }

    [HttpPost]
    public async Task<IActionResult> Edit(TagDto viewModel)
    public async Task<IActionResult> Edit(TagViewModel viewModel)
    {
        if (!ModelState.IsValid) return View(viewModel);

        var updatedTag = await tagService.UpdateTagAsync(viewModel);
        var updatedTag = await tagService.UpdateTagAsync(mapper.Map<TagDto>(viewModel));
        if (updatedTag == null)
        {
            ModelState.AddModelError("Id", "Failed to update tag.");
+1 −1
Original line number Diff line number Diff line
@using BusinessLayer.DTOs
@using PresentationLayer.Mvc
@model Infrastructure.QueryObjects.FilteredResult<PresentationLayer.Mvc.Models.OrderDetailViewModel>
@model Infrastructure.QueryObjects.FilteredResult<PresentationLayer.Mvc.Areas.Customer.Models.OrderViewModel>

@{
    ViewData[Constants.Keys.Title] = "Orders";
+3 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@ public class MvcMapperInstaller : Profile
        CreateMap<UserSimpleViewModel, UserDto>().ReverseMap();
        CreateMap<UserUpdateRestrictedViewModel, UserDto>().ReverseMap();
        CreateMap<UserUpdateRestrictedViewModel, UserUpdateDto>().ReverseMap();
        CreateMap<UserUpdateViewModel, UserDto>().ReverseMap();
        CreateMap<UserUpdateViewModel, UserUpdateDto>().ReverseMap();

        CreateMap<AddToCartViewModel, AddToCartDto>().ReverseMap();
        CreateMap<BaseEntityViewModel, BaseEntityDto>().ReverseMap();
        CreateMap<CartItemDetailViewModel, CartItemDetailDto>().ReverseMap();