Exemplo n.º 1
0
        public async Task <IHttpActionResult> GetEmendamenti(BaseRequest <EmendamentiDto> model)
        {
            try
            {
                var atto = await _logicAtti.GetAtto(model.id);

                if (atto == null)
                {
                    return(NotFound());
                }

                model.param.TryGetValue("CLIENT_MODE", out object CLIENT_MODE); // per trattazione aula
                model.param.TryGetValue("VIEW_MODE", out object viewMode);      // per vista preview/griglia
                ViewModeEnum VIEW_MODE = ViewModeEnum.GRID;
                if (viewMode != null)
                {
                    Enum.TryParse(viewMode.ToString(), out VIEW_MODE);
                }
                var session = await GetSession();

                var persona = await _logicPersone.GetPersona(session);

                var ricerca_presidente_regione = await _logicAdmin.GetUtenti(new BaseRequest <PersonaDto>
                {
                    page   = 1,
                    size   = 1,
                    filtro = new List <FilterStatement <PersonaDto> >
                    {
                        new FilterStatement <PersonaDto>
                        {
                            PropertyId = nameof(PersonaDto.Ruoli),
                            Operation  = Operation.EqualTo,
                            Value      = (int)RuoliIntEnum.Presidente_Regione,
                            Connector  = FilterStatementConnector.And
                        }
                    }
                }, session
                                                                             , Request.RequestUri);

                var presidente = ricerca_presidente_regione.Results.First();
                var results    =
                    await _logicEm.GetEmendamenti(model, persona, Convert.ToInt16(CLIENT_MODE), (int)VIEW_MODE, presidente, Request.RequestUri);

                results.Atto = Mapper.Map <ATTI, AttiDto>(atto);
                return(Ok(results));
            }
            catch (Exception e)
            {
                Log.Error("GetEmendamenti", e);
                return(ErrorHandler(e));
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> GetEmendamenti(BaseRequest <EmendamentiDto> model)
        {
            ///TODO: implementare i controlli anche sull'atto

            try
            {
                var atto = await _logicAtti.GetAtto(model.id);

                if (atto == null)
                {
                    return(NotFound());
                }

                object CLIENT_MODE;
                model.param.TryGetValue("CLIENT_MODE", out CLIENT_MODE); // per trattazione aula
                var session = await GetSession();

                var persona = await _logicPersone.GetPersona(session);

                var results =
                    await _logicEm.GetEmendamenti(model, persona, Convert.ToInt16(CLIENT_MODE));

                return(Ok(new EmendamentiViewModel
                {
                    Data = new BaseResponse <EmendamentiDto>(
                        model.page,
                        model.size,
                        results,
                        model.filtro,
                        await _logicEm.CountEM(model, persona, Convert.ToInt16(CLIENT_MODE)),
                        Request.RequestUri),
                    Atto = Mapper.Map <ATTI, AttiDto>(atto),
                    Mode = (ClientModeEnum)Convert.ToInt16(CLIENT_MODE),
                    CurrentUser = persona
                }));
            }
            catch (Exception e)
            {
                Log.Error("GetEmendamenti", e);
                return(ErrorHandler(e));
            }
        }
        public async Task <IHttpActionResult> GetEmendamenti(EmendamentiByQueryModel model)
        {
            try
            {
                var countEM = await _logicEm.CountEM(model.Query);

                return(Ok(
                           new BaseResponse <EmendamentiDto>(
                               model.page,
                               100,
                               await _logicEm.GetEmendamenti(model),
                               null,
                               countEM)
                           ));
            }
            catch (Exception e)
            {
                Log.Error("JOB - GetEmendamenti", e);
                return(ErrorHandler(e));
            }
        }
Exemplo n.º 4
0
        public async Task <HttpResponseMessage> EsportaGrigliaExcel(Guid id, OrdinamentoEnum ordine, PersonaDto persona)
        {
            try
            {
                var _pathTemp = AppSettingsConfiguration.CartellaTemp;
                if (!Directory.Exists(_pathTemp))
                {
                    Directory.CreateDirectory(_pathTemp);
                }

                var nameFileXLS      = $"PEM_{DateTime.Now:ddMMyyyy_hhmmss}.xlsx";
                var FilePathComplete = Path.Combine(_pathTemp, nameFileXLS);

                var atto = await _unitOfWork.Atti.Get(id);

                using (var fs = new FileStream(FilePathComplete, FileMode.Create, FileAccess.Write))
                {
                    IWorkbook workbook   = new XSSFWorkbook();
                    var       excelSheet = workbook.CreateSheet($"{atto.TIPI_ATTO.Tipo_Atto} {atto.NAtto}");

                    var row = excelSheet.CreateRow(0);

                    if (atto.OrdineVotazione.HasValue)
                    {
                        if (atto.OrdineVotazione.Value)
                        {
                            row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("OrdineVotazione");
                        }
                    }

                    if (persona.CurrentRole == RuoliIntEnum.Amministratore_PEM)
                    {
                        row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("IDEM");
                        row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Atto");
                    }

                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Numero EM");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Data Deposito");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Stato");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Tipo");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Parte");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Articolo");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Comma");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Lettera");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Titolo");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Capo");

                    if (atto.VIS_Mis_Prog)
                    {
                        row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Missione");
                        row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Programma");
                        row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("TitoloB");
                    }

                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Proponente");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Area Politica");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Firmatari");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("Firmatari dopo deposito");
                    row.CreateCell(GetColumn(row.LastCellNum)).SetCellValue("LinkEM");

                    var emList = await _logicEm.GetEmendamenti(new BaseRequest <EmendamentiDto>
                    {
                        id     = id,
                        ordine = ordine,
                        page   = 1,
                        size   = 50
                    }, persona, (int)ClientModeEnum.GRUPPI);

                    foreach (var em in emList)
                    {
                        var rowEm = excelSheet.CreateRow(excelSheet.LastRowNum + 1);

                        if (atto.OrdineVotazione.HasValue)
                        {
                            if (atto.OrdineVotazione.Value)
                            {
                                rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(em.OrdineVotazione);
                            }
                        }

                        if (persona.CurrentRole == RuoliIntEnum.Amministratore_PEM)
                        {
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(em.UIDEM.ToString());
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                            .SetCellValue(
                                $"{atto.TIPI_ATTO.Tipo_Atto}-{atto.NAtto}-{atto.SEDUTE.legislature.num_legislatura}");
                        }

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(
                            GetNomeEM(em,
                                      em.Rif_UIDEM.HasValue
                                    ? Mapper.Map <EM, EmendamentiDto>(await _logicEm.GetEM(em.Rif_UIDEM.Value))
                                    : null));
                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(
                            !string.IsNullOrEmpty(em.DataDeposito)
                                ? Decrypt(em.DataDeposito)
                                : "--");

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue(persona.CurrentRole == RuoliIntEnum.Amministratore_PEM
                                ? $"{em.STATI_EM.IDStato}-{em.STATI_EM.Stato}"
                                : em.STATI_EM.Stato);

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue(persona.CurrentRole == RuoliIntEnum.Amministratore_PEM
                                ? $"{em.TIPI_EM.IDTipo_EM}-{em.TIPI_EM.Tipo_EM}"
                                : em.TIPI_EM.Tipo_EM);

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue(persona.CurrentRole == RuoliIntEnum.Amministratore_PEM
                                ? $"{em.PARTI_TESTO.IDParte}-{em.PARTI_TESTO.Parte}"
                                : em.PARTI_TESTO.Parte);

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue(em.UIDArticolo.HasValue ? em.ARTICOLI.Articolo : "");
                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue(em.UIDComma.HasValue ? em.COMMI.Comma : "");
                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue(em.UIDLettera.HasValue ? em.LETTERE.Lettera : em.NLettera);

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(em.NTitolo);
                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(em.NCapo);

                        if (atto.VIS_Mis_Prog)
                        {
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(em.NMissione.ToString());
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(em.NProgramma.ToString());
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue(em.NTitoloB.ToString());
                        }

                        var proponente =
                            Mapper.Map <View_UTENTI, PersonaDto>(await _unitOfWork.Persone.Get(em.UIDPersonaProponente.Value));
                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue(persona.CurrentRole == RuoliIntEnum.Amministratore_PEM
                                ? $"{proponente.id_persona}-{proponente.DisplayName}"
                                : proponente.DisplayName);

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue("");

                        if (!string.IsNullOrEmpty(em.DataDeposito))
                        {
                            var firme = await _logicFirme.GetFirme(Mapper.Map <EmendamentiDto, EM>(em),
                                                                   FirmeTipoEnum.TUTTE);

                            var firmeDto = firme.Select(Mapper.Map <FIRME, FirmeDto>)
                                           .ToList();

                            var firmeAnte = firmeDto.Where(f =>
                                                           f.Timestamp < Convert.ToDateTime(Decrypt(em.DataDeposito)));
                            var firmePost = firmeDto.Where(f =>
                                                           f.Timestamp > Convert.ToDateTime(Decrypt(em.DataDeposito)));

                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                            .SetCellValue(GetFirmatariEM_OPENDATA(firmeAnte,
                                                                  persona.CurrentRole));
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                            .SetCellValue(GetFirmatariEM_OPENDATA(firmePost,
                                                                  persona.CurrentRole));
                        }
                        else
                        {
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue("--");
                            rowEm.CreateCell(GetColumn(rowEm.LastCellNum)).SetCellValue("--");
                        }

                        rowEm.CreateCell(GetColumn(rowEm.LastCellNum))
                        .SetCellValue($"{AppSettingsConfiguration.urlPEM}/{em.UID_QRCode}");
                    }

                    workbook.Write(fs);
                }

                var stream = new MemoryStream();
                using (var fileStream = new FileStream(FilePathComplete, FileMode.Open))
                {
                    await fileStream.CopyToAsync(stream);
                }

                stream.Position = 0;
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(stream.GetBuffer())
                };
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = nameFileXLS
                };
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                return(result);
            }
            catch (Exception e)
            {
                Log.Error("Logic - EsportaGrigliaXLS", e);
                throw e;
            }
        }