c # – Uncle Bob clean architecture refactoring techniques for data objects / entities / LINQ queries

I have a relatively simple controller logic with ugly parts of object creation. Some of the objects are really huge and although all the controller does is return the object, it seems messy and difficult to read. So I would like to ask how I can make these cases cleaner. Let me show you some examples:

For example, pay attention to the creation of viewmodel:

Public asynchronous task Edit (Guid id)
{
if (id.IsValidGuid ())
{
// Get user details
var userTask = ApiGatewayService.GetUserDetail (id, AuthService.BearerToken);
var nationalitiesTask = ApiGatewayService.GetNationalityList (new FilterParameters (), AuthService.BearerToken);
var countriesTask = ApiGatewayService.GetCountryList (new FilterParameters (), AuthService.BearerToken);
Wait Task.WhenAll (User Task, Nationalities Task, Country Task);
var user = userTask.Result;
var nationalities = nationalitiesTasks.Result;
var countries = countriesTask.Result;
if (user is null)
returns NotFound ();
var userAddress = user.PrimaryAddress;
var userHomePhone = user.Phones.FirstOrDefault (x => x.Type == PhoneType.LandLine);
var userMobilePhone = user.Phones.FirstOrDefault (x => x.Type == PhoneType.Mobile);
// See model
var viewModel = new EditUserViewModel
{
User = user,
Id = user.Id,
Name = user.FirstName,
Surname = user.LastName,
BirthDay = user.Detail? .Birthday,
Email = user.Email,
Nationality = user. Detail? Nationality? .Id,
Title = user.Detail! = Null? user.Detail.Title: TitleType.Mr,
ProfilePhotoName = user.Detail? .ProfilePhotoName,
MarketingOptin = user.Detail! = Null? user.Detail.MarketingOptin: false,
ChangePassword = false,
Password = null,
Address_City = userAddress? .City,
Address_Country = userAddress? .Country.Id,
Address_HouseName = userAddress? .HouseName,
Address_HouseNumber = userAddress? .HouseNumber,
Address_Line = userAddress? .AddressLine,
Address_PostCode = userAddress? .PostCode,
Address_StreetName = userAddress? .StreetName,
Home_CountryCode = userHomePhone? .CountryCode? .ToString (),
Home_PhoneNumber = userHomePhone? .PhoneNumber,
Mobile_CountryCode = userMobilePhone? .CountryCode? .ToString (),
Mobile_PhoneNumber = userMobilePhone? .PhoneNumber,
List of countries = countries. List,
List of nationalities = nationalities. List
};
back View (viewModel);
}
plus
return RedirectToAction ("Index");
}

Or another using LINQ with a large selection

    Public CompanyDetailModel GetCompanyDetails (Guid accountHolderId)
{
CompanyDetailModel companyDetailModel = new CompanyDetailModel ();

var accountHolder = _dbContext.AccountHolders.FirstOrDefault (x => x.Id == accountHolderId);

var companyId = accountHolder.ObjectId;
var company = _dbContext.Companies.FirstOrDefault (x => x.Id == companyId);

companyDetailModel.CompanyId = company.Id;
companyDetailModel.Description = company.Description;
companyDetailModel.Name = company.Name;
companyDetailModel.RegistrationNumber = company.RegistrationNumber;
companyDetailModel.VATNumber = company.VATNumber;


var users = from ah in _dbContext.AccountHolders
join uc in _dbContext.UserCompanies in ah.ObjectId equals uc.CompanyId
join u in _dbContext.Users in uc.UserId is equal to u.Id
where ah.Id == accountHolderId
Select a new CompanyUserModel
{
User ID = u.Id,
CompanyId = (Guid) uc.CompanyId,
FullName = u.FirstName + "" + u.LastName,
Email = u.Email,
PhoneNumber = u.PhoneNumber,
UserCompanyRoleType = uc.Role
};

var invite = de ci in _dbContext.UserCompanyInvites
Select new CompanyUserInviteModel
{
Id = ci.Id,
CompanyId = ci.CompanyId,
IsAccepted = ci.IsAccepted,
UserEmail = ci.UserEmail,
RoleType = ci.RoleType
};

companyDetailModel.CompanyUsers = users.ToList ();
companyDetailModel.CompanyUserInvites = invite.ToList ();

return companyDetailModel;
}

Is it enough to take the creation of objects to a private method, or is there a better way? Would not it really be tedious to set up a mapper?