/// <summary>
        /// Save and Update Counters
        /// </summary>
        /// <param name="counterDetails"></param>
        public void SaveAndUpdateCounters(CounterDTO counterDetails)
        {
            counter counterEntity = new counter();
            AutoMapper.Mapper.Map(counterDetails, counterEntity);

            if (counterDetails.Counter_Id == 0)
            {
                ESalesUnityContainer.Container.Resolve<IGenericRepository<counter>>().Save(counterEntity);
            }
            else
            {
                ESalesUnityContainer.Container.Resolve<IGenericRepository<counter>>().Update(counterEntity);
            }
        }
 /// <summary>
 /// Initialize counter details to be updated on daily basis
 /// </summary>
 /// <param name="counterDetail">Counter which is to be updated for current day</param>
 /// <returns>returns counter details</returns>
 private CounterDetailsDTO InitializeCounterDetails(CounterDTO counter)
 {
     CounterDetailsDTO counterDetails = new CounterDetailsDTO();
     counterDetails.CounterDetail_Counter_ID = counter.Counter_Id;
     counterDetails.CounterDetail_Agent_Id = Convert.ToInt32(counter.Counter_Agent_Id);
     counterDetails.CounterDetail_Date = DateTime.Now.Date;
     counterDetails.CounterDetail_Count = 0;
     counterDetails.CounterDetail_CreatedDate = DateTime.Now;            
     return counterDetails;
 }
    /// <summary>
    /// TO check MACId for this user already exists or not
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    protected void CheckMACId_ServerValidate(object sender, ServerValidateEventArgs args)
    {
          CounterDTO objCounterDTO=new CounterDTO();
          if (ViewState["CounterId"] != null)
          {
              objCounterDTO = ESalesUnityContainer.Container.Resolve<ICounterService>().GetCounterDetailsByMacId(txtMacId.Text.Trim(),  Convert.ToInt32(Membership.GetUser(ddlUser.SelectedItem.Value).ProviderUserKey), Convert.ToInt32(ViewState["CounterId"]));
          }
          else
          {
              objCounterDTO = ESalesUnityContainer.Container.Resolve<ICounterService>().GetCounterDetailsByMacId(txtMacId.Text.Trim(), Convert.ToInt32(Membership.GetUser(ddlUser.SelectedItem.Value).ProviderUserKey), 0);
          }

        if (objCounterDTO.Counter_Id >0)
        {
            args.IsValid = false;
        }
    }
    /// <summary>
    /// Initialized counter details from page values
    /// </summary>
    /// <returns>returns counter details with duly filled in values</returns>
    private CounterDTO InitializeCounterDetails()
    {    
        CounterDTO counterDetails = new CounterDTO();
        if (ViewState[Globals.StateMgmtVariables.COUNTERID] != null)
        {
            counterDetails.Counter_Id = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.COUNTERID]);
        }

        counterDetails.Counter_Name = txtCounterName.Text.Trim();
        counterDetails.Counter_MAC_Id = txtMacId.Text.Trim();
        counterDetails.Counter_Agent_Id = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.AGENTID]);
        counterDetails.Counter_User_Id = Convert.ToInt32(Membership.GetUser(ddlUser.SelectedItem.Value).ProviderUserKey);
        counterDetails.Counter_CreatedBy = base.GetCurrentUserId();
        counterDetails.Counter_CreatedDate = DateTime.Now;
        counterDetails.Counter_LastUpdatedDate = DateTime.Now;
        return counterDetails;
    }
        /// <summary>
        /// Get Counter Details By Id
        /// </summary>
        /// <param name="counterId">int32:counterId</param>
        /// <returns></returns>
        public CounterDTO GetCounterDetailsById(int counterId)
        {
            CounterDTO CounterDetails = new CounterDTO();
            counter objlstCounterDetail = ESalesUnityContainer.Container.Resolve<IGenericRepository<counter>>()
                .GetSingle(item => item.Counter_IsDeleted == false && item.Counter_Id == counterId);

            AutoMapper.Mapper.Map(objlstCounterDetail, CounterDetails);
            return CounterDetails;
        }
        /// <summary>
        /// Get Counter Details  By MacId
        /// </summary>
        /// <param name="macAddress">string:macAddress</param>
        /// <param name="userId">int32:userId</param>
        /// <param name="counterId">int32:counterId</param>
        /// <returns></returns>
        public CounterDTO GetCounterDetailsByMacId(string macAddress, int userId, int counterId)
        {
            CounterDTO counterDetails = new CounterDTO();
            counter counterEntity = new counter();

            if (userId > 0)
            {
                counterEntity = ESalesUnityContainer.Container.Resolve<IGenericRepository<counter>>()
                   .GetSingle(item => item.Counter_IsDeleted == false && item.Counter_MAC_Id == macAddress
                       && item.Counter_User_Id == userId);
            }
            else
            {
                if (counterId > 0)
                {
                    counterEntity = ESalesUnityContainer.Container.Resolve<IGenericRepository<counter>>()
                      .GetSingle(item => item.Counter_IsDeleted == false && item.Counter_MAC_Id == macAddress
                          && item.Counter_Id != counterId);
                }
                else
                {
                    counterEntity = ESalesUnityContainer.Container.Resolve<IGenericRepository<counter>>()
                       .GetSingle(item => item.Counter_IsDeleted == false && item.Counter_MAC_Id == macAddress);
                }
            }

            AutoMapper.Mapper.Map(counterEntity, counterDetails);
            return counterDetails;
        }