/// <summary>
        /// Verify District Exists or not by stateId,districtId and districtName
        /// </summary>
        /// <param name="stateId">Int32:stateId</param>
        /// <param name="districtId">Int32:districtId</param>
        /// <param name="districtName">string:districtName</param>
        /// <returns></returns>
        public bool DistrictExists(int stateId, int districtId, string districtName)
        {
            DistrictDTO districtDetails = new DistrictDTO();
            bool result = false;

            if (districtId == 0)
            {
                AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<district>>()
                    .GetSingle(item => item.Dist_StateId == stateId &&
                    item.Dist_Name == districtName && item.Dist_IsDeleted == false), districtDetails);
            }
            else
            {
                AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<district>>()
                    .GetSingle(item => item.Dist_StateId == stateId && item.Dist_Name == districtName 
                        && item.Dist_IsDeleted == false && item.Dist_Id != districtId), districtDetails);
            }

            if (districtDetails.Dist_Id > 0)
            {
                result = true;
            }
            return result;
        }
        /// <summary>
        /// Get District By DistId
        /// </summary>
        /// <param name="districtId">Int32:districtId</param>
        /// <returns></returns>
        public DistrictDTO GetDistrictByDistId(int districtId)
        {
           DistrictDTO districtDetails = new DistrictDTO();

           AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<district>>()
               .GetSingle(item => item.Dist_IsDeleted == false && item.Dist_Id == districtId),
              districtDetails);
            
            //return the value
           return districtDetails;
        }
	protected void grdDistrict_RowUpdating(object sender, GridViewUpdateEventArgs e)
	{
		if (Page.IsValid)
		{
			DistrictDTO districtDetails = new DistrictDTO();
			districtDetails = ESalesUnityContainer.Container.Resolve<ILocationService>()
			   .GetDistrictByDistId(Convert.ToInt32(grdDistrict.DataKeys[e.RowIndex].Value));

			districtDetails.Dist_Name = ((TextBox)grdDistrict.Rows[e.RowIndex].FindControl("txtDistrict")).Text;
			districtDetails.Dist_LastUpdatedDate = DateTime.Now;
			districtDetails.Dist_Createdby = GetCurrentUserId();

			int stateId = ESalesUnityContainer.Container.Resolve<ILocationService>().SaveAndUpdateDistrict(districtDetails);
			ucMessageBoxForGrid.ShowMessage(Messages.DistrictUpdatedSuccessfully);
		}
	}
        /// <summary>
        /// Save And Update District
        /// </summary>
        /// <param name="districtDetails"></param>
        /// <returns></returns>
        public int SaveAndUpdateDistrict(DistrictDTO districtDetails)
        {            
            district districtEntity = new district();
            AutoMapper.Mapper.Map(districtDetails, districtEntity);
            
            if (districtEntity.Dist_Id == 0)
            {
                ESalesUnityContainer.Container.Resolve<IGenericRepository<district>>().Save(districtEntity);
            }
            else
            {
                ESalesUnityContainer.Container.Resolve<IGenericRepository<district>>().Update(districtEntity);
            }

            //return value
            return districtEntity.Dist_Id;
        }
    protected void grdDistrict_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == Globals.GridCommandEvents.ADDNEW)
        {
            if (Page.IsValid)
            {
                DistrictDTO districtDetails = new DistrictDTO();

                GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
                districtDetails.Dist_Name = ((TextBox)row.FindControl("txtNewDistrict")).Text;
                districtDetails.Dist_StateId = Convert.ToInt32(ViewState["StateId"]);
                districtDetails.Dist_CreatedDate = DateTime.Now;
                districtDetails.Dist_LastUpdatedDate = DateTime.Now;
                districtDetails.Dist_Createdby = GetCurrentUserId();
                
                int districtId = ESalesUnityContainer.Container.Resolve<ILocationService>().SaveAndUpdateDistrict(districtDetails);
				ucMessageBoxForGrid.ShowMessage(Messages.DistrictSavedSuccessfully);
            }
        }
    }