проанализируй мой код
using AutoMapper;
using BuildingFlow_BLL.Models.ViewModels;
using BuildingFlow_DAL.Contract;
using BuildingFlow_Model.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;

namespace BuildingFlow_MVC.Controllers
{
  public class ProjectController : Controller
  {
    private readonly IUnitOfWork _unitOfWork;
    private readonly IMapper _mapper;

    public ProjectController(IUnitOfWork unitOfWork, IMapper mapper)
    {
      _unitOfWork = unitOfWork;
      _mapper = mapper;
    }

    // GET: Project/Index
    public IActionResult Index()
    {

      var projectsRepository = _unitOfWork.GetRepository<Project>();
      var projects = projectsRepository.AsReadOnlyQueryable()
                      .Include(p => p.Client)
                      .Include(p => p.ProjectManagers);

      var projectVMs = _mapper.Map<List<ProjectVM>>(projects.ToList());

      // Дополнительно: маппинг менеджеров для отображения их имен
      foreach (var projectVM in projectVMs)
      {
        var project = projects.FirstOrDefault(p => p.Id == projectVM.Id);
        if (project != null)
        {
          projectVM.ProjectManagers = project.ProjectManagers.;
        }
      }

      return View(projectVMs);
    }

    // GET: Project/Create
    public IActionResult Create()
    {
      var projectVM = new ProjectVM
      {
        Clients = GetClientsSelectList(),
        ProjectManagers = GetProjectManagersSelectList()
      };

      return View(projectVM);
    }

    // POST: Project/Create
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Create(ProjectVM projectVM)
    {
      if (ModelState.IsValid)
      {
        var project = _mapper.Map<Project>(projectVM);

        // Добавление выбранных менеджеров к проекту
        if (projectVM.SelectedProjectManagerIds != null && projectVM.SelectedProjectManagerIds.Any())
        {
          var managers = _unitOfWork.GetRepository<ProjectManager>()
                                    .AsReadOnlyQueryable()
                                    .Where(pm => projectVM.SelectedProjectManagerIds.Contains(pm.Id))
                                    .ToList();
          project.ProjectManagers = managers;
        }

        _unitOfWork.GetRepository<Project>().Create(project);
        await _unitOfWork.SaveChangesAsync();
        return RedirectToAction(nameof(Index));
      }

      // Если модель не валидна, повторно заполняем списки
      projectVM.Clients = GetClientsSelectList();
      projectVM.ProjectManagers = GetProjectManagersSelectList();

      return View(projectVM);
    }

    // GET: Project/Edit/5
    public IActionResult Edit(int id)
    {
      var project = _unitOfWork.GetRepository<Project>()
                               .AsReadOnlyQueryable()
                               .Include(p => p.ProjectManagers)
                               .FirstOrDefault(p => p.Id == id);

      if (project == null)
        return NotFound();

      var projectVM = _mapper.Map<ProjectVM>(project);
      projectVM.SelectedProjectManagerIds = project.ProjectManagers.Select(pm => pm.Id).ToList();

      projectVM.Clients = GetClientsSelectList();
      projectVM.ProjectManagers = GetProjectManagersSelectList();

      return View(projectVM);
    }

    // POST: Project/Edit/5
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Edit(int id, ProjectVM projectVM)
    {
      if (id != projectVM.Id)
        return BadRequest();

      if (ModelState.IsValid)
      {
        var project = _unitOfWork.GetRepository<Project>()
                                 .AsQueryable()
                                 .Include(p => p.ProjectManagers)
                                 .FirstOrDefault(p => p.Id == id);

        if (project == null)
          return NotFound();

        // Обновление свойств проекта
        _mapper.Map(projectVM, project);

        // Обновление связей с менеджерами
        // Удаление существующих связей
        project.ProjectManagers.Clear();

        // Добавление новых связей
        if (projectVM.SelectedProjectManagerIds != null && projectVM.SelectedProjectManagerIds.Any())
        {
          var managers = _unitOfWork.GetRepository<ProjectManager>()
                                    .AsReadOnlyQueryable()
                                    .Where(pm => projectVM.SelectedProjectManagerIds.Contains(pm.Id))
                                    .ToList();
          project.ProjectManagers = managers;
        }
        await _unitOfWork.SaveChangesAsync();
        return RedirectToAction(nameof(Index));
      }

      // Если модель не валидна, повторно заполняем списки
      projectVM.Clients = GetClientsSelectList();
      projectVM.ProjectManagers = GetProjectManagersSelectList();

      return View(projectVM);
    }

    // GET: Project/Delete/5
    public IActionResult Delete(int id)
    {
      var project = _unitOfWork.GetRepository<Project>()
                               .AsReadOnlyQueryable()
                               .Include(p => p.Client)
                               .Include(p => p.ProjectManagers)
                               .FirstOrDefault(p => p.Id == id);

      if (project == null)
        return NotFound();

      var projectVM = _mapper.Map<ProjectVM>(project);
      projectVM.ClientName = project.Client?.Name;
      projectVM.SelectedProjectManagerIds = project.ProjectManagers.Select(pm => pm.Id).ToList();
      projectVM.Clients = GetClientsSelectList();
      projectVM.ProjectManagers = GetProjectManagersSelectList();

      return View(projectVM);
    }

    // POST: Project/Delete/5
    [HttpPost, ActionName("Delete")]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> DeleteConfirmed(int id)
    {
      var project = await _unitOfWork.GetRepository<Project>()
        .AsQueryable()
        .FirstOrDefaultAsync(p=>p.Id==id);
      if (project == null)
        return NotFound();

      _unitOfWork.GetRepository<Project>().Delete(project);
      await _unitOfWork.SaveChangesAsync();
      return RedirectToAction(nameof(Index));
    }

    // Вспомогательные методы для получения списков клиентов и менеджеров
    private IEnumerable<SelectListItem> GetClientsSelectList()
    {
      var clients = _unitOfWork.GetRepository<Client>().AsReadOnlyQueryable().ToList();
      return clients.Select(c => new SelectListItem
      {
        Value = c.Id.ToString(),
        Text = c.Name
      });
    }

    private IEnumerable<SelectListItem> GetProjectManagersSelectList()
    {
      var managers = _unitOfWork.GetRepository<ProjectManager>().AsReadOnlyQueryable().ToList();
      return managers.Select(pm => new SelectListItem
      {
        Value = pm.Id.ToString(),
        Text = pm.Name
      });
    }
  }
}