public PaymentHistoryUpdate GetPaymentHistoryUpdate() { var result = new PaymentHistoryUpdate(); result.Amount = PaymentHistoryView.Amount; result.PaymentDate = PaymentHistoryView.PaymentDate; result.PaymentHistoryId = PaymentHistoryView.PaymentHistoryId; result.Reference = PaymentHistoryView.Reference; return(result); }
public async Task <data.PaymentHistory> Update(data.InvoiceContext db, PaymentHistoryUpdate update) { try { var paymentHistoryToUpdate = await db.PaymentHistorys.FirstOrDefaultAsync(w => w.PaymentHistoryId == update.PaymentHistoryId); paymentHistoryToUpdate.Amount = update.Amount; paymentHistoryToUpdate.PaymentDate = update.PaymentDate; paymentHistoryToUpdate.PaymentHistoryId = update.PaymentHistoryId; paymentHistoryToUpdate.Reference = update.Reference; return(paymentHistoryToUpdate); } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
// Update Transaction Code public async Task <PaymentHistoryView> Update(PaymentHistoryUpdate update) { try { using (var db = new data.InvoiceContext()) { var result = await Update(db, update); await db.SaveChangesAsync(); return((PaymentHistoryView)result); } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(null); } }
public async Task <PaymentHistoryView> PaymentHistoryUpdate(PaymentHistoryUpdate update) { try { string json = ""; var client = new HttpClient(); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(PaymentHistoryUpdate), new DataContractJsonSerializerSettings() { DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ss") }); serializer.WriteObject(ms, update); ms.Position = 0; StreamReader sr = new StreamReader(ms); json = sr.ReadToEnd(); } var stream = await client.PutAsync($"http://localhost:44443/api/paymentHistory/{update.PaymentHistoryId}", new StringContent(json, Encoding.UTF8, "application/json")); using (var ms = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(PaymentHistoryView)); 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); } }