public ActionResult ConfirmUpload(BulkUploadHistoryDetailViewModel bulkModel)
        {
            if ((userContext.IsProvider() && Permission.HasPermission(false, true, Permission.PermissionName.CanBulkUploadProviderFiles)) ||
                (userContext.IsOrganisation() && Permission.HasPermission(false, true, Permission.PermissionName.CanBulkUploadOrganisationFiles)))
            {
                var history = db.BulkUploads.FirstOrDefault(b => b.BulkUploadId.Equals(bulkModel.BulkUploadId));
                if (history == null)
                {
                    return(HttpNotFound());
                }

                if (userContext.ItemId.HasValue)
                {
                    if ((userContext.IsOrganisation() && history.UserOrganisationId != userContext.ItemId) ||
                        (userContext.IsProvider() && history.UserProviderId != userContext.ItemId))
                    {
                        return(HttpNotFound());
                    }
                }
                else
                {
                    return(HttpNotFound());
                }

                // Check that the status is currently at "Needs Confirmation"
                if (history
                    .BulkUploadStatusHistories
                    .OrderByDescending(x => x.CreatedDateTimeUtc)
                    .First()
                    .BulkUploadStatusId != (Int32)Constants.BulkUploadStatus.Needs_Confirmation)
                {
                    return(HttpNotFound());
                }

                var model = new BulkUploadViewModel
                {
                    Summary = new UploadSummary
                    {
                        TargetFileUrl = history.FilePath,
                        FileName      = history.FileName
                    },
                    OverrideException = true
                };

                /*
                 * Matt - dev note
                 * ---------------------
                 * This section relates to replacing the in-application BulkUpload
                 * with a more efficient out-of-application service based system.
                 *
                 */
                try
                {
                    var bulkUploadService = new BulkUploadWCFServiceClient();
                    var parameters        = new ConfirmParameters
                    {
                        BulkUploadId = bulkModel.BulkUploadId,
                        UserId       =
                            history
                            .BulkUploadStatusHistories
                            .OrderByDescending(x => x.CreatedDateTimeUtc)
                            .First()
                            .AspNetUser
                            .Id
                    };
                    bulkUploadService.Confirm(parameters);
                }
                catch (FaultException <BulkUploadFault> ex)
                {
                    model.Message = String.Format("The bulk upload service reported an error: {0}", ex.Detail.Message);
                }

                /*
                 * end
                 */

                //model.InitiateBulkUpload(userContext, db);
                string viewName;
                if (history.FileContentType != null && history.FileContentType == (int)Constants.FileContentType.ApprenticeshipData)
                {
                    viewName = "PostApprenticeshipUpload";
                }
                else
                {
                    viewName = "PostCourseUpload";
                }

                //   var viewName = (bulkModel.FileContentType == Constants.FileContentType.CourseData ? "PostCourseUpload" : "PostApprenticeshipUpload");

                return(View(viewName, model));
            }
            return(Redirect());
        }
Beispiel #2
0
        public static void InitiateBulkUpload(
            this BulkUploadViewModel model,
            UserContext.UserContextInfo userContext,
            ProviderPortalEntities db)
        {
            try
            {
                // copy data to local data store
                new FileHandler(model).CopyFileToDataStore();

                // get bulk upload service client
                var bulkUploadService = new BulkUploadWCFServiceClient();

                // when validating only ...
                if (!model.OverrideException)
                {
                    // ... build contextual parameters for bulk upload serivce
                    var parameters = new EnqueueParameters
                    {
                        FileName          = model.Summary.FileName,
                        FilePath          = model.Summary.FilePath,
                        UserId            = LoggedInUser(db),
                        UserContextType   = userContext.ContextName.ToString(),
                        UserContextItemId = (int)userContext.ItemId,
                        FileSize          = model.Summary.ContentLength
                    };

                    // ... and enqueue the bulk upload with the service
                    var result = bulkUploadService.Enqueue(parameters);
                }
            }
            catch (EndpointNotFoundException ex)
            {
                model.Message = AppGlobal.Language.GetText(
                    "BulkUpload_Exceptions_EndpointNotFoundException",
                    "The Bulk Upload service has encountered an error, and your upload has failed.  Please try your upload later.  If you encounter this message again, please contact the Support Team.");
                AppGlobal.Log.WriteLog(string.Concat(ex.Message, ":", ex.StackTrace));
            }
            catch (TimeoutException ex)
            {
                model.Message = AppGlobal.Language.GetText(
                    "BulkUpload_Exceptions_TimeoutException",
                    "The Bulk Upload service could not be contacted, and your upload has failed.  Please try your upload later.  If you encounter this message again, please contact the Support Team.");
                AppGlobal.Log.WriteLog(string.Concat(ex.Message, ":", ex.StackTrace));
            }
            catch (FaultException <BulkUploadProviderFault> ex)
            {
                var template = AppGlobal.Language.GetText("BulkUpload_Exceptions_BulkUploadProviderFaultException", "The Bulk Upload service has rejected your file, with the following error: {0}");
                model.Message = String.Format(template, ex.Detail.Message);
            }
            catch (FaultException <BulkUploadFault> ex)
            {
                model.Message = AppGlobal.Language.GetText("BulkUpload_Exceptions_BulkUploadFaultException", "The Bulk Upload service has encountered an error, and your upload has failed.  Please try your upload later.  If you encounter this message again, please contact the Support Team.");
                AppGlobal.Log.WriteLog(string.Concat(ex.Detail.Message, ":", ex.StackTrace));
            }
            catch (Exception ex)
            {
                model.Message = ex.Message;
                AppGlobal.Log.WriteLog(string.Concat(ex.Message, ":", ex.StackTrace));
            }
        }