Пример #1
0
        public ActionResult insertDTObyXML([FromBody] documentDTO newDocument)
        {
            _iDocumentValidatorService.setDocument(newDocument);
            ValDocuments valDoc = new ValDocuments(_iDocumentValidatorService);

            var errores = valDoc.verificador();

            if (errores.Count() == 0)
            {
                newDocument = _iDocumentValidatorService.getMaskedDocument();
                _iserviceDocument.InsertNewDocument(newDocument, "", "By Email");
                return(Ok(newDocument));
            }
            else
            {
                _iserviceDocument.InsertErrorDocument(newDocument, errores);
                return(BadRequest(new { errors = errores }));
            }
        }
Пример #2
0
        public ActionResult insertDocument([FromBody] documentDTO newDocument)
        {
            var identity = (ClaimsPrincipal)Thread.CurrentPrincipal;

            /*var sid = identity.Claims.Where(c => c.Type == ClaimTypes.Sid)
             *     .Select(c => c.Value).SingleOrDefault();*/

            var sid = User.Claims.Where(c => c.Type == ClaimTypes.Sid)
                      .Select(c => c.Value).SingleOrDefault();

            newDocument.ruc_empresa_proveedor = User.Identity.Name;
            _iDocumentValidatorService.setDocument(newDocument);
            ValDocuments valDoc  = new ValDocuments(_iDocumentValidatorService);
            var          errores = valDoc.verificador();

            if (errores.Count() > 0)
            {
                return(BadRequest(new { errors = errores }));
                //return new HttpStatusCodeResult(400,);
            }
            else
            {
                newDocument = _iDocumentValidatorService.getMaskedDocument();
                var doc = _iserviceDocument.InsertNewDocument(newDocument, User.Identity.Name, sid);

                /*
                 * var errores = valDocumentsx.verificador();
                 * if (errores.Count()==0)
                 * {
                 *  _iserviceDocument.InsertNewDocument(newDocument,User.Identity.Name);
                 *  return Ok(newDocument);
                 * }
                 * return BadRequest(new { errors = errores });
                 */

                return(Ok(doc));
            }
            //pasamos los servicios
        }
Пример #3
0
        private void WriteComentariesExcel(Dictionary <int, documentDTO> dict, string url)
        {
            XSSFWorkbook xssfwb;

            using (FileStream file = new FileStream(url, FileMode.Open, FileAccess.ReadWrite))
            {
                xssfwb = new XSSFWorkbook(file);
                file.Close();
            }

            ISheet     sheet = xssfwb.GetSheetAt(0);
            IRow       row   = sheet.GetRow(0);
            ICellStyle OkStyle;
            ICellStyle ErrorStyle;
            ICellStyle DangerStyle;

            ErrorStyle = xssfwb.CreateCellStyle();
            ErrorStyle.FillForegroundColor = IndexedColors.Gold.Index;
            ErrorStyle.FillPattern         = FillPattern.SolidForeground;

            OkStyle = xssfwb.CreateCellStyle();
            OkStyle.FillForegroundColor = IndexedColors.SeaGreen.Index;
            OkStyle.FillPattern         = FillPattern.SolidForeground;

            DangerStyle = xssfwb.CreateCellStyle();
            DangerStyle.FillForegroundColor = IndexedColors.Red.Index;
            DangerStyle.FillPattern         = FillPattern.SolidForeground;

            documentDTO doc;

            foreach (KeyValuePair <int, documentDTO> kv in dict)
            {
                row = sheet.GetRow(kv.Key);
                try
                {
                    doc = kv.Value;

                    //validator
                    _iDocumentValidatorService.setDocument(doc);
                    ValDocuments valDoc  = new ValDocuments(_iDocumentValidatorService);
                    var          errores = valDoc.verificador();

                    if (errores.Count() > 0)
                    {
                        //banderita :V
                        ICell cellIndex = row.GetCell(0) ?? row.CreateCell(0);
                        cellIndex.CellStyle = ErrorStyle;

                        foreach (KeyValuePair <string, List <string> > errorsByCells in errores)
                        {
                            int pos_cells = getExcelPostByString(errorsByCells.Key);

                            if (pos_cells >= 0)
                            {
                                var   result = String.Join(". ", errorsByCells.Value.ToArray());
                                ICell cell   = row.GetCell(pos_cells) ?? row.CreateCell(pos_cells);

                                ICellStyle tempStyle   = ErrorStyle;
                                IComment   tempComment = GetComment(sheet, result);
                                cell.CellComment = tempComment;
                                cell.CellStyle   = tempStyle;
                                error           += 1;
                            }
                        }
                    }
                    else
                    {
                        doc = _iDocumentValidatorService.getMaskedDocument();


                        //var docOK = InsertDocument(doc);
                        var docOK = ObtenerMapperDocument(doc);

                        ICell cell = row.GetCell(0) ?? row.CreateCell(0);
                        cell.CellStyle = OkStyle;
                        DocumentsOK.Add(docOK);
                        ok += 1;
                    }
                }
                catch (Exception error)
                {
                    ICell cell = row.GetCell(0) ?? row.CreateCell(0);
                    cell.CellStyle = DangerStyle;
                    danger        += 1;
                }
            }

            using (FileStream file = new FileStream(url, FileMode.Create, FileAccess.Write))
            {
                xssfwb.Write(file);
                file.Close();
            }
        }