/// <summary> /// Flattens the given invoice into a "Basic Invoice" Reposne using the ginven account number and expense for the account /// </summary> public static InvoiceListing MapFromObject(Invoice invoice) { if (invoice == null) { return(null); } //Calculate Expense of invoice decimal expense = 0; foreach (var cost in invoice.AccountTotals) { expense += cost.Expense; } var listing = new InvoiceListing() { InvoiceId = invoice.InvoiceId, InvoiceNumber = invoice.InvoiceNumber, InvoiceDate = invoice.InvoiceDate, DatePaid = invoice.DatePaid, InvoiceType = InvoiceTypeListing.MapFromObject(invoice.InvoiceType), Expense = expense, Description = invoice.Description, Vendor = VendorListing.MapFromObject(invoice.Vendor) }; return(listing); }
/// <summary> /// /// </summary> /// <param name="invoice"></param> /// <returns></returns> public static InvoiceDetails MapFromObject(Invoice invoice) { var details = new InvoiceDetails() { InvoiceId = invoice.InvoiceId, InvoiceDate = invoice.InvoiceDate, DatePaid = invoice.DatePaid, InvoiceNumber = invoice.InvoiceNumber, InvoiceType = InvoiceTypeListing.MapFromObject(invoice.InvoiceType), Description = invoice.Description, Vendor = VendorListing.MapFromObject(invoice.Vendor) }; details.Tickets = new List <TicketBasic>(); foreach (var ticket in invoice.Tickets) { details.Tickets.Add(TicketBasic.MapFromObject(ticket)); } decimal totalExpense = 0; details.Expenses = new List <InvoiceExpense>(); foreach (var accountTotal in invoice.AccountTotals) { totalExpense += accountTotal.Expense; var cityExpenses = new List <CityExpenseBasic>(); foreach (var expense in accountTotal.CityExpenses) { cityExpenses.Add(CityExpenseBasic.MapFromObject(expense)); } details.Expenses.Add(new InvoiceExpense() { InvoiceAccountId = accountTotal.InvoiceAccountId, Expense = accountTotal.Expense, Account = AccountListing.MapFromObject(accountTotal.Account), CityExpense = cityExpenses }); } details.TotalExpense = totalExpense; return(details); }
/// <summary> /// Flattens the given invoice into a "Basic Invoice" Reposne using the ginven account number and expense for the account /// </summary> public static InvoiceBasic MapFromObject(Invoice invoice, string accountNumber, decimal expense) { var basicInvoice = new InvoiceBasic() { InvoiceId = invoice.InvoiceId, InvoiceNumber = invoice.InvoiceNumber, InvoiceDate = invoice.InvoiceDate, DatePaid = invoice.DatePaid, InvoiceType = InvoiceTypeListing.MapFromObject(invoice.InvoiceType), AccountNumber = accountNumber, Expense = expense, Description = invoice.Description, }; basicInvoice.Vendor = new VendorListing() { VendorId = invoice.Vendor.VendorId, Name = invoice.Vendor.Name }; return(basicInvoice); }