public ActionResult DownloadlEntitiesFile(int?id) { string currentUserId = User.Identity.GetUserId(); if (currentUserId == null) { return(RedirectToAction("Register", "Account")); } ApplicationUser user = db.Users.Find(currentUserId); if (currentUserId != null && !user.EmailConfirmed) { return(RedirectToAction("Index", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Dataset dataset = datasetRepository.Get((int)id); if (dataset == null) { return(HttpNotFound()); } if (!securityService.HasAccess((int)id, currentUserId)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } byte[] entitiesFile = datasetService.GetEntitiesFile(dataset); return(File(entitiesFile, "text/csv", "Dataset_Entities" + DateTime.Now + ".csv")); }