Ejemplo n.º 1
0
        public void Post([FromBody] BankStatement BankStatement)
        {
            //BankStatement BankStatement = new BankStatement()
            //{
            //    BankStatementBrand = BankStatementDto.BankStatementBrand,
            //    BankStatementholderName = BankStatementDto.BankStatementholderName,
            //    CVS = BankStatementDto.CVS,
            //    BankStatementType = BankStatementDto.BankStatementType,
            //    Id = BankStatementDto.BankStatementId,
            //    ExpirationDate = BankStatementDto.ExpirationDate,
            //    Number = BankStatementDto.Number,
            //    CreatedDate = BankStatementDto.CreatedDate
            //};

            try
            {
                //   _BankStatementBusiness.SaveAndUpdate(BankStatement);
                _BankStatementBusiness.Save();
            }
            catch (Exception ex)
            {
                //  throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }
        }
        public IActionResult Index()
        {
            try
            {
                var file = Request.Form.Files[0];


                var folderName = Path.Combine("Resources", "File");
                var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
                if (file.Length > 0)
                {
                    //var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    //var fullPath = Path.Combine(pathToSave, fileName);
                    //var dbPath = Path.Combine(folderName, fileName);
                    //using (var stream = new FileStream(fullPath, FileMode.Create))
                    //{


                    var stream = file.OpenReadStream();
                    //     file.CopyTo(stream);
                    OFXDataBusiness business  = new OFXDataBusiness();
                    OFXReader       OFXReader = new OFXReader(stream);
                    var             data      = business.LoadData(OFXReader);

                    _BankStatementBusiness.Add(new Domain.Enitties.BankStatement()
                    {
                        Active          = true,
                        CreatedDate     = DateTime.Now,
                        Accttype        = data.ACCTTYPE,
                        Balamt          = data.BALAMT,
                        Bankid          = data.BANKID,
                        Curdef          = data.CURDEF,
                        Dtasof          = data.DTASOF.OFXFormatteddDate(),
                        Dataserver      = data.DTSERVER.OFXFormatteddDate(),
                        Language        = data.LANGUAGE,
                        Ofx             = data.OFX,
                        Severity        = data.SEVERITY,
                        Acctid          = data.ACCTID,
                        Trnuid          = data.TRNUID,
                        Code            = data.CODE,
                        Accountlaunches = data.statements.Select(x => new Accountlaunche()
                        {
                            Active      = true,
                            CreatedDate = DateTime.Now,
                            Dtposted    = x.DTPOSTED.OFXFormatteddDate(),
                            Memo        = x.MEMO,
                            Trnamt      = x.TRNAMT,
                            Trntype     = x.TRNTYPE
                        }).ToList()
                    });
                    _BankStatementBusiness.Save();
                }

                //var folderName = Path.Combine("Resources", "Images");
                //var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
                //if (file.Length > 0)
                //{
                //    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                //    var fullPath = Path.Combine(pathToSave, fileName);
                //    var dbPath = Path.Combine(folderName, fileName);
                //    using (var stream = new FileStream(fullPath, FileMode.Create))
                //    {
                //        file.CopyTo(stream);
                //    }
                //    return Ok(new { dbPath });
                //}
                //else
                //{
                //    return BadRequest();
                //}
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Internal server error: {ex}"));
            }
            return(Ok());
        }