Beispiel #1
0
        public async Task <ReportResponse> GetReport(ReportRequest req, Uri url)
        {
            var result   = new ReportResponse();
            var lista_em = await _unitOfWork
                           .Emendamenti
                           .GetReport(req.id, req.type, req.page, req.size);

            var lista_em_dto = new List <EmendamentiDto>();

            foreach (var em in lista_em)
            {
                var newItem = Mapper.Map <EM, EmendamentiDto>(em);
                newItem.DisplayTitle = GetNomeEM(em,
                                                 em.Rif_UIDEM.HasValue
                        ? await _logicEm.GetEM(em.Rif_UIDEM.Value)
                        : null);
                newItem.PersonaProponente = Mapper.Map <View_UTENTI, PersonaLightDto>(
                    await _unitOfWork.Persone.Get(em.UIDPersonaProponente.Value));
                lista_em_dto.Add(newItem);
            }

            result.Data = new BaseResponse <EmendamentiDto>(
                req.page,
                req.size,
                lista_em_dto,
                null,
                await _unitOfWork.Emendamenti.CountReport(req.id),
                url);

            result.Approvati = await _unitOfWork.Emendamenti.CountReport(req.id, StatiEnum.Approvato);

            result.Non_Approvati = await _unitOfWork.Emendamenti.CountReport(req.id, StatiEnum.Non_Approvato);

            result.Inammissibili = await _unitOfWork.Emendamenti.CountReport(req.id, StatiEnum.Inammissibile);

            result.Decaduti = await _unitOfWork.Emendamenti.CountReport(req.id, StatiEnum.Decaduto);

            result.Ritirati = await _unitOfWork.Emendamenti.CountReport(req.id, StatiEnum.Ritirato);

            result.Atto = Mapper.Map <ATTI, AttiDto>(await _unitOfWork.Atti.Get(req.id));
            return(result);
        }
Beispiel #2
0
        public async Task <IHttpActionResult> GetEmendamento(Guid id)
        {
            ///TODO: implementare i controlli anche sull'atto
            try
            {
                var em = await _logicEm.GetEM(id);

                if (em == null)
                {
                    return(NotFound());
                }
                var session = await GetSession();

                var persona = await _logicPersone.GetPersona(session);

                return(Ok(await _logicEm.GetEM_DTO(em, persona)));
            }
            catch (Exception e)
            {
                Log.Error("GetEmendamento", e);
                return(ErrorHandler(e));
            }
        }
Beispiel #3
0
        public async Task <IHttpActionResult> GetEmendamento(Guid id)
        {
            ///TODO: implementare i controlli anche sull'atto
            try
            {
                var em = await _logicEm.GetEM(id);

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

                var session = await GetSession();

                var persona = await _logicPersone.GetPersona(session);

                var atto = await _unitOfWork.Atti.Get(em.UIDAtto);

                var personeInDb = await _unitOfWork.Persone.GetAll();

                var personeInDbLight = personeInDb.Select(Mapper.Map <View_UTENTI, PersonaLightDto>).ToList();

                var result = await _logicEm.GetEM_DTO(em, atto, persona, personeInDbLight);

                return(Ok(result));
            }
            catch (Exception e)
            {
                Log.Error("GetEmendamento", e);
                return(ErrorHandler(e));
            }
        }
Beispiel #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;
            }
        }