/// <summary>
        /// A controller method to navigate to the page to upload
        /// data into the Staging Table. Take the ID of the staging table as
        /// a parameter.
        ///
        /// Accessed via /Staging/UploadToStaging
        /// </summary>
        /// <param name="tableID">The database ID of the staging table to be uploaded to. </param>
        /// <returns></returns>
        public ActionResult UploadToStaging(int tableID)
        {
            UploadStagingModel model = new UploadStagingModel();

            model.StagingTableID = tableID;

            List <Breadcrumb> trail = new List <Breadcrumb>();

            trail.Add(new Breadcrumb()
            {
                LinkText = "Home", Action = "Index", Controller = "Home", isCurrent = false
            });
            trail.Add(new Breadcrumb()
            {
                LinkText = "Staging Index", Action = "Index", Controller = "Staging", isCurrent = false
            });
            trail.Add(new Breadcrumb()
            {
                LinkText = "Upload to Staging", isCurrent = true
            });

            model.Breadcrumbs = trail;

            return(View(model));
        }
 /// <summary>
 /// Method to persist a file to a location on disk
 /// </summary>
 /// <param name="model">The model object that contains the file to be saved</param>
 /// <param name="path">The path that the file should be uploaded to</param>
 public void writeCSVtoDisk(UploadStagingModel model, String path)
 {
     try
     {
         model.attachment.SaveAs(path);
     }
     catch (Exception ex)
     {
     }
 }
        public ActionResult UploadToStaging(UploadStagingModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.attachment.ContentLength > 0)
                {
                    string fileName = Path.GetFileName(model.attachment.FileName);
                    string path     = Path.Combine(Server.MapPath("~/App_Data/CSVUploads"), fileName);

                    Data_Loading_Tool.Database.FileAccess fileAccess = new Data_Loading_Tool.Database.FileAccess();

                    fileAccess.writeCSVtoDisk(model, path);

                    StagingDataAccess dataAccess = new StagingDataAccess();

                    dataAccess.updateTableFromCSV(path, model.StagingTableID, model.UniqueUploadRef, model.UnpivotData, model.FirstUpload, model.GeographyColumn);

                    TempData["SuccessMessage"] = "The Data was uploaded successfully";
                    return(RedirectToAction("Index"));
                }
            }

            List <Breadcrumb> trail = new List <Breadcrumb>();

            trail.Add(new Breadcrumb()
            {
                LinkText = "Home", Action = "Index", Controller = "Home", isCurrent = false
            });
            trail.Add(new Breadcrumb()
            {
                LinkText = "Staging Index", Action = "Index", Controller = "Staging", isCurrent = false
            });
            trail.Add(new Breadcrumb()
            {
                LinkText = "Upload to Staging", isCurrent = true
            });

            model.Breadcrumbs = trail;

            return(View(model));
        }