public static string CheckAndInsertData(string Name, int AssetType, FEA_BusinessLogic.FEA_ITSEntities dbEntity, out string sError) { sError = ""; try { var item = dbEntity.ITSAssetFTies.Where(i => ((i.Name.Trim().ToLower() == Name.Trim().ToLower())) && (i.Type == AssetType) ).SingleOrDefault(); if (item == null) { ITSAssetFTY itemNew = new ITSAssetFTY() { ID = Guid.NewGuid().ToString(), Name = Name, Status = 1, Type = AssetType }; dbEntity.ITSAssetFTies.Add(itemNew); dbEntity.SaveChanges(); return(itemNew.ID); } return(item.ID); } catch (Exception ex) { sError = ex.Message; return(""); } }
public void AddItemToWarehouse(string ItemDetailID, string UnitID, int Quantity, string strDocType, FEA_BusinessLogic.FEA_ITSEntities dbRef) { string strType = strDocType; switch (strDocType) { case "MAINTENANCESTOCK": strType = "MAINTENANCE"; break; case "PRODUCTIONSTOCK": strType = "PRODUCTION"; break; } var item = dbRef.MNInventories.Where(i => (i.ItemDetailID == ItemDetailID) && (i.UnitID == UnitID)).SingleOrDefault(); if (item != null) { item.Quantity += Quantity; } else { item = new MNInventory() { ID = Guid.NewGuid().ToString(), DocType = strType, ItemDetailID = ItemDetailID, Quantity = Quantity, UnitID = UnitID }; dbRef.MNInventories.Add(item); } }
/// <summary> /// this function checking item in warehouse /// if the item exist then add item to it /// else - create new item /// </summary> /// <param name="ItemDetailID"></param> /// <param name="UnitID"></param> /// <param name="Quantity"></param> /// <param name="dbRef"></param> public void AddItemToWarehouse(string ItemDetailID, string UnitID, int Quantity, FEA_BusinessLogic.FEA_ITSEntities dbRef) { var item = dbRef.ITInventories.Where(i => (i.ItemDetailID == ItemDetailID) && (i.UnitID == UnitID)).SingleOrDefault(); if (item != null) { item.Quantity += Quantity; } else { item = new ITInventory() { ID = Guid.NewGuid().ToString(), ItemDetailID = ItemDetailID, Quantity = Quantity, UnitID = UnitID }; dbRef.ITInventories.Add(item); } }