public static PORT.Company GetCompany(string connectionString, Int64 id) { using (UnitOfWork uow = new UnitOfWork()) { uow.ConnectionString = connectionString; uow.Connect(); PORT.Company company = new PORT.Company(); DAL.Datamodel.ORG_Company xdp_company = uow.Query <DAL.Datamodel.ORG_Company>().Where(c => c.EntityId.EntityId.Id == id).FirstOrDefault(); DAL.Datamodel.SYS_Address billing = uow.Query <DAL.Datamodel.ORG_CompanyAddress>().Where(a => a.CompanyId == xdp_company && a.AddressId.TypeId == DAL.Enums.SYS_Type.BillingAddress).FirstOrDefault().AddressId; company.billingAddressLine1 = billing.Line1; company.billingAddressLine2 = billing.Line2; company.billingAddressLine3 = billing.Line3; company.billingAddressLine4 = billing.Line4; company.billingAddressCode = billing.Code; company.referenceShort1 = xdp_company.SalesmanCode; company.referenceShort2 = xdp_company.RepCode; company.code = xdp_company.EntityId.EntityId.CodeSub; company.name = xdp_company.EntityId.EntityId.Name; return(company); } }
public static PORT.Document GetById(string connectionString, long id) { using (UnitOfWork uow = new UnitOfWork()) { uow.ConnectionString = connectionString; uow.Connect(); XPQuery<DAL.Datamodel.ORG_TRX_Header> docs = new XPQuery<DAL.Datamodel.ORG_TRX_Header>(uow); PORT.Document document = docs.Where(d => d.Id == id) .Select(d => new PORT.Document() { id = d.HeaderId.Id, companyId = d.CompanyId.EntityId.EntityId.Id, companyName = d.CompanyId.EntityId.EntityId.Name, datePosted = d.DatePosted, referenceShort1 = d.ReferenceShort1, referenceShort2 = d.ReferenceShort2, referenceShort3 = d.ReferenceShort3, documentheader = new PORT.DocumentHeader() { documentNumber = d.HeaderId.DocumentNumber.ToString(), total = d.HeaderId.SYS_DOC_Lines.Sum(l => l.Total), totalVat = d.HeaderId.SYS_DOC_Lines.Sum(l => l.TotalTax), documentLines = d.HeaderId.SYS_DOC_Lines.Select(l => new PORT.DocumentLines() { amount = l.Amount, description = l.Description, itemId = l.ItemId.Id, lineOrder = l.LineOrder, quantity = l.Quantity, total = l.Total, totalVat = l.TotalTax, isNew = false }).ToList() } }).FirstOrDefault(); DAL.Datamodel.SYS_Address billing = uow.Query<DAL.Datamodel.ORG_CompanyAddress>().Where(a => a.CompanyId.EntityId.EntityId.Id == document.companyId && a.AddressId.TypeId == DAL.Enums.SYS_Type.BillingAddress).FirstOrDefault().AddressId; document.billingAddressLine1 = String.IsNullOrEmpty(billing.Line1) ? " " : billing.Line1; document.billingAddressLine2 = String.IsNullOrEmpty(billing.Line2) ? " " : billing.Line2; document.billingAddressLine3 = String.IsNullOrEmpty(billing.Line3) ? " " : billing.Line3; document.billingAddressLine4 = String.IsNullOrEmpty(billing.Line4) ? " " : billing.Line4; document.billingAddressCode = String.IsNullOrEmpty(billing.Code) ? " " : billing.Code; return document; } }