public HttpResponseMessage DownloadDataset(DataRequestModel requestModel) { if (requestModel == null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid Request"); } requestModel = new DataRequestModel() { AppId = requestModel.AppId, DatasetID = requestModel.DatasetID, GUID = requestModel.GUID, DeviceId = requestModel.DeviceId //AppId = 1, //DatasetID = 4, //GUID = Guid.Parse("90b2044c-ae0a-46f3-9260-acf3a058294a"), //DeviceId = "Hammads" }; if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid Request"); } DownloadActions downloadActions = new DownloadActions(); DataResponseModel responseModel = downloadActions.DownloadData(requestModel); if (responseModel.Error != null) { return Request.CreateResponse(HttpStatusCode.OK, responseModel, "application/json"); } return Request.CreateResponse(HttpStatusCode.OK, responseModel, "application/json"); }
public DataResponseModel DownloadData(DataRequestModel requestModel) { DownloadCase downloadCase = new DownloadCase(); return downloadCase.DownloadFile(requestModel); }
/// <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; }