protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var statementTransaction = validationContext.ObjectInstance as StatementTransaction; if (statementTransaction == null) { return(new ValidationResult("Statement Transaction is empty")); } NiboOfxParserContext niboContext = new NiboOfxParserContext(); var customId = new StatementTransaction( statementTransaction.Value, statementTransaction.Type, statementTransaction.Id, statementTransaction.PostedDate, statementTransaction.Memo, statementTransaction.PayeeId).CustomId; var customIdAlreadyExists = niboContext.StatementTransactions.FirstOrDefault(x => x.CustomId == customId); if (customIdAlreadyExists == null) { return(ValidationResult.Success); } else { return(new ValidationResult($"The statement transaction already exists")); } // return base.IsValid(value, validationContext); }
static Transaction MapToModel(StatementTransaction transactionDto) { decimal amount; if (!decimal.TryParse(transactionDto.TRNAMT, out amount)) { throw new OfxResponseException("Amount of transaction can not be parsed. " + transactionDto.TRNAMT); } DateTime datePosted; const int targetLength = 14; var truncatedValue = transactionDto.DTPOSTED.Length == targetLength ? transactionDto.DTPOSTED : transactionDto.DTPOSTED.Length > targetLength ? transactionDto.DTPOSTED.Substring(0, targetLength) : transactionDto.DTPOSTED + new string('0', targetLength - transactionDto.DTPOSTED.Length); if (!DateTime.TryParseExact(truncatedValue, Utils.DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out datePosted)) { throw new OfxResponseException("Date of transaction can not be parsed. " + transactionDto.DTPOSTED); } var description = transactionDto.Item is Payee ? (transactionDto.Item as Payee).NAME : transactionDto.Item as string; return(new Transaction( transactionDto.FITID, transactionDto.TRNTYPE.ToString(), amount, datePosted, description, transactionDto.MEMO)); }
private static Transaction MapToModel(StatementTransaction transactionDto) { var amount = decimal.Parse(transactionDto.TRNAMT); var truncatedValue = transactionDto.DTPOSTED.Length == DateTimeFormat.Length ? transactionDto.DTPOSTED : transactionDto.DTPOSTED.Length > DateTimeFormat.Length ? transactionDto.DTPOSTED.Substring(0, DateTimeFormat.Length) : transactionDto.DTPOSTED + new string('0', DateTimeFormat.Length - transactionDto.DTPOSTED.Length); var datePosted = DateTime.ParseExact(truncatedValue, DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); var description = transactionDto.Item is Payee payee ? payee.NAME : transactionDto.Item as string; return(new Transaction() { Memo = transactionDto.MEMO, Description = description, DatePosted = datePosted, Amount = amount, Type = transactionDto.TRNTYPE.ToString(), Id = transactionDto.FITID, }); }
/// <summary> /// Construct a statement transaction by parsing an OFX transaction entity /// </summary> /// <param name="ofxTransaction"></param> public Transaction(StatementTransaction ofxTransaction) { // Assign to internal state PostDate = OFXUtils.DateFromOFX(ofxTransaction.DTPOSTED); TransactionId = ofxTransaction.FITID; Amount = OFXUtils.DecimalStringToFixedInt(ofxTransaction.TRNAMT); Name = (string)ofxTransaction.Item; }
public static Transaction ToTransaction(this StatementTransaction transactionDto) => new Transaction { Memo = transactionDto.Memo, TransactionAmount = transactionDto.TransactionAmount, Type = transactionDto.TransactionType.ToUpper().Trim() == "CREDIT" ? TransactionType.Credit : TransactionType.Debit, DatePosted = transactionDto.DatePosted.ConvertOfxDateToDateTime() };
public ActionResult DeleteConfirmed(long id) { StatementTransaction statementTransaction = db.StatementTransactions.Find(id); db.StatementTransactions.Remove(statementTransaction); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Type,PostedDate,Value,CustomId,PayeeId,Memo")] StatementTransaction statementTransaction) { if (ModelState.IsValid) { db.Entry(statementTransaction).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(statementTransaction)); }
/// <summary> /// Method to fill Statement Transaction Object /// </summary> /// <param name="node">Statement transaction XML Node</param> /// <returns>Statement transaction Filled</returns> public StatementTransaction FillStatementTransactions(XmlNode node) { var statementTransaction = new StatementTransaction(); var statementTransactionList = new List <StatementTransaction>(); for (var i = 0; i < node.ChildNodes.Count; i++) { switch (node.ChildNodes[i].Name) { case "TRNTYPE": statementTransaction.Type = node.ChildNodes[i].InnerText; break; case "DTPOSTED": statementTransaction.PostedDate = ExtractDate(node.ChildNodes[i].InnerText); break; case "TRNAMT": statementTransaction.Value = Convert.ToDouble(node.ChildNodes[i].InnerText, CultureInfo.GetCultureInfo("en-US")); break; case "FITID": statementTransaction.Id = Convert.ToInt64(node.ChildNodes[i].InnerText); break; case "MEMO": statementTransaction.Memo = node.ChildNodes[i].InnerText; break; case "PAYEEID": statementTransaction.PayeeId = Convert.ToInt32(node.ChildNodes[i].InnerText); break; } } //creato object with customId var statementTransactionWithCustomId = new StatementTransaction(statementTransaction.Value, statementTransaction.Type, statementTransaction.Id, statementTransaction.PostedDate, statementTransaction.Memo, statementTransaction.PayeeId); //Vefify if customId already existis on database var statementTransactionAux = GetStatementTransactionByCustomId(statementTransactionWithCustomId.CustomId); //if customId exists, return null if (statementTransactionAux != null) { return(null); } //if customId not exists, return object filled to save return(statementTransactionWithCustomId); }
public ActionResult Create([Bind(Include = "Id,Type,PostedDate,Value,CustomId,PayeeId,Memo")] StatementTransaction statementTransaction) { if (ModelState.IsValid) { db.StatementTransactions.Add(statementTransaction); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(statementTransaction)); }
// GET: StatementTransactions/Delete/5 public ActionResult Delete(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StatementTransaction statementTransaction = db.StatementTransactions.Find(id); if (statementTransaction == null) { return(HttpNotFound()); } return(View(statementTransaction)); }
public void SaveStatementTransaction(StatementTransaction statementTransaction) { db.StatementTransactions.Add(statementTransaction); db.SaveChanges(); }