public List <ItemVarient> GetItemVarients() { List <ItemVarient> itemVarientList1 = new List <ItemVarient>(); cls_user_responses clsUserResponses = new cls_user_responses(); List <ItemVarient> itemVarientList2; try { using (CustomERPEntities customErpEntities = new CustomERPEntities()) { List <ItemVarient> list = customErpEntities.ItemVarient.Select <ItemVarient, ItemVarient>((Expression <Func <ItemVarient, ItemVarient> >)(itm => itm)).ToList <ItemVarient>(); if (list.Count > 0) { foreach (ItemVarient itemVarient in list) { ItemVarient itemName = itemVarient; Item obj = customErpEntities.Item.Where <Item>((Expression <Func <Item, bool> >)(itm => itm.IDNUMBER == itemName.ItemID)).FirstOrDefault <Item>(); if (obj != null) { itemName.ItemName = obj.ItemName; itemName.ProductImage = obj.ItemImage; itemName.ItemVarientName = obj.ItemName + " - " + itemName.Color + " - " + itemName.Size; } } itemVarientList1 = list; } itemVarientList2 = itemVarientList1; } } catch (Exception ex) { itemVarientList2 = itemVarientList1; } return(itemVarientList2); }
public List <Sales> GetSales() { List <Sales> salesList1 = new List <Sales>(); cls_user_responses clsUserResponses = new cls_user_responses(); List <Sales> salesList2; try { using (CustomERPEntities customErpEntities = new CustomERPEntities()) { List <Sales> list1 = customErpEntities.Sales.Select <Sales, Sales>((Expression <Func <Sales, Sales> >)(itm => itm)).ToList <Sales>(); foreach (Sales sales in list1) { Sales customerName = sales; List <SalesDetails> list2 = customErpEntities.SalesDetails.Where <SalesDetails>((Expression <Func <SalesDetails, bool> >)(sl => sl.SalesID == customerName.IDNUMBER)).ToList <SalesDetails>(); if (list2.Count > 0) { foreach (SalesDetails salesDetails in list2) { SalesDetails itemName = salesDetails; 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.SalesDetails = 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; } } salesList1 = list1; salesList2 = salesList1; } } catch (Exception ex) { salesList2 = salesList1; } return(salesList2); }
public List <Purchase> GetPurchases() { List <Purchase> purchaseList1 = new List <Purchase>(); cls_user_responses clsUserResponses = new cls_user_responses(); List <Purchase> purchaseList2; try { using (CustomERPEntities customErpEntities = new CustomERPEntities()) { List <Purchase> list1 = customErpEntities.Purchase.Select <Purchase, Purchase>((Expression <Func <Purchase, Purchase> >)(itm => itm)).ToList <Purchase>(); foreach (Purchase purchase in list1) { Purchase supplierName = purchase; List <PurchaseDetails> list2 = customErpEntities.PurchaseDetails.Where <PurchaseDetails>((Expression <Func <PurchaseDetails, bool> >)(pd => pd.PurchaseID == supplierName.IDNUMBER)).ToList <PurchaseDetails>(); if (list2.Count > 0) { foreach (PurchaseDetails purchaseDetails in list2) { PurchaseDetails itemName = purchaseDetails; 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; } } } supplierName.PurchaseDetails = list2; } Supplier supplier = customErpEntities.Supplier.Where <Supplier>((Expression <Func <Supplier, bool> >)(sp => sp.IDNUMBER == supplierName.SupplierID)).FirstOrDefault <Supplier>(); if (supplier != null) { supplierName.SupplierName = supplier.SupplierName; } } purchaseList1 = list1; purchaseList2 = purchaseList1; } } catch (Exception ex) { purchaseList2 = purchaseList1; } return(purchaseList2); }
public static bool saveStocks(Item product_requests, int ResponseGenID) { Stockdbf entity1 = new Stockdbf(); StockDetails entity2 = new StockDetails(); ItemVarient itemVarient1 = new ItemVarient(); bool flag = false; try { using (CustomERPEntities customErpEntities = new CustomERPEntities()) { if (product_requests.ItemVarients != null) { if (product_requests.ItemVarients.Count > 0) { foreach (ItemVarient itemVarient2 in product_requests.ItemVarients) { ItemVarient responseGenID = itemVarient2; responseGenID.ItemID = ResponseGenID; responseGenID.CreatedBy = new int?(1); responseGenID.CreatedDate = new DateTime?(DateTime.Now); responseGenID.UpdateBy = new int?(1); responseGenID.UpdatedDate = new DateTime?(DateTime.Now); ItemVarient warehouseID = customErpEntities.ItemVarient.Where <ItemVarient>((Expression <Func <ItemVarient, bool> >)(iv => iv.IDNUMBER == responseGenID.IDNUMBER && iv.ItemID == ResponseGenID)).SingleOrDefault <ItemVarient>(); if (warehouseID == null) { warehouseID = responseGenID; entity1.StockQty = responseGenID.Inventory; warehouseID.WarehouseID = responseGenID.WarehouseID; customErpEntities.ItemVarient.Add(warehouseID); customErpEntities.SaveChanges(); if (customErpEntities.Stockdbf.Where <Stockdbf>((Expression <Func <Stockdbf, bool> >)(st => st.ItemID == responseGenID.ItemID && st.ItemVarientID == responseGenID.IDNUMBER)).FirstOrDefault <Stockdbf>() != null) { entity1.StockQty = responseGenID.Inventory; customErpEntities.SaveChanges(); entity2.StockQty = responseGenID.Inventory; entity2.StockRate = warehouseID.Cost; entity2.TranNo = product_requests.ItemName; customErpEntities.SaveChanges(); } else { entity1.CompanyID = new int?(1); entity1.ItemID = responseGenID.ItemID; entity1.ItemVarientID = responseGenID.IDNUMBER; entity1.StockQty = warehouseID.Inventory; customErpEntities.Stockdbf.Add(entity1); customErpEntities.SaveChanges(); entity2.CompanyID = new int?(1); entity2.StockID = entity1.IDNUMBER; entity2.ItemID = responseGenID.ItemID; entity2.ItemVarientID = responseGenID.IDNUMBER; entity2.StockQty = responseGenID.Inventory; entity2.StockRate = responseGenID.Cost; entity2.TranCode = "C"; entity2.TranBook = "OP"; entity2.TranNo = product_requests.ItemName; entity2.CreatedBy = new int?(1); entity2.CreatedDate = new DateTime?(DateTime.Now); customErpEntities.StockDetails.Add(entity2); customErpEntities.SaveChanges(); } flag = true; } else { warehouseID.Color = responseGenID.Color; warehouseID.Size = responseGenID.Size; warehouseID.Inventory = responseGenID.Inventory; warehouseID.WarehouseID = responseGenID.WarehouseID; warehouseID.Cost = responseGenID.Cost; warehouseID.SKU = responseGenID.SKU; warehouseID.UPC = responseGenID.UPC; customErpEntities.SaveChanges(); if (customErpEntities.Stockdbf.FirstOrDefault <Stockdbf>((Expression <Func <Stockdbf, bool> >)(x => x.ItemID == warehouseID.ItemID && x.ItemVarientID == warehouseID.IDNUMBER)) != null) { entity1.StockQty = warehouseID.Inventory; customErpEntities.SaveChanges(); entity2.StockQty = responseGenID.Inventory; entity2.StockRate = warehouseID.Cost; entity2.TranNo = product_requests.ItemName; customErpEntities.SaveChanges(); } else { entity1.CompanyID = new int?(1); entity1.ItemID = warehouseID.ItemID; entity1.ItemVarientID = warehouseID.IDNUMBER; entity1.StockQty = warehouseID.Inventory; customErpEntities.Stockdbf.Add(entity1); customErpEntities.SaveChanges(); entity2.CompanyID = new int?(1); entity2.StockID = entity1.IDNUMBER; entity2.ItemID = warehouseID.ItemID; entity2.ItemVarientID = warehouseID.IDNUMBER; entity2.StockQty = warehouseID.Inventory; entity2.StockRate = warehouseID.Cost; entity2.TranCode = "C"; entity2.TranBook = "OP"; entity2.TranNo = product_requests.ItemName; entity2.CreatedBy = new int?(1); entity2.CreatedDate = new DateTime?(DateTime.Now); customErpEntities.StockDetails.Add(entity2); customErpEntities.SaveChanges(); } flag = true; } } } flag = true; } flag = true; } } catch (Exception ex) { flag = false; } return(flag); }