public PaymentHistoryAdd GetPaymentHistoryAdd() { var result = new PaymentHistoryAdd(); result.Amount = PaymentHistoryView.Amount; result.PaymentDate = PaymentHistoryView.PaymentDate; result.PaymentHistoryId = PaymentHistoryView.PaymentHistoryId; result.Reference = PaymentHistoryView.Reference; result.InvoiceInvoiceId = PaymentHistoryView.InvoiceInvoiceId; return(result); }
// Add Transaction Code public async Task <PaymentHistoryView> Add(PaymentHistoryAdd add) { try { using (var db = new data.InvoiceContext()) { var result = await Add(db, add); await db.SaveChangesAsync(); return((PaymentHistoryView)result); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
public async Task <PaymentHistoryView> PaymentHistoryAdd(PaymentHistoryAdd add) { try { string json = ""; var client = new HttpClient(); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(PaymentHistoryAdd)); serializer.WriteObject(ms, add); ms.Position = 0; StreamReader sr = new StreamReader(ms); json = sr.ReadToEnd(); } var stream = await client.PostAsync("http://localhost:44443/api/paymentHistory", new StringContent(json, Encoding.UTF8, "application/json")); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(PaymentHistoryView), new DataContractJsonSerializerSettings() { DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss") }); await stream.Content.CopyToAsync(ms); ms.Position = 0; var view = serializer.ReadObject(ms) as PaymentHistoryView; return(view); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
public async Task <data.PaymentHistory> Add(data.InvoiceContext db, PaymentHistoryAdd add) { try { var newPaymentHistory = new data.PaymentHistory(); newPaymentHistory.Amount = add.Amount; newPaymentHistory.PaymentDate = add.PaymentDate; newPaymentHistory.Reference = add.Reference; var invoiceLookup = await db.Invoices.FirstOrDefaultAsync(w => w.InvoiceId == add.InvoiceInvoiceId); if (invoiceLookup != null) { newPaymentHistory.Invoice = invoiceLookup; } db.PaymentHistorys.Add(newPaymentHistory); return(newPaymentHistory); } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }