public async Task <IActionResult> AddOrEdit(int id, [Bind("TransactionId,AccountNumber,BeneficiaryName,BankName,SWIFTCode,Amount,Date")] TransactionModel transactionModel)
 {
     if (ModelState.IsValid)
     {
         //Insert
         if (id == 0)
         {
             transactionModel.Date = DateTime.Now;
             _context.Add(transactionModel);
             await _context.SaveChangesAsync();
         }
         //Update
         else
         {
             try
             {
                 _context.Update(transactionModel);
                 await _context.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!TransactionModelExists(transactionModel.TransactionId))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.Transactions.ToList()) }));
     }
     return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", transactionModel) }));
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("TransactionID,AccountController,BeneficaryName,BankName,Code,Amount")] TransactionModel transactionModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transactionModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(transactionModel));
        }
        public async Task <IActionResult> UploadFile(List <IFormFile> files)
        {
            TransactionModel transactionModel = new TransactionModel();

            foreach (var formFile in files)
            {
                var lines = System.IO.File.ReadAllLines(System.IO.Path.Combine(_env.WebRootPath, @"..\OFX\" + formFile.FileName));
                foreach (var line in lines)
                {
                    if (line.Equals("<STMTTRN>"))
                    {
                        transactionModel = new TransactionModel();
                    }
                    else if (line.Contains("<TRNTYPE>"))
                    {
                        transactionModel.Type = line.Replace("<TRNTYPE>", "");
                    }
                    else if (line.Contains("<DTPOSTED>"))
                    {
                        string date = line.Replace("<DTPOSTED>", "");
                        date = date.Substring(0, 8);
                        date = DateTime.ParseExact(date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

                        transactionModel.Date = DateTime.Parse(date);
                    }
                    else if (line.Contains("<TRNAMT>"))
                    {
                        transactionModel.Amount = double.Parse((double.Parse(line.Replace("<TRNAMT>", "")) / 100).ToString("f2"));
                    }
                    else if (line.Contains("<MEMO>"))
                    {
                        transactionModel.Memo = line.Replace("<MEMO>", "");
                    }
                    else if (line.Equals("</STMTTRN>"))
                    {
                        var alreadyExists = await _context.Transactions.AnyAsync(x => x.Type == transactionModel.Type &&
                                                                                 x.Date == transactionModel.Date && x.Amount == transactionModel.Amount &&
                                                                                 x.Memo == transactionModel.Memo);

                        if (alreadyExists == false)
                        {
                            _context.Add(transactionModel);
                            await _context.SaveChangesAsync();
                        }
                    }
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 4
0
 public async Task <IActionResult> AddOrEdit(int id, [Bind("EmpleadoId,TipoDocumentoId,NumeroDocumento,Nombres,Apellidos,AreaId,FechaNacimiento")] EmpleadoModel empleadoModel)
 {
     if (ModelState.IsValid)
     {
         //Insert
         if (id == 0)
         {
             empleadoModel.FechaCreacion = DateTime.Now;
             _context.Add(empleadoModel);
             await _context.SaveChangesAsync();
         }
         //Update
         else
         {
             try
             {
                 //empleadoModel.FechaNacimiento = Convert.ToDate(empleadoModel.FechaNacimiento.ToString("dd/MM/yyyy"));
                 empleadoModel.FechaCreacion = DateTime.Now;
                 _context.Update(empleadoModel);
                 await _context.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!TransactionModelExists(empleadoModel.EmpleadoId))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.Empleado.ToList()) }));
     }
     return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", empleadoModel) }));
 }