c # – Techniques for refactoring Uncle Bob's own architecture for object / entity queries / LINQ

I have a relatively simple controller logic with ugly parts of creating objects. Some objects are really huge and even if all the controller does is return the object, it looks messy and hard to read. I would like to ask how can I make such cases cleaner? Let me show you some examples:

For example, pay attention to creating viewmodel:

public asynchronous task Edit (Guid id)
{
if (id.IsValidGuid ())
{
// Get the details of the user
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 (userTask, nationalitiesTask, countriesTask);
var user = userTask.Result;
var nationalities = nationalitiesTask.Result;
var countries = countriesTask.Result;
if (user is null)
return 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 the model
var viewModel = new EditUserViewModel
{
User = user,
Id = user.Id,
FirstName = user.FirstName,
LastName = user.LastName,
BirthDay = user.Detail? .BirthDay,
Email = user.Email,
Nationality = user. .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,
CountriesList = countries.List,
NationalitiesList = nationalities.List
};
return the view (viewModel);
}
other
return RedirectToAction ("Index");
}

Or another using LINQ with a huge choice

    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 = de ah in _dbContext.AccountHolders
join uc in _dbContext.UserCompanies on ah.ObjectId is equal to uc.CompanyId
join u in _dbContext.Users on uc.UserId equals u.Id
where ah.Id == accountHolderId
select a new CompanyUserModel
{
UserId = u.Id,
CompanyId = (Guid) uc.CompanyId,
FullName = u.FirstName + "" + u.Name,
Email = u.Email,
PhoneNumber = u.PhoneNumber,
UserCompanyRoleType = uc.Role
};

var prompt = here in _dbContext.UserCompanyInvites
select a new CompanyUserInvite template
{
Id = ci.Id,
CompanyId = ci.CompanyId,
IsAccepted = ci.IsAccepted,
UserEmail = ci.UserEmail,
RoleType = ci.RoleType
};

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

back companyDetailModel;
}

Is it enough to go from creating objects to a private method or is there a better way? Would not it be really tedious to set up a mapper?