public async Task <QueryResModel <List <DatiPagamentoDTO> > > GetDatiPagamento(int invoiceId) { var resModel = new QueryResModel <List <DatiPagamentoDTO> >(); var datiPagamento = await DbContext.DatiPagamento .Where(dp => dp.BodyModelId == invoiceId) .Include(dp => dp.DettaglioPagamento) .ToListAsync() .ConfigureAwait(false); resModel.Data = new List <DatiPagamentoDTO>(); if (datiPagamento.Count > 0) { resModel.Succeeded = true; foreach (var dp in datiPagamento) { resModel.Data.Add(Mapper.Map <DatiPagamentoModel, DatiPagamentoDTO>(dp)); } return(resModel); } else { resModel.Succeeded = false; resModel.Error = "Nessun pagamento trovato"; return(resModel); } }
// @Contatti public async Task <QueryResModel <List <ContattiDTO> > > GetContacts(int cliforId) { var resModel = new QueryResModel <List <ContattiDTO> >(); var contatti = await DbContext.Contatti .Where(c => c.CliforModelId == cliforId) .ToListAsync() .ConfigureAwait(false); resModel.Data = new List <ContattiDTO>(); if (contatti.Count > 0) { resModel.Succeeded = true; foreach (var c in contatti) { resModel.Data.Add(Mapper.Map <ContattiModel, ContattiDTO>(c)); } return(resModel); } else { resModel.Succeeded = false; resModel.Error = "Nessun contatto trovato"; return(resModel); } }
public async Task <QueryResModel <Dictionary <string, int> > > GetCPIds(string name) { QueryResModel <Dictionary <string, int> > res = new QueryResModel <Dictionary <string, int> >(); res.Data = new Dictionary <string, int>(); var result = await DbContext.Clifor .Where(cf => cf.Denominazione.Contains(name) || cf.Nome.Contains(name) || cf.Cognome.Contains(name)) .Select(cf => new { denominazione = cf.Denominazione, nome = cf.Nome, cognome = cf.Cognome, id = cf.Id }) .ToListAsync() .ConfigureAwait(false); foreach (var r in result) { var temp = r.denominazione == null ? r.nome + " " + r.cognome : r.denominazione; res.Data.Add(temp, r.id); } return(res); }
public async Task <QueryResModel <CliForDTO> > UpdateAsync(CliForModel data) { QueryResModel <CliForDTO> queryResult = new QueryResModel <CliForDTO>(); int changes = -1; if (await DbContext.Clifor.AnyAsync(cf => cf.Id == data.Id).ConfigureAwait(false)) { DbContext.Clifor.Update(data); changes = await DbContext .SaveChangesAsync() .ConfigureAwait(false); } if (changes <= 0) { queryResult.Succeeded = false; queryResult.Error = changes == -1 ? "Error: CliFor not found" : "Error: Update failed."; return(queryResult); } else { CliForModel cliFor = await DbContext.Clifor .Where(cf => cf.Id == data.Id) .AsNoTracking() .FirstAsync() .ConfigureAwait(false); queryResult.Data = Mapper.Map <CliForModel, CliForDTO>(cliFor); return(queryResult); } }
public async Task <QueryResModel <BodyDTO> > UpdateAsync(BodyModel invoice) { QueryResModel <BodyDTO> queryResult = new QueryResModel <BodyDTO>(); int changes = -1; if (await DbContext.Bodies.AnyAsync(b => b.Id == invoice.Id).ConfigureAwait(false)) { DbContext.Bodies.Update(invoice); changes = await DbContext.SaveChangesAsync().ConfigureAwait(false); } if (changes <= 0) { queryResult.Succeeded = false; queryResult.Error = changes == -1 ? "Error: invoice not found" : "Error: Update failed."; return(queryResult); } else { BodyModel bodyModel = await DbContext.Bodies .Where(cf => cf.Id == invoice.Id) .AsNoTracking() .FirstAsync() .ConfigureAwait(false); queryResult.Data = Mapper.Map <BodyModel, BodyDTO>(bodyModel); return(queryResult); } }
public async Task <QueryResModel <List <string> > > GetRoles() { QueryResModel <List <string> > roles = new QueryResModel <List <string> >(); List <IdentityRole> ide = await RoleManager.Roles.ToListAsync(); roles.Data = ide.Select(r => r.Name).OrderByDescending(r => r).ToList(); return(roles); }
public IActionResult Auth([FromHeader] string authorization) { QueryResModel <UserAuth> result = AuthService.Auth(authorization); if (result.Succeeded) { return(Ok(result.Data)); } else { return(BadRequest(result.Error)); } }
public async Task <IActionResult> GetOneCliForAsync(int id) { QueryResModel <CliForDTO> qrm = await InvService.GetOneCliForAsync(id).ConfigureAwait(false); if (qrm.Succeeded) { return(Ok(qrm.Data)); } else { return(NotFound(qrm.Error)); } }
public async Task <IActionResult> SignIn([FromForm] string username, [FromForm] string password) { QueryResModel <string> result = await AuthService.SignIn(username, password).ConfigureAwait(false); if (result.Succeeded) { return(Ok(result.Data)); } else { return(BadRequest(result.Error)); } }
public async Task <IActionResult> UpdateBodyAsync([FromBody] BodyModel invoice) { QueryResModel <BodyDTO> qrm = await InvService.UpdateAsync(invoice).ConfigureAwait(false); if (qrm.Succeeded) { return(Ok(qrm.Data)); } else { return(BadRequest(qrm.Error)); } }
public async Task <IActionResult> GetContattoAsync(int id) { QueryResModel <List <ContattiDTO> > qrm = await InvService.GetContacts(id).ConfigureAwait(false); if (qrm.Succeeded) { return(Ok(qrm.Data)); } else { return(BadRequest(qrm.Error)); } }
public async Task <IActionResult> UpdateCliForAsync([FromBody] CliForModel cliFor) { QueryResModel <CliForDTO> qrm = await InvService.UpdateAsync(cliFor).ConfigureAwait(false); if (qrm.Succeeded) { return(Ok(qrm.Data)); } else { return(BadRequest(qrm.Error)); } }
public async Task <IActionResult> GetCPIds([FromForm] string name) { QueryResModel <Dictionary <string, int> > qrm = await InvService.GetCPIds(name).ConfigureAwait(false); if (qrm.Succeeded) { return(Ok(qrm.Data)); } else { return(NotFound(qrm.Error)); } }
public async Task <IActionResult> GetCliForsAsync(CliForsInputModel model) { QueryResModel <ManyCliForDTO> qrm = await InvService.GetCliForsAsync(model).ConfigureAwait(false); if (qrm.Succeeded) { return(Ok(qrm.Data)); } else { return(NotFound(qrm.Error)); } }
public async Task <IActionResult> GetRoles() { QueryResModel <List <string> > result = await AuthService.GetRoles().ConfigureAwait(false); if (result.Succeeded) { return(Ok(result.Data)); } else { return(BadRequest(result.Error)); } }
public async Task <QueryResModel <string> > SignIn(string username, string password) { QueryResModel <string> result = new QueryResModel <string>(); IdentityUser user = await UserManager.FindByNameAsync(username).ConfigureAwait(false); if (user != null && await UserManager.CheckPasswordAsync(user, password).ConfigureAwait(false)) { List <Claim> claims = new List <Claim> { new Claim(JwtRegisteredClaimNames.Sub, username), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; var roles = await UserManager.GetRolesAsync(user).ConfigureAwait(false); foreach (var role in roles) { var roleClaim = new Claim(ClaimTypes.Role, role); claims.Add(roleClaim); } var secretByte = Encoding.UTF8.GetBytes(AuthOptions.CurrentValue.Secret); var key = new SymmetricSecurityKey(secretByte); var algorithm = SecurityAlgorithms.HmacSha256; var signingCredentials = new SigningCredentials(key, algorithm); var token = new JwtSecurityToken( AuthOptions.CurrentValue.Issuer, AuthOptions.CurrentValue.Audience, claims: claims, notBefore: DateTime.Now, expires: DateTime.Now.AddHours(1), signingCredentials: signingCredentials ); var tokenJson = new JwtSecurityTokenHandler().WriteToken(token); result.Succeeded = true; result.Data = tokenJson; } else { result.Error = "Error: Username and password do not match an existing account."; } return(result); }
public async Task <IActionResult> GetPaymentsAsync(PagamentiInputModel input) { QueryResModel <ManyDettaglioPagamentoDTO> qrm = await InvService.GetPaymentsAsync(input).ConfigureAwait(false); if (qrm.Succeeded) { return(Ok(qrm.Data)); } else { return(NotFound(qrm.Error)); } }
public async Task <QueryResModel <ManyCliForDTO> > GetCliForsAsync(CliForsInputModel input) { QueryResModel <ManyCliForDTO> queryResult = new QueryResModel <ManyCliForDTO>(); IQueryable <CliForModel> IQclifors = DbContext.Clifor .Where(cf => cf.Nome.ToLower().Contains(input.PartialName) || cf.Cognome.ToLower().Contains(input.PartialName) || cf.Denominazione.ToLower().Contains(input.PartialName) || cf.CodiceFiscale.ToLower().Contains(input.PartialName) || (cf.IdPaese + cf.IdCodice).ToLower().Contains(input.PartialName) ) .Include(cf => cf.Contatti) .Include(cf => cf.ContiBancari) .Include(cf => cf.Sedi) .OrderBy(cf => cf.Denominazione ?? (cf.Nome + cf.Cognome)); List <CliForModel> clifors = await IQclifors .Skip(input.Offset) .Take(input.Limit) .ToListAsync() .ConfigureAwait(false); ManyCliForDTO cliForsDTO = new ManyCliForDTO(); queryResult.Data.Count = await IQclifors .CountAsync() .ConfigureAwait(false); foreach (var cf in clifors) { queryResult.Data.CliFors.Add(Mapper.Map <CliForModel, CliForDTO>(cf)); } if (queryResult.Data.Count == 0) { queryResult.Succeeded = false; queryResult.Error = "No resources found."; } return(queryResult); }
public QueryResModel <UserAuth> Auth(string token) { if (token.Contains("Bearer ")) { token = token.Split(" ")[1]; } else { return(new QueryResModel <UserAuth> { Succeeded = false, Error = "Invalid JWT Token" }); } JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler(); JwtSecurityToken jwtToken = handler.ReadJwtToken(token); IEnumerable <Claim> claims = jwtToken.Claims; QueryResModel <UserAuth> user = new QueryResModel <UserAuth>(); user.Data = new UserAuth(); foreach (var claim in claims) { switch (claim.Type) { case "sub": user.Data.Username = claim.Value; break; case ClaimTypes.Role: user.Data.Role = claim.Value; break; default: break; } } return(user); }
public async Task <QueryResModel <ManyDettaglioPagamentoDTO> > GetPaymentsAsync(PagamentiInputModel input) { QueryResModel <ManyDettaglioPagamentoDTO> queryResult = new QueryResModel <ManyDettaglioPagamentoDTO>(); queryResult.Data = new ManyDettaglioPagamentoDTO(); queryResult.Data.Payments = new List <PaymentsDTO>(); IQueryable <DettaglioPagamentoModel> paymentsQuery = DbContext.DettaglioPagamento .Where(dp => dp.PaymentDate == null && dp.DatiPagamento.Active) .OrderBy(dp => dp.DataScadenzaPagamento); if (input.EndDate != null) { paymentsQuery = paymentsQuery .Where(dp => dp.DataScadenzaPagamento <= input.EndDate || dp.DataScadenzaPagamento == null); } if (input.Emitted) { paymentsQuery = paymentsQuery .Where(dp => dp.DatiPagamento.BodyModel.CedentePrestatoreId == OwnerId); if (input.Name != null) { paymentsQuery = paymentsQuery .Where(dp => dp.DatiPagamento.BodyModel.CessionarioCommittente.Denominazione.Contains(input.Name) || (dp.DatiPagamento.BodyModel.CessionarioCommittente.Nome + " " + dp.DatiPagamento.BodyModel.CessionarioCommittente.Cognome).Contains(input.Name)); } } else { paymentsQuery = paymentsQuery .Where(dp => dp.DatiPagamento.BodyModel.CessionarioCommittenteId == OwnerId); if (input.Name != null) { paymentsQuery = paymentsQuery .Where(dp => dp.DatiPagamento.BodyModel.CedentePrestatore.Denominazione.Contains(input.Name) || (dp.DatiPagamento.BodyModel.CedentePrestatore.Nome + " " + dp.DatiPagamento.BodyModel.CedentePrestatore.Cognome).Contains(input.Name)); } } List <DettaglioPagamentoModel> payments = await paymentsQuery .Skip(input.Offset) .Take(input.Limit) .ToListAsync() .ConfigureAwait(false); int nrOfPayments = await paymentsQuery .CountAsync() .ConfigureAwait(false); queryResult.Data.TotalPages = (int)Math.Ceiling((double)nrOfPayments / InvoicesOptions.PaymentsPerPage); foreach (var p in payments) { int cliforId = await DbContext.DettaglioPagamento .Where(dp => dp.Id == p.Id) .Select(dp => input.Emitted ? dp.DatiPagamento.BodyModel.CessionarioCommittenteId : dp.DatiPagamento.BodyModel.CedentePrestatore.Id) .FirstOrDefaultAsync() .ConfigureAwait(false); string clifor = await DbContext.Clifor .Where(dp => dp.Id == cliforId) .Select(cf => cf.Denominazione ?? cf.Cognome + " " + cf.Nome) .FirstOrDefaultAsync() .ConfigureAwait(false); List <ContiBancariModel> conti = await DbContext.DettaglioPagamento .Where(dp => dp.Id == p.Id) .Select(dp => input.Emitted ? dp.DatiPagamento.BodyModel.CessionarioCommittente.ContiBancari : dp.DatiPagamento.BodyModel.CedentePrestatore.ContiBancari) .FirstOrDefaultAsync() .ConfigureAwait(false); string numero = await DbContext.DettaglioPagamento .Where(dp => dp.Id == p.Id) .Select(dp => dp.DatiPagamento.BodyModel.Numero) .FirstOrDefaultAsync() .ConfigureAwait(false); DateTime data = await DbContext.DettaglioPagamento .Where(dp => dp.Id == p.Id) .Select(dp => dp.DatiPagamento.BodyModel.Data) .FirstOrDefaultAsync() .ConfigureAwait(false); queryResult.Data.Payments.Add(new PaymentsDTO { DettaglioPagamento = Mapper.Map <DettaglioPagamentoModel, DettaglioPagamentoDTO>(p), CliforId = cliforId, Clifor = clifor, ContiBancari = Mapper.Map <List <ContiBancariModel>, List <ContiBancariDTO> >(conti), Numero = numero, Data = data }); } if (nrOfPayments == 0) { queryResult.Succeeded = false; queryResult.Error = "Resources not found."; } return(queryResult); }
// @Clifor public async Task <QueryResModel <CliForDTO> > GetOneCliForAsync(int id) { QueryResModel <CliForDTO> queryResult = new QueryResModel <CliForDTO>(); CliForModel cliFor = await DbContext.Clifor .Where(cf => cf.Id == id) .Include(cf => cf.Contatti) .Include(cf => cf.ContiBancari) .Include(cf => cf.Sedi) .AsNoTracking() .FirstOrDefaultAsync() .ConfigureAwait(false); if (cliFor.Id != 0) { cliFor.BodyModelCP = await DbContext.Bodies .Where(b => b.CedentePrestatoreId == cliFor.Id) .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) .ThenInclude(cc => cc.ContiBancari) .OrderByDescending(b => b.Data) .Take(5) .ToListAsync(); cliFor.BodyModelCC = await DbContext.Bodies .Where(b => b.CessionarioCommittenteId == cliFor.Id) .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.CedentePrestatore) .ThenInclude(cp => cp.ContiBancari) .OrderByDescending(b => b.Data) .Take(5) .ToListAsync(); foreach (var inv in cliFor.BodyModelCP) { inv.CedentePrestatore = null; inv.CessionarioCommittente.BodyModelCC = null; inv.CessionarioCommittente.BodyModelCP = null; if (inv.ImportoTotaleDocumento == null) { inv.ImportoTotaleDocumento = 0; foreach (var pagamento in inv.DatiPagamento) { foreach (var dettaglio in pagamento.DettaglioPagamento) { inv.ImportoTotaleDocumento += dettaglio.ImportoPagamento; } } } } foreach (var inv in cliFor.BodyModelCC) { inv.CessionarioCommittente = null; inv.CedentePrestatore.BodyModelCC = null; inv.CedentePrestatore.BodyModelCP = null; if (inv.ImportoTotaleDocumento == null) { inv.ImportoTotaleDocumento = 0; foreach (var pagamento in inv.DatiPagamento) { foreach (var dettaglio in pagamento.DettaglioPagamento) { inv.ImportoTotaleDocumento += dettaglio.ImportoPagamento; } } } } queryResult.Data = Mapper.Map <CliForModel, CliForDTO>(cliFor); } else { queryResult.Data = null; queryResult.Succeeded = false; queryResult.Error = "Resource not found"; } return(queryResult); }