/// <summary>
        /// Delete free data , create file name , Get all dataset of users and generate file if not exist on file system
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public DataResponseModel DownloadFile(DataRequestModel requestModel)
        {
            DataResponseModel dataResponseModel = new DataResponseModel();
            var datasetIds = new List<int>();

            DownloadRepo downloadrepo = new DownloadRepo();
            int? UserId = downloadrepo.GetUserId(requestModel.GUID, requestModel.DeviceId, requestModel.AppId);

            if(UserId == null)
            {
                dataResponseModel.IsValid = false;
                dataResponseModel.Error = "Invalid User";
                return dataResponseModel;
            }


            if ((requestModel.DatasetID == 0))   //Full Data                      //If full data
            {
                if (UserId == null)
                {
                    dataResponseModel.IsValid = false;
                    dataResponseModel.Error = "Invalid User";
                    return dataResponseModel;
                }


                List<int> getUserDataSets = downloadrepo.GetUserDataset(UserId.Value);

                if (getUserDataSets == null)
                {
                    dataResponseModel.IsValid = false;
                    dataResponseModel.Error = "Invalid User";
                    return dataResponseModel;
                }

                DestroyFreeDataRepo destroyFree = new DestroyFreeDataRepo();
                destroyFree.DeleteFreeData(UserId.Value);

                datasetIds = getUserDataSets;
            }
            else       
            {

                DestroyFreeDataRepo destroyFree = new DestroyFreeDataRepo();
                destroyFree.DeleteFreeData(UserId.Value);

                AddFreeData addFreeData = new AddFreeData();
                addFreeData.AddData(UserId.Value,requestModel.DatasetID);

                datasetIds.Add(requestModel.DatasetID);
            }

            string fileName = "";
            var folderPath = "";
            var filePath = "";

            GenerateJSON createFile = new GenerateJSON();            //Create File Name
            createFile.createFileName(datasetIds,ref filePath ,ref folderPath ,ref fileName);

            
            if (!File.Exists(filePath))
            {
                GenerateJSON generateJSON = new GenerateJSON();       //File Not Exists then generate data
                generateJSON.generateJSON(datasetIds,filePath,folderPath,fileName);
            }

            filePath = System.Web.Hosting.HostingEnvironment.MapPath(string.Format("{0}{1}", folderPath, fileName + ".gz"));   //Creating File Path

            GenerateTokenRepo token = new GenerateTokenRepo();
            string TokenId = token.AddToDatabase(requestModel.GUID , filePath);


            //InstallationRepo installationRepo = new InstallationRepo();
            //installationRepo.LastDateUpdated(requestModel.GUID);

            dataResponseModel.IsValid = true;
            dataResponseModel.Error = null;
            dataResponseModel.TokenId = TokenId;
            return dataResponseModel;
        }
        /// <summary>
        /// Validating Download Token
        /// </summary>
        /// <param name="tokenId"></param>
        /// <returns></returns>
        public TokenResponseModel DownloadOnToken(string tokenId)
        {
            TokenResponseModel responseModel = new TokenResponseModel();

            GenerateTokenRepo token = new GenerateTokenRepo();
            string filePath = token.TokenStatus(tokenId);

            if(filePath == null)
            {
                responseModel.IsValid = false;
                responseModel.Error = "Token Expired";
                return responseModel; 
            }

            responseModel.IsValid = true;
            responseModel.Error = null;
            responseModel.filePath = filePath;
            return responseModel; 
        }