I want to order my list by idEtatD but this attribute isn't my table primarykey or id it's a normal attribute migrated from another table,nut OrderBy or OrderByDescending didn't give me a result my list still not ordered by idEtatD.
public ActionResult ListeDemande( int? page)
{
traçabilitérepository=new TraçabilitéDemandeRepository(db);
var listdemandes = (from d in db.Demande_Gabarit
join t in db.Traçabilité_Demande_Gabarit
on d.id_demande equals t.iddemande into ThisList
from t in ThisList.DefaultIfEmpty()
select new
{
id_demande=d.id_demande,
NumDemande = d.NumDemande,
Emetteur = d.Emetteur,
Date = d.Date,
Ligne = d.Ligne.designation,
Etat = t.Etat_Demande_Gabarit.EtatDemande
}).ToList().Select(x => new DemandeViewModel()
{
NumDemande = x.NumDemande,
Emetteur = x.Emetteur,
Date = x.Date,
designation = x.Ligne,
EtatDemande = x.Etat,
id_demande = x.id_demande
});
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(listdemandes.OrderByDescending(x => x.idEtatD).ToList().ToPagedList(pageNumber, pageSize));
}
Please I need your help and thank you.
You can order the items at the beginning, but you need to include it in the list:
traçabilitérepository = new TraçabilitéDemandeRepository(db);
var listdemandes = (from d in db.Demande_Gabarit
join t in db.Traçabilité_Demande_Gabarit
on d.id_demande equals t.iddemande into ThisList
from t in ThisList.DefaultIfEmpty()
orderby t.idEtatD descending
select new
{
id_demande = d.id_demande,
NumDemande = d.NumDemande,
Emetteur = d.Emetteur,
Date = d.Date,
Ligne = d.Ligne.designation,
Etat = t.Etat_Demande_Gabarit.EtatDemande,
idEtatD = XXXX
}).ToList().Select(x => new DemandeViewModel()
{
NumDemande = x.NumDemande,
Emetteur = x.Emetteur,
Date = x.Date,
designation = x.Ligne,
EtatDemande = x.Etat,
id_demande = x.id_demande
});
Related
Here is the code:
[HttpGet]
public async Task<IActionResult> Get([FromQuery] string sort, [FromQuery] string sortColumn, [FromQuery] int perPage = 10, [FromQuery] int page = 0)
{
string searchString = string.Empty;
var ncquery = _context.NonConformities .AsQueryable();
var ncfilter = Helper.OrderBy(ncquery, sortColumn, sort == "asc")
.Skip(perPage * (page - 1))
.Take(perPage);
if (!String.IsNullOrEmpty(searchString))
{
ncfilter = ncfilter.Where(nc => nc.Title.Contains(searchString));
}
var data = await (from nc in _context.NonConformities
join mdt in _context.MasterData on nc.NcTypes equals mdt.Id
join mdo in _context.MasterData on nc.Originator equals mdo.Id
join mdd in _context.MasterData on nc.Department equals mdd.Id
join mdc in _context.MasterData on nc.Category equals mdc.Id
join mds in _context.MasterData on nc.Status equals mds.Id
select new
{
Id = nc.Id,
Title = nc.Title,
Originator = mdo.Items,
Department = mdd.Items,
Date = nc.Date,
NcTypes = mdt.Items,
Category = mdc.Items,
Status = mds.Items,
Description = nc.Description,
Evidence = nc.Evidence,
ReviewRecommendation = nc.ReviewRecommendation,
}).ToListAsync();
//await ncfilter.ToListAsync();
var totalItems = await _context.NonConformities.CountAsync();
int totalPages = (int)Math.Ceiling(totalItems / (double)perPage);
var model = new PaginatedItems<NonConformity>(page, perPage, totalPages, data );
return Ok(model);
}
I suspect the issue is in the line
var model = new PaginatedItems<NonConformity>(page, perPage, totalPages, data );
You need to have a list of NonConformity instead of a list of anonymous type:
select new
{
Id = nc.Id,
...
})
.ToListAsync() // Fetch the records from the database
.Select( x => new NonConformity(...)); // Transform them into NonConformity objects
I need an help here! I always get an error from linq (wrong expression). Should work but it´s not... I don´t get any error when order by max Id but I need to get the Id of the max date group by IDFiscal and CodigoXPCliente. I tried diferent ways but I always get an error.
var queryTemp =
(from u in _userManager.Users.Where(u => u.TipoUsuario == "Cliente")
join ass in context.AssessoresCliente on u.Id equals ass.ApplicationUser.Id into temp_ass
from temp in temp_ass
select new ListaBaseCliente_Atendimento
{
Nome = u.Nome,
IDFiscal = u.IDFiscal,
Email = u.Email,
PhoneNumber = u.PhoneNumber,
DataPessoa = u.DataPessoa,
DataCadastro = temp.DataCadastro,
CodigoXPCliente = temp.CodigoXPCliente,
AssessorCambio = temp.AssessorCambio,
AssessorProtect = temp.AssessorProtect,
CodigoAssessorXP = temp.CodigoAssessorXP,
ClienteCambio = temp.ClienteCambio,
ClienteProtect = temp.ClienteProtect,
ClienteXP = temp.ClienteXP,
AssessorXP = temp.AssessorXP,
CadastroValido = true,
DataRegistroUsuario = temp.DataRegistroUsuario,
DataArquivo = DataHoje,
ContaXPNova = temp.ContaXPNova,
ImportacaoBitrix = temp.ImportacaoBitrix,
IdAssessoresCliente = temp.Id,
RegistroValido = temp.RegistroValido
}).AsEnumerable();
var agrup = from s in queryTemp group s by new { s.IDFiscal, s.CodigoXPCliente } into g
select g.OrderByDescending(t => t.DataRegistroUsuario).FirstOrDefault();
I use fluent API and Ef Core.
This is my linq:
var data = (from candidateHP in _cempContexto.CandidateHiringProcessSummary
join jobsHP in _cempContexto.JobHiringProcessSummary on candidateHP.JobCode equals jobsHP.JobCode
join job in _cempContexto.Vaga on jobsHP.JobCode equals job.Codigo
join candidateJob in _cempContexto.TrCandidatoVaga on new { X = job.Codigo, Y = candidateCode } equals new { X = candidateJob.VagaCodigo, Y = candidateJob.CandidatoCodigo }
where
candidateHP.CandidateCode == candidateCode
select
new
{
JobCode = jobsHP.JobCode,
CompanyCode = job.EmpresaCodigo,
Title = job.Titulo,
HasImage = true,
CompanyName = job.NomeEmpresa,
QuantityJobs = job.QuantidadeVaga,
Location = job.CidadeCodigo,
QuantityResumeSent = jobsHP.QuantityResumeSent,
JobStatusCode = jobsHP.StatusCode,
CandidateStatusCode = candidateHP.StatusCode,
StatusCode = job.StatusCodigo,
ResumeSentDate = candidateJob.Data,
InsertDate = job.DataDeCadastro,
EndDate = job.DataDeSaida,
city= _cempContexto.TrVagaCidade.SelectMany(p => _cempContexto.TrVagaCidade.Where(q => q.VagaCodigo == candidateHP.JobCode).Select(q => new { q })).ToList()
})
.ToList();
I need to Fill city with that subquery. I need a better way to do that, How could I proceed?
Split code into two queries :
var query = (from candidateHP in _cempContexto.CandidateHiringProcessSummary
join jobsHP in _cempContexto.JobHiringProcessSummary on candidateHP.JobCode equals jobsHP.JobCode
join job in _cempContexto.Vaga on jobsHP.JobCode equals job.Codigo
join candidateJob in _cempContexto.TrCandidatoVaga on new { X = job.Codigo, Y = candidateCode } equals new { X = candidateJob.VagaCodigo, Y = candidateJob.CandidatoCodigo }
where
candidateHP.CandidateCode == candidateCode
select
new
{ jobsHP = jobsHP, job = job, candidateJob = candidateJob}).ToList();
var data = query.Select(x => new {
JobCode = x.jobsHP.JobCode,
CompanyCode = x.job.EmpresaCodigo,
Title = x.job.Titulo,
HasImage = true,
CompanyName = x.job.NomeEmpresa,
QuantityJobs = x.job.QuantidadeVaga,
Location = x.job.CidadeCodigo,
QuantityResumeSent = x.jobsHP.QuantityResumeSent,
JobStatusCode = x.jobsHP.StatusCode,
CandidateStatusCode = x.candidateHP.StatusCode,
StatusCode = x.job.StatusCodigo,
ResumeSentDate = x.candidateJob.Data,
InsertDate = x.job.DataDeCadastro,
EndDate = x.job.DataDeSaida,
city= query.Select(y => y.candidateHP.JobCode).Select(q => new { q })).ToList()
})
.ToList();
var approverlist = _db.ApprvRejClaimTravelCashByApproverIdIPhone(ProjectSession.CompanyUserId, ProjectSession.CompanyId, Status).AsEnumerable().ToList();`
var results =
from item in approverlist
group item by item.ClaimId
into g
select new
{
ClaimId = g.Key,
Name = g.First().Name,
Amount = g.Sum(s => s.Amount),
Description = g.First().Description,
Status = g.First().Status,
CreatedDate = g.First().CreatedDate,
SubmitedDate = g.First().SubmitedDate,
FullName = g.First().FullName,
ApproverStatus = g.First().ApproverStatus,
CurrencySymbol = g.First().CurrencySymbol,
chkbox = g.First().chkbox,
IsHierarchy = g.First().IsHierarchy,
ColumnCategory = g.First().ColumnCategory,
ColumnCategoryCode = g.First().ColumnCategoryCode
};
return Json(results.ToDataSourceResult(request));
getting undefined in column Amount when i bind this result to my kendo mvc grid,,,,any one have idea why this happens ?
Also tried below one but same result undefined :
var results = from x in approverlist
group x.ClaimId by new { x.ClaimId, x.Name, x.Description, x.Status, x.CreatedDate, x.SubmitedDate, x.FullName, x.ApproverStatus, x.CurrencySymbol, x.chkbox, x.IsHierarchy, x.ColumnCategory, x.ColumnCategoryCode }
into g
select new { g.Key.ClaimId, g.Key.Name, Amount = g.Sum(), g.Key.Description, g.Key.Status, g.Key.CreatedDate, g.Key.SubmitedDate, g.Key.FullName, g.Key.ApproverStatus, g.Key.CurrencySymbol, g.Key.chkbox, g.Key.IsHierarchy, g.Key.ColumnCategory, g.Key.ColumnCategoryCode };
I have the following query in controller and I want to store a column value in a variable but I am not being able to iterate it. Here is my code:
var srmas = (
from SRMAs in db.SRMAs
join SRMAStatus in db.SRMAStatus on SRMAs.Status equals SRMAStatus.Id
join PurchaseOrders in db.PurchaseOrders on SRMAs.PONumber equals PurchaseOrders.PONumber
join Suppliers in db.Suppliers on PurchaseOrders.SupplierID equals Suppliers.SupplierID
join SRMADetails in db.SRMADetails on SRMAs.Id equals SRMADetails.SRMAId
where(SRMAs.Id == srmaid)
group SRMADetails by new
{
SRMADetails.Id,
SRMADetails.SRMAId,
SRMADetails.SupplierPartNum,
SRMAs.PONumber,
SRMAs.ActualAmount,
SRMAs.ApprovedOn,
SRMAs.Status,
SRMAs.TrackingNumber,
SRMAs.SupplierRMANumber,
SRMAs.RequestedFromSupp,
SRMAs.CreatedOn,
Suppliers.SupplierName,
SRMAStatus.StatusName,
PurchaseOrders.PODate,
PurchaseOrders.suppliersOrderNumber
} into grp
select new
{
grp.Key.Status,
grp.Key.SRMAId,
grp.Key.Id,
grp.Key.PONumber,
grp.Key.SupplierRMANumber,
grp.Key.ActualAmount,
grp.Key.SupplierPartNum,
grp.Key.RequestedFromSupp,
grp.Key.TrackingNumber,
grp.Key.ApprovedOn,
grp.Key.SupplierName,
grp.Key.StatusName,
grp.Key.PODate,
grp.Key.suppliersOrderNumber,
grp.Key.CreatedOn,
Sum = grp.Sum(SRMADetails => SRMADetails.Cost * SRMADetails.QtyReturned)
}
).ToList();
System.Collections.IEnumerable et = (System.Collections.IEnumerable)srmas;
IEnumerator it = et.GetEnumerator();
while (it.MoveNext())
{
SRMA current = (SRMA)it.Current;
Response.Write(current.Status);
}
ViewBag.SRMAs = srmas.Select(srma => new IndexViewModel
{
Id = srma.SRMAId,
SupplierRMANum = srma.SupplierRMANumber,
SRMADetailsID = srma.Id,
PONumber = srma.PONumber,
CreatedOn = srma.CreatedOn,
SupplierName = srma.SupplierName,
SRMAStatus = srma.StatusName,
Status = srma.Status,
suppliersOrderNumber = srma.suppliersOrderNumber,
PODate = srma.PODate,
Sum = srma.Sum,
TrackingNumber = srma.TrackingNumber,
ActualAmount = srma.ActualAmount
}).ToList();
I just want to get Status value of first record. How do I do it?