public async Task <ActionResult> EseguiAzione(Guid id, int azione, string pin = "") { try { switch ((ActionEnum)azione) { case ActionEnum.ELIMINA: var em = await ApiGateway.GetEmendamento(id); await ApiGateway.EliminaEM(id); return(Json(Url.Action("RiepilogoEmendamenti", "Emendamenti", new { id = em.UIDAtto }), JsonRequestBehavior.AllowGet)); case ActionEnum.RITIRA: await ApiGateway.RitiraEM(id); break; case ActionEnum.FIRMA: var resultFirma = await ApiGateway.FirmaEM(id, pin); var listaErroriFirma = new List <string>(); foreach (var itemFirma in resultFirma.Where(itemFirma => itemFirma.Value.Contains("ERROR"))) { listaErroriFirma.Add($"{listaErroriFirma.Count + 1} - {itemFirma.Value.Substring(7)}"); } if (listaErroriFirma.Count > 0) { return(Json( new { message = $"Errori nella procedura di firma: {listaErroriFirma.Aggregate((i, j) => i + ", " + j)}" }, JsonRequestBehavior.AllowGet)); } break; case ActionEnum.DEPOSITA: var resultDeposita = await ApiGateway.DepositaEM(id, pin); var listaErroriDeposito = new List <string>(); foreach (var itemDeposito in resultDeposita.Where(itemDeposito => itemDeposito.Value.Contains("ERROR"))) { listaErroriDeposito.Add( $"{listaErroriDeposito.Count + 1} - {itemDeposito.Value.Substring(7)}"); } if (listaErroriDeposito.Count > 0) { return(Json( new { message = $"Errori nella procedura di deposito: {listaErroriDeposito.Aggregate((i, j) => i + ", " + j)}" }, JsonRequestBehavior.AllowGet)); } break; default: throw new ArgumentOutOfRangeException(nameof(azione), azione, null); } return(Json(Request.UrlReferrer.ToString(), JsonRequestBehavior.AllowGet)); } catch (Exception e) { Console.WriteLine(e); return(Json(JsonConvert.DeserializeObject <ErrorResponse>(e.Message), JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> EseguiAzioneMassive(ComandiAzioneModel model) { try { if (model.ListaEmendamenti == null || !model.ListaEmendamenti.Any()) { var listaEM = await ApiGateway.GetEmendamenti(model.AttoUId, (ClientModeEnum)model.ClientMode, OrdinamentoEnum.Default, 1, 50); model.ListaEmendamenti = listaEM.Data.Results.Select(em => em.UIDEM).ToList(); } switch (model.Azione) { case ActionEnum.FIRMA: var resultFirma = await ApiGateway.FirmaEM(model); var listaErroriFirma = new List <string>(); foreach (var itemFirma in resultFirma.Where(itemFirma => itemFirma.Value.Contains("ERROR"))) { listaErroriFirma.Add($"{listaErroriFirma.Count + 1} - {itemFirma.Value.Substring(7)}"); } if (listaErroriFirma.Count > 0) { return(Json( new { message = $"Errori nella procedura di firma: {listaErroriFirma.Aggregate((i, j) => i + ", " + j)}" }, JsonRequestBehavior.AllowGet)); } break; case ActionEnum.DEPOSITA: var resultDeposita = await ApiGateway.DepositaEM(model); var listaErroriDeposito = new List <string>(); foreach (var itemDeposito in resultDeposita.Where(itemDeposito => itemDeposito.Value.Contains("ERROR"))) { listaErroriDeposito.Add( $"{listaErroriDeposito.Count + 1} - {itemDeposito.Value.Substring(7)}"); } if (listaErroriDeposito.Count > 0) { return(Json( new { message = $"Errori nella procedura di deposito: {listaErroriDeposito.Aggregate((i, j) => i + ", " + j)}" }, JsonRequestBehavior.AllowGet)); } break; case ActionEnum.INVITA: var resultInvita = await ApiGateway.NotificaEM(model); var listaErroriInvita = new List <string>(); foreach (var itemInvito in resultInvita.Where(itemInvita => itemInvita.Value.Contains("ERROR"))) { listaErroriInvita.Add( $"{listaErroriInvita.Count + 1} - {itemInvito.Value.Substring(7)}"); } if (listaErroriInvita.Count > 0) { return(Json( new { message = $"Errori nella procedura di invito: {listaErroriInvita.Aggregate((i, j) => i + ", " + j)}" }, JsonRequestBehavior.AllowGet)); } break; default: throw new ArgumentOutOfRangeException(nameof(model.Azione), model.Azione, null); } return(Json(Request.UrlReferrer.ToString(), JsonRequestBehavior.AllowGet)); } catch (Exception e) { Console.WriteLine(e); return(Json(JsonConvert.DeserializeObject <ErrorResponse>(e.Message), JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> NuovoSUBEmendamento(Guid id, Guid ref_em) { var emModel = await ApiGateway.GetNuovoEmendamentoModel(id, ref_em); return(View("EmendamentoForm", emModel)); }
public async Task <ActionResult> ModificaMetaDatiEmendamento(Guid id) { var emModel = await ApiGateway.GetModificaMetaDatiEmendamentoModel(id); return(View("MetaDatiForm", emModel)); }
public InvoiceController(ApiGateway buybackGateway) { _buybackGateway = buybackGateway; }
public async Task <ActionResult> GetListaDestinatari(Guid atto, TipoDestinatarioNotificaEnum tipo) { var destinatari = await ApiGateway.GetListaDestinatari(atto, tipo); return(Json(destinatari, JsonRequestBehavior.AllowGet)); }
internal async Task <Dictionary <Guid, BodyModel> > GeneraPDFEmendamenti(IEnumerable <EmendamentiDto> Emendamenti, int Da, int A, string _pathTemp) { var listaPercorsiEM = new Dictionary <Guid, BodyModel>(); try { listaPercorsiEM = Emendamenti.ToDictionary(em => em.UIDEM, em => new BodyModel()); Action <BodyModel> CreaPDF = item => { Log.Debug($"Percorso EM [{item.Path}]"); //Creo PDF EM con allegati PdfStamper.CreaPDF(item.Body, item.Path, item.EM, model.urlCLIENT); }; if (Da != 0 && A != 0) { Log.Debug($"Stampo solo DA [{Da}], A [{A}]"); var j = 1; var k = Da; var k_end = A; foreach (var item in Emendamenti) { if (j >= k) { if (j > k_end) { break; } var bodyPDF = await ApiGateway.GetBodyEM(item.UIDEM, TemplateTypeEnum.PDF); var nameFilePDF = $"{item.DisplayTitle.Replace(" ", "_").Replace("all'", "")}_{item.UIDEM}_{DateTime.Now:ddMMyyyy_hhmmss}.pdf"; var FilePathComplete = Path.Combine(_pathTemp, nameFilePDF); var dettagliCreaPDF = new BodyModel { Path = FilePathComplete, Body = bodyPDF, EM = item }; listaPercorsiEM[item.UIDEM] = dettagliCreaPDF; } j++; } } else { foreach (var item in Emendamenti) { var bodyPDF = await ApiGateway.GetBodyEM(item.UIDEM, TemplateTypeEnum.PDF); var nameFilePDF = $"{item.DisplayTitle.Replace(" ", "_").Replace("all'", "")}_{item.UIDEM}_{DateTime.Now:ddMMyyyy_hhmmss}.pdf"; var FilePathComplete = Path.Combine(_pathTemp, nameFilePDF); var dettagliCreaPDF = new BodyModel { Path = FilePathComplete, Body = bodyPDF, EM = item }; listaPercorsiEM[item.UIDEM] = dettagliCreaPDF; } } listaPercorsiEM.AsParallel().ForAll(item => CreaPDF(item.Value)); } catch (Exception ex) { Log.Error("GeneraPDFEmendamenti Error-->", ex); } return(listaPercorsiEM); }
private async void DoWork() { var utenteRichiedente = await ApiGateway.GetPersona(stampa.UIDUtenteRichiesta); try { Log.Debug( $"[{stampa.UIDStampa}] Utente Richiedente [{utenteRichiedente.DisplayName}], EMAIL [{utenteRichiedente.email}]"); if (stampa.Tentativi < Convert.ToInt16(model.NumMaxTentativi)) { var dirFascicolo = $"Fascicolo_{stampa.UIDStampa}_{DateTime.Now:ddMMyyyy_hhmmss}"; var _pathTemp = Path.Combine(model.CartellaLavoroTemporanea, dirFascicolo); if (!Directory.Exists(_pathTemp)) { Directory.CreateDirectory(_pathTemp); } var resultEmendamenti = await ApiGateway.JobGetEmendamenti(stampa.QueryEM, 1); var has_next = resultEmendamenti.Paging.Has_Next; var listaEMendamenti = resultEmendamenti.Results.ToList(); while (has_next) { resultEmendamenti = await ApiGateway.JobGetEmendamenti(stampa.QueryEM, resultEmendamenti.Paging.Page + 1); has_next = resultEmendamenti.Paging.Has_Next; listaEMendamenti.AddRange(resultEmendamenti.Results); } Log.Debug($"[{stampa.UIDStampa}] Totale EM [{listaEMendamenti.Count}]"); var atto = stampa.ATTI; if (stampa.NotificaDepositoEM) { //STAMPA PDF DEPOSITATO (BACKGROUND MODE) Log.Debug($"[{stampa.UIDStampa}] BACKGROUND MODE - Genera PDF Depositato"); var listaPdfEmendamentiGenerati = await GeneraPDFEmendamenti(listaEMendamenti, stampa.Da, stampa.A, _pathTemp); Log.Debug($"[{stampa.UIDStampa}] BACKGROUND MODE - Salva EM nel repository"); var em = listaEMendamenti.First(); var dirSeduta = $"Seduta_{atto.SEDUTE.Data_seduta:yyyyMMdd}"; var dirPDL = Regex.Replace($"{atto.TIPI_ATTO.Tipo_Atto} {atto.NAtto}", @"[^0-9a-zA-Z]+", "_"); var pathRepository = $"{model.RootRepository}/{dirSeduta}/{dirPDL}"; if (!Directory.Exists(pathRepository)) { Directory.CreateDirectory(pathRepository); } var destinazioneDeposito = Path.Combine(pathRepository, Path.GetFileName(listaPdfEmendamentiGenerati.First().Value.Path)); SpostaFascicolo(listaPdfEmendamentiGenerati.First().Value.Path, destinazioneDeposito); stampa.PathFile = Path.Combine($"{dirSeduta}/{dirPDL}", Path.GetFileName(listaPdfEmendamentiGenerati.First().Value.Path)); stampa.UIDEM = em.UIDEM; await ApiGateway.JobUpdateFileStampa(stampa); var bodyMail = await ApiGateway.GetBodyEM(em.UIDEM, TemplateTypeEnum.MAIL, true); if (atto.SEDUTE.Data_effettiva_inizio.HasValue) { var ruoloSegreteriaAssempblea = await ApiGateway.GetRuolo(RuoliIntEnum.Segreteria_Assemblea); Log.Debug( $"[{stampa.UIDStampa}] BACKGROUND MODE - EM depositato il {listaEMendamenti.First().DataDeposito}"); if (Convert.ToDateTime(listaEMendamenti.First().DataDeposito) > atto.SEDUTE.Data_effettiva_inizio.Value) { Log.Debug($"[{stampa.UIDStampa}] BACKGROUND MODE - Seduta già iniziata"); await ApiGateway.SendMail(new MailModel { DA = model.EmailFrom, A = $"{ruoloSegreteriaAssempblea.ADGroupShort}@consiglio.regione.lombardia.it", OGGETTO = $"[TRATTAZIONE AULA] {atto.TIPI_ATTO.Tipo_Atto} {atto.NAtto}: Depositato {listaEMendamenti.First().DisplayTitle}", MESSAGGIO = bodyMail }); } } else { Log.Debug($"[{stampa.UIDStampa}] BACKGROUND MODE - Seduta non è ancora iniziata"); } var email_destinatari = $"{utenteRichiedente.email};[email protected]"; var email_destinatariGruppo = string.Empty; var email_destinatariGiunta = string.Empty; if (em.id_gruppo > 10000) { Log.Debug( $"[{stampa.UIDStampa}] BACKGROUND MODE - Invio mail a Capo Gruppo e Segreteria Politica"); var capoGruppo = await ApiGateway.GetCapoGruppo(em.id_gruppo); var segreteriaPolitica = await ApiGateway.GetSegreteriaPolitica(em.id_gruppo, false, true); if (segreteriaPolitica.Any()) { email_destinatariGruppo = segreteriaPolitica.Select(u => u.email) .Aggregate((i, j) => $"{i};{j}"); } if (capoGruppo != null) { email_destinatariGruppo += $";{capoGruppo.email}"; } } else { Log.Debug($"[{stampa.UIDStampa}] BACKGROUND MODE - Invio mail a Giunta Regionale"); var giuntaRegionale = await ApiGateway.GetGiuntaRegionale(); var segreteriaGiuntaRegionale = await ApiGateway.GetSegreteriaGiuntaRegionale(false, true); if (segreteriaGiuntaRegionale.Any()) { email_destinatariGiunta += segreteriaGiuntaRegionale.Select(u => u.email) .Aggregate((i, j) => $"{i};{j}"); } if (giuntaRegionale.Any()) { email_destinatariGiunta += giuntaRegionale.Select(u => u.email).Aggregate((i, j) => $"{i};{j}"); } } if (!string.IsNullOrEmpty(email_destinatariGruppo)) { email_destinatari += ";" + email_destinatariGruppo; } if (!string.IsNullOrEmpty(email_destinatariGiunta)) { email_destinatari += ";" + email_destinatariGiunta; } var resultInvio = await ApiGateway.SendMail(new MailModel { DA = model.EmailFrom, A = email_destinatari, OGGETTO = $"{atto.TIPI_ATTO.Tipo_Atto} {atto.NAtto}: Depositato {listaEMendamenti.First().DisplayTitle}", MESSAGGIO = bodyMail, pathAttachment = destinazioneDeposito, IsDeposito = true }); if (resultInvio) { await ApiGateway.JobSetInvioStampa(stampa); } } else { //STAMPA - STANDARD MODE Log.Debug($"[{stampa.UIDStampa}] STANDARD MODE - Genera PDF"); var bodyCopertina = await ApiGateway.GetCopertina(new CopertinaModel { Atto = atto, TotaleEM = listaEMendamenti.Count, Ordinamento = stampa.Ordine.HasValue ? (OrdinamentoEnum)stampa.Ordine.Value : OrdinamentoEnum.Presentazione }); var nameFilePDFCopertina = $"COPERTINAEM_{DateTime.Now:ddMMyyyy_hhmmss}.pdf"; var DirCopertina = Path.Combine(_pathTemp, nameFilePDFCopertina); PdfStamper.CreaPDFCopertina(bodyCopertina, DirCopertina); var listaPdfEmendamentiGenerati = await GeneraPDFEmendamenti(listaEMendamenti, stampa.Da, stampa.A, _pathTemp); var countNonGenerati = listaPdfEmendamentiGenerati.Count(item => !File.Exists(item.Value.Path)); Log.Debug($"PDF NON GENERATI [{countNonGenerati}]"); //Funzione che fascicola i PDF creati prima var nameFileTarget = $"Fascicolo_{DateTime.Now:ddMMyyyy_hhmmss}.pdf"; var FilePathTarget = Path.Combine(_pathTemp, nameFileTarget); PdfStamper.CreateMergedPDF(FilePathTarget, DirCopertina, listaPdfEmendamentiGenerati.ToDictionary(item => item.Key, item => item.Value.Path)); var _pathStampe = Path.Combine(model.CartellaLavoroStampe, nameFileTarget); Log.Debug($"[{stampa.UIDStampa}] Percorso stampe {_pathStampe}"); SpostaFascicolo(FilePathTarget, _pathStampe); var LinkFile = Path.Combine(model.CartellaStampeLink, nameFileTarget); //Funzione che genera il LINK per il download del documento appena creato var URLDownload = Path.Combine(model.urlCLIENT, LinkFile); //Funzione che genera il LINK per il download del documento appena creato stampa.PathFile = nameFileTarget; await ApiGateway.JobUpdateFileStampa(stampa); if (stampa.Scadenza.HasValue) { var resultInvio = await ApiGateway.SendMail(new MailModel { DA = model.EmailFrom, A = utenteRichiedente.email, OGGETTO = "Link download fascicolo", MESSAGGIO = URLDownload }); if (resultInvio) { await ApiGateway.JobSetInvioStampa(stampa); } } else { if (stampa.Ordine.HasValue) { if ((OrdinamentoEnum)stampa.Ordine.Value == OrdinamentoEnum.Presentazione) { atto.LinkFascicoloPresentazione = URLDownload; } if ((OrdinamentoEnum)stampa.Ordine.Value == OrdinamentoEnum.Votazione) { atto.LinkFascicoloVotazione = URLDownload; } await ApiGateway.ModificaFilesAtto(atto); } } } PulisciCartellaLavoroTemporanea(_pathTemp); } else { await ApiGateway.SendMail(new MailModel { DA = model.EmailFrom, A = utenteRichiedente.email, OGGETTO = "Errore generazione stampa", MESSAGGIO = $"ID stampa: [{stampa.UIDStampa}], per l'atto: [{stampa.UIDAtto}]" }); } } catch (Exception ex) { Log.Error($"[{stampa.UIDStampa}] ERROR", ex); try { await ApiGateway.JobErrorStampa(stampa.UIDStampa, ex.Message); await ApiGateway.JobUnLockStampa(stampa.UIDStampa); } catch (Exception ex2) { Log.Error($"[{stampa.UIDStampa}] ERROR", ex2); try { await ApiGateway.SendMail(new MailModel { DA = model.EmailFrom, A = utenteRichiedente.email, OGGETTO = "Errore generazione fascicolo", MESSAGGIO = ex.Message }); } catch (Exception exMail) { Log.Error($"[{stampa.UIDStampa}] ERROR", exMail); await ApiGateway.JobErrorStampa(stampa.UIDStampa, exMail.Message); } } } }
/// <summary> /// Ritorna la lista dei firmatari per visualizzazione client /// </summary> /// <param name="firme"></param> /// <param name="currentUId"></param> /// <param name="tipo"></param> /// <param name="tag"></param> /// <returns></returns> public static async Task <string> GetFirmatariEM(IEnumerable <FirmeDto> firme, Guid currentUId, FirmeTipoEnum tipo, string token, bool tag = false) { try { if (firme == null) { return(string.Empty); } var firmeDtos = firme.ToList(); if (!firmeDtos.Any()) { return(string.Empty); } var apiGateway = new ApiGateway(token); if (tag) { var result = new List <string>(); var firmaProponente = firmeDtos.First(); var proponente = await apiGateway.Persone.Get(firmaProponente.UID_persona); if (string.IsNullOrEmpty(firmaProponente.Data_ritirofirma)) { result.Add(_chipTemplate.Replace("{{foto}}", proponente.foto) .Replace("{{DisplayName}}", $"<b>{firmaProponente.FirmaCert}</b>") .Replace("{{OPZIONALE}}", "")); } else { result.Add(_chipTemplate.Replace("{{foto}}", proponente.foto) .Replace("{{DisplayName}}", $"<span style='text-decoration:line-through;color:grey'>{firmaProponente.FirmaCert}</span>") .Replace("{{OPZIONALE}}", "")); } firmeDtos.Remove(firmaProponente); foreach (var firmeDto in firmeDtos) { var persona = await apiGateway.Persone.Get(firmeDto.UID_persona); if (string.IsNullOrEmpty(firmeDto.Data_ritirofirma)) { result.Add(_chipTemplate.Replace("{{foto}}", persona.foto) .Replace("{{DisplayName}}", $"{firmeDto.FirmaCert}").Replace("{{OPZIONALE}}", "")); } else { result.Add( $"<span style='text-decoration:line-through;color:grey'>{firmeDto.FirmaCert}</span>"); } } return(result.Aggregate((i, j) => i + j)); } var titoloColonna = tipo == FirmeTipoEnum.DOPO_DEPOSITO ? "Firme aggiunte dopo il deposito" : "Firmatari dell'emendamento"; var table = "<ul class=\"collection\">{{BODY_FIRME}}</ul>"; var body = "<li class=\"collection-header\"><h4 style=\"margin-left:10px\">Firmatari</h4></li>"; var em = await apiGateway.Emendamento.Get(firmeDtos.Select(f => f.UIDEM).First()); foreach (var firmeDto in firmeDtos) { body += "<li class=\"collection-item with-header\">"; if (!string.IsNullOrEmpty(firmeDto.Data_ritirofirma)) { body += $"<div><del>{firmeDto.FirmaCert}</del>"; body += $"<br/><label>firmato il </label><del>{firmeDto.Data_firma}</del>"; body += $"<br/><label>ritirato il </label>{firmeDto.Data_ritirofirma}</div>"; } else { body += $"<div>{firmeDto.FirmaCert}"; body += $"<br/><label>firmato il </label>{firmeDto.Data_firma}"; if (currentUId == firmeDto.UID_persona) { if (em.IDStato >= (int)StatiEnum.Depositato) { body += $"<a class='chip red center white-text secondary-content' style=\"min-width:unset;margin-top:-16px\" onclick=\"RitiraFirma('{firmeDto.UIDEM}')\"><i class='icon material-icons'>delete</i> Ritira</a>"; } else { body += $"<a class='chip red center white-text secondary-content' style=\"min-width:unset;margin-top:-16px\" onclick=\"EliminaFirma('{firmeDto.UIDEM}')\"><i class='icon material-icons'>delete</i> Elimina</a>"; } } } body += "</li>"; } return(table.Replace("{{titoloColonna}}", titoloColonna).Replace("{{BODY_FIRME}}", body)); } catch (Exception e) { Log.Error("GetFirmatariEM", e); throw e; } }
public async Task <ActionResult> GetGruppi() { return(Json(await ApiGateway.GetGruppi(), JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> GetPersona(Guid id) { return(Json(await ApiGateway.GetPersona(id), JsonRequestBehavior.AllowGet)); }