public List <SalesContract> GetSales() { List <SalesContract> salesContractList1 = new List <SalesContract>(); cls_user_responses clsUserResponses = new cls_user_responses(); List <SalesContract> salesContractList2; try { using (CustomERPEntities customErpEntities = new CustomERPEntities()) { List <SalesContract> list1 = customErpEntities.SalesContract.Select <SalesContract, SalesContract>((Expression <Func <SalesContract, SalesContract> >)(itm => itm)).ToList <SalesContract>(); foreach (SalesContract salesContract in list1) { SalesContract customerName = salesContract; List <SalesContractDetails> list2 = customErpEntities.SalesContractDetails.Where <SalesContractDetails>((Expression <Func <SalesContractDetails, bool> >)(sl => sl.SalesID == customerName.IDNUMBER)).ToList <SalesContractDetails>(); if (list2.Count > 0) { foreach (SalesContractDetails salesContractDetails in list2) { SalesContractDetails itemName = salesContractDetails; Item obj = customErpEntities.Item.Where <Item>((Expression <Func <Item, bool> >)(it => it.IDNUMBER == itemName.ItemID)).FirstOrDefault <Item>(); if (obj != null) { itemName.ItemName = obj.ItemName; itemName.ProductImage = obj.ItemImage; ItemVarient itemVarient = customErpEntities.ItemVarient.Where <ItemVarient>((Expression <Func <ItemVarient, bool> >)(itv => itv.IDNUMBER == itemName.ItemVarientID)).FirstOrDefault <ItemVarient>(); if (itemVarient != null) { itemName.Color = itemVarient.Color; itemName.SKU = itemVarient.SKU; itemName.UPC = itemVarient.UPC; } } } customerName.SalescontractDetails = list2; } Customer customer = customErpEntities.Customer.Where <Customer>((Expression <Func <Customer, bool> >)(cp => cp.IDNUMBER == customerName.CustomerID)).FirstOrDefault <Customer>(); if (customer != null) { customerName.CustomerName = customer.CustomerName; } } salesContractList1 = list1; salesContractList2 = salesContractList1; } } catch (Exception ex) { salesContractList2 = salesContractList1; } return(salesContractList2); }
public static bool saveSalesContractDetail( SalesContract salescontract_requests, int ResponseGenID) { Stockdbf stockdbf = new Stockdbf(); StockDetails stockDetails = new StockDetails(); bool flag = false; try { using (CustomERPEntities customErpEntities = new CustomERPEntities()) { if (salescontract_requests.SalescontractDetails != null) { if (salescontract_requests.SalescontractDetails.Count > 0) { foreach (SalesContractDetails salescontractDetail1 in salescontract_requests.SalescontractDetails) { SalesContractDetails salescontractDetail = salescontractDetail1; salescontractDetail.SalesID = ResponseGenID; SalesContractDetails salesContractDetails = customErpEntities.SalesContractDetails.Where <SalesContractDetails>((Expression <Func <SalesContractDetails, bool> >)(iv => iv.IDNUMBER == salescontractDetail.IDNUMBER && iv.SalesID == ResponseGenID)).SingleOrDefault <SalesContractDetails>(); if (salesContractDetails == null) { customErpEntities.SalesContractDetails.Add(salescontractDetail); customErpEntities.SaveChanges(); } else { salesContractDetails.Price = salescontractDetail.Price; salesContractDetails.Qty = salescontractDetail.Qty; salesContractDetails.TotalAmount = salescontractDetail.TotalAmount; salesContractDetails.CompanyID = salescontractDetail.CompanyID; salesContractDetails.UnitID = salescontractDetail.UnitID; customErpEntities.SaveChanges(); } } } flag = true; } flag = true; } } catch (Exception ex) { flag = false; } return(flag); }