public Task BindModelAsync(ModelBindingContext bindingContext) { DateTime begin = Convert.ToDateTime(bindingContext.ValueProvider.GetValue("begin").FirstValue); DateTime end = Convert.ToDateTime(bindingContext.ValueProvider.GetValue("end").FirstValue); string name = bindingContext.ValueProvider.GetValue("name").FirstValue; string number = bindingContext.ValueProvider.GetValue("number").FirstValue; bool emitted = Convert.ToBoolean(bindingContext.ValueProvider.GetValue("emitted").FirstValue); bool ascending = Convert.ToBoolean(bindingContext.ValueProvider.GetValue("ascending").FirstValue); int page = Convert.ToInt32(bindingContext.ValueProvider.GetValue("page").FirstValue); var inputModel = new BodiesInputModel(begin, end, name, number, emitted, ascending, page, InvoicesOptions.CurrentValue); bindingContext.Result = ModelBindingResult.Success(inputModel); return(Task.CompletedTask); }
public async Task <ManyBodyDTO> GetBodiesAsync(BodiesInputModel input) { var(begin, end, name, number, emitted, ascending, page, limit, offset) = input; IQueryable <BodyModel> getBodiesQuery = DbContext.Bodies .Where(b => b.Data >= begin && b.Data <= end) .Include(b => b.Causale) .Include(b => b.DatiDDT) .ThenInclude(ddt => ddt.RiferimentoNumeroLinea) .Include(b => b.DatiPagamento) .ThenInclude(dp => dp.DettaglioPagamento) .Include(b => b.DatiRiepilogo) .Include(b => b.DettaglioLinee) .ThenInclude(dl => dl.CodiceArticolo) .Include(b => b.DettaglioLinee) .ThenInclude(dl => dl.ScontoMaggiorazione) .Include(b => b.DatiBeniServizi) .Include(b => b.CedentePrestatore) .ThenInclude(cp => cp.ContiBancari) .Include(b => b.CessionarioCommittente) .AsNoTracking(); if (ascending) { getBodiesQuery = getBodiesQuery .OrderBy(b => b.Data) .ThenBy(b => b.Id); } else { getBodiesQuery = getBodiesQuery .OrderByDescending(b => b.Data) .ThenBy(b => b.Id); } if (number != null) { getBodiesQuery = getBodiesQuery.Where(b => b.Numero == number); } if (emitted) { getBodiesQuery = getBodiesQuery .Where(b => b.CedentePrestatoreId == OwnerId); if (name != null) { getBodiesQuery = getBodiesQuery .Where(b => b.CessionarioCommittente.Denominazione .Contains(name) || (b.CessionarioCommittente.Nome + " " + b.CessionarioCommittente.Cognome) .Contains(name)); } } else { getBodiesQuery = getBodiesQuery .Where(b => b.CessionarioCommittenteId == OwnerId); if (name != null) { getBodiesQuery = getBodiesQuery .Where(b => b.CedentePrestatore.Denominazione .Contains(name) || (b.CedentePrestatore.Nome + " " + b.CedentePrestatore.Cognome) .Contains(name)); } } List <BodyModel> getBodiesModel = await getBodiesQuery .Skip(offset) .Take(limit) .ToListAsync() .ConfigureAwait(false); ManyBodyDTO getBodiesDTO = new ManyBodyDTO(); int bodiesFound = await getBodiesQuery .CountAsync() .ConfigureAwait(false); getBodiesDTO.TotalPages = (int)Math.Ceiling((double)bodiesFound / InvoicesOptions.InvoicesPerPage); foreach (var bodiesElement in getBodiesModel) { bodiesElement.CedentePrestatore.BodyModelCP = null; bodiesElement.CedentePrestatore.BodyModelCC = null; bodiesElement.CessionarioCommittente.BodyModelCP = null; bodiesElement.CessionarioCommittente.BodyModelCC = null; bodiesElement.DatiDDT = bodiesElement.DatiDDT .OrderBy(ddt => ddt.DataDDT) .ThenBy(ddt => ddt.NumeroDDT) .ToList(); bodiesElement.DettaglioLinee = bodiesElement.DettaglioLinee .OrderBy(dl => dl.NumeroLinea) .ToList(); getBodiesDTO.Bodies.Add(Mapper.Map <BodyModel, BodyDTO>(bodiesElement)); } foreach (var b in getBodiesDTO.Bodies) { b.DettaglioLinee = b.DettaglioLinee .OrderBy(dl => dl.NumeroLinea) .ToList(); } return(getBodiesDTO); }
public Task <ManyBodyDTO> GetBodiesAsync(BodiesInputModel model) { return(InvService.GetBodiesAsync(model)); }