/// <summary>
 /// Method to get user detail by user id
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public UsersModel GetUserModelList(int userId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         UsersModel lstUser;
         using (DBUsers objDbUser = new DBUsers())
         {
             lstUser = objDbUser.GetUserModelList(userId);
         }
         return lstUser;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to update user detail
 /// </summary>
 /// <param name="userMl"></param>
 /// <returns></returns>
 public int UpdateUserDetails(UsersModel userMl)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         int result;
         using (DBUsers objDbUsers = new DBUsers())
         {
             result = objDbUsers.UpdateUserDetails(userMl);
         }
         return result;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Get device by logical device Id
 /// </summary>
 /// <param name="deviceMl"></param>
 /// <returns></returns>
 public int GetDeviceModelByLogicalDeviceId(DeviceModel deviceMl)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         int result;
         using (DBDevice objDbDevice = new DBDevice())
         {
             result = objDbDevice.GetDeviceModelByLogicalDeviceId(deviceMl);
         }
         return result;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 ///  Method to get the device detail by logical device id
 /// </summary>
 /// <param name="logicalDeviceId"></param>
 /// <returns></returns>
 public DeviceModel GetDeviceByLogicalDeviceId(string logicalDeviceId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         DeviceModel lstDevice;
         using (DBDevice objDbDevice = new DBDevice())
         {
             lstDevice = objDbDevice.GetDeviceByLogicalDeviceId(logicalDeviceId, Convert.ToInt32(ConfigurationManager.AppSettings["SensorTimeWindow"]));
         }
         return lstDevice;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method tot delete the device
 /// </summary>
 /// <param name="deviceId"></param>
 /// <returns></returns>
 public void DeleteDevice(int deviceId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         using (DBDevice objDbDevice = new DBDevice())
         {
             objDbDevice.DeleteDevice(deviceId);
         }
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get the user be email id
 /// </summary>
 /// <param name="emailId"></param>
 /// <returns></returns>
 public UsersModel GetUserModelListByEmail(string emailId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         UsersModel objUser;
         using (DBUsers objDbUsers = new DBUsers())
         {
             objUser = objDbUsers.GetUserModelListByEmail(emailId);
         }
         return objUser;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get list of temperatures
 /// </summary>
 /// <returns></returns>
 public IEnumerable<TemperatureModel> GetTemperatureList(string logicalDeviceId, string readingTimeFrom, string readingTimeTo)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         IEnumerable<TemperatureModel> lstTemperature;
         using (DBTemperature objDbTemperature = new DBTemperature())
         {
             lstTemperature = objDbTemperature.GetTemperatureList(logicalDeviceId, readingTimeFrom, readingTimeTo);
         }
         return lstTemperature;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Get device by id for deletion
 /// </summary>
 /// <param name="deviceId"></param>
 /// <returns></returns>
 public DeviceModel GetDeviceById(int deviceId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         DeviceModel device;
         using (DBDevice objDbDevice = new DBDevice())
         {
             device = objDbDevice.GetDeviceById(deviceId);
         }
         return device;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// MEthod to get the list of all items
 /// </summary>
 /// <returns></returns>
 public IEnumerable<ItemModel> GetItemList()
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         IEnumerable<ItemModel> lstItem;
         using (DBItem objDbItem = new DBItem())
         {
             lstItem = objDbItem.GetItemList();
         }
         return lstItem;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get item detail by item id
 /// </summary>
 /// <param name="itemId"></param>
 /// <returns></returns>
 public void DeleteItem(int itemId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         using (DBItem objDbItem = new DBItem())
         {
             objDbItem.DeleteItem(itemId);
         }
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get Item by Item Id
 /// </summary>
 /// <param name="itemId"></param>
 /// <returns></returns>
 public ItemModel GetItemByItemId(int itemId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         ItemModel lstItem;
         using (DBItem objDbItem = new DBItem())
         {
             lstItem = objDbItem.GetItemByItemId(itemId);
         }
         return lstItem;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get the list of inventories
 /// </summary>
 /// <returns></returns>
 public IEnumerable<InventoryModel> GetInventoryList(string logicalDeviceId, string searchText)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         IEnumerable<InventoryModel> lstInventory;
         using (DBInventory objDbInventory = new DBInventory())
         {
             lstInventory = objDbInventory.GetInventoryList(logicalDeviceId, searchText);
         }
         return lstInventory;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to filter the user list by search text
 /// </summary>
 /// <param name="searchText"></param>
 /// <returns></returns>
 public List<UsersModel> GetFilterUserModelList(string searchText)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         List<UsersModel> lstUsersModel;
         using (DBUsers objDbUser = new DBUsers())
         {
             lstUsersModel = objDbUser.GetFilterUserModelList(searchText);
         }
         return lstUsersModel;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// search user by search text for server side searching and paging
 /// </summary>
 /// <param name="searchText"></param>
 /// <param name="pageNumber"></param>
 /// <param name="pageSize"></param>
 /// <returns></returns>
 public List<UsersModel> SearchUserList(string searchText, int pageNumber, int pageSize)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         List<UsersModel> lstUsersModel;
         using (DBUsers objDbUser = new DBUsers())
         {
             lstUsersModel = objDbUser.SearchUserList(searchText, pageNumber, pageSize);
         }
         return lstUsersModel;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get device by deviceid with page number and page size for server side paging
 /// </summary>
 /// <param name="logicalDeviceId"></param>
 /// <returns></returns>
 public DeviceModel GetDeviceInventoriesList(string logicalDeviceId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         DeviceModel lstDevice;
         using (DBDevice objDbDevice = new DBDevice())
         {
             lstDevice = objDbDevice.GetDeviceInventoriesList(logicalDeviceId);
         }
         return lstDevice;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to check duplicate device with serial number
 /// </summary>
 /// <param name="deviceId"></param>
 /// <param name="serial"></param>
 /// <returns></returns>
 public int CheckForDuplicateSerial(int deviceId, string serial)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         int result;
         using (DBDevice objDbDevice = new DBDevice())
         {
             result = objDbDevice.CheckForDuplicateSerial(deviceId, serial);
         }
         return result;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Get ITem with EPC tag
 /// </summary>
 /// <param name="itemMl"></param>
 /// <returns></returns>
 public int GetItemModelByEpc(ItemModel itemMl)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         int result;
         using (DBItem objDbItem = new DBItem())
         {
             result = objDbItem.GetItemModelByEpc(itemMl);
         }
         return result;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get device list after applying filter of search text
 /// </summary>
 /// <param name="searchText"></param>
 /// <returns></returns>
 public List<DeviceModel> GetFilterDeviceList(string searchText)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         List<DeviceModel> lstDevice;
         using (DBDevice objDbDevice = new DBDevice())
         {
             lstDevice = objDbDevice.GetFilterDeviceList(searchText, Convert.ToInt32(ConfigurationManager.AppSettings["SensorTimeWindow"]));
         }
         return lstDevice;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get the itm list by search text filter
 /// </summary>
 /// <param name="searchText"></param>
 /// <returns></returns>
 public List<ItemModel> GetFilterItemList(string searchText)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         List<ItemModel> lstItem;
         using (DBItem objDbItem = new DBItem())
         {
             lstItem = objDbItem.GetFilterItemList(searchText);
         }
         return lstItem;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to get list of temperatures
 /// </summary>
 /// <param name="searchString"></param>
 /// <param name="startDateFrom"></param>
 /// <param name="startDateTo"></param>
 /// <returns></returns>
 public IEnumerable<TransactionModel> GetInventoryTransaction(string searchString, string startDateFrom, string startDateTo)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         IEnumerable<TransactionModel> lstTransaction;
         using (DBTransaction objDbTransaction = new DBTransaction())
         {
             lstTransaction = objDbTransaction.GetInventoryTransaction(searchString, startDateFrom, startDateTo, Convert.ToInt32(ConfigurationManager.AppSettings["SensorTimeWindow"]));
         }
         return lstTransaction;
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }
 /// <summary>
 /// Method to delete the user by user id
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public void DeleteUserDetails(int userId)
 {
     ServiceData serviceData = new ServiceData();
     try
     {
         using (DBUsers objDbUsers = new DBUsers())
         {
             objDbUsers.DeleteUserDetails(userId);
         }
     }
     catch (Exception ex)
     {
         serviceData.Result = false;
         serviceData.ErrorMessage = ex.Message;
         serviceData.ErrorDetails = ex.ToString();
         throw new FaultException<ServiceData>(serviceData);
     }
 }