public int InsertOrUpdateItem(ItemInfoFilter itemInfo) { IDataReader dataReader = null; try { Database db = DatabaseFactory.CreateDatabase("DbConnection"); int currentDate = 0; int currentTime = 0; Common.GetCurrentDateTime(out currentDate, out currentTime); dataReader = BillingDAL.CheckItemNameExists(db, itemInfo.ItemID, itemInfo.ItemName); if (dataReader.Read()) { dataReader.Close(); return(-1); //itemname already exists } else { dataReader.Close(); if (itemInfo.ItemID > 0) { BillingDAL.UpdateItem(db, itemInfo.ItemID, itemInfo.ItemName, itemInfo.ItemDescription, itemInfo.Price, itemInfo.UserID, currentDate, currentTime); return(itemInfo.ItemID); } else { return(BillingDAL.InsertItem(db, itemInfo.ItemName, itemInfo.ItemDescription, itemInfo.Price, itemInfo.UserID, currentDate, currentTime)); } } } catch (Exception ex) { Common.LogException(ex); throw new WebFaultException <string>(ex.Message, HttpStatusCode.InternalServerError); } finally { if (dataReader != null && !dataReader.IsClosed) { dataReader.Close(); } } }