示例#1
0
        public ActionResult LoadRegistrationList(HttpPostedFileBase upload)
        {
            Trace.WriteLine("POST EventGuests/LoadRegistrationList upload: " + upload.ToString());
            ViewBag.Title = "Load Registration";
            CsvUploadStatus csvUploadStatus = service.UploadGuestsFromCsvFile(upload);

            if (!csvUploadStatus.SuccessfulUpload)
            {
                ViewBag.Message = csvUploadStatus.ErrorMessage;
                return(View(new DataTable()));
            }
            ViewBag.SuccessfulUploadMessage = true;
            ViewBag.RegisteredGuestCount    = csvUploadStatus.EventGuestsUploaded;
            ViewBag.AlreadyRegisteredCount  = csvUploadStatus.ColumnsNotUploaded;
            return(View(new DataTable()));
        }
示例#2
0
        public CsvUploadStatus UploadGuestsFromCsvFile(HttpPostedFileBase upload)
        {
            CsvUploadStatus status = new CsvUploadStatus();

            status.SuccessfulUpload = false;
            status.ErrorMessage     = EventGuestConstants.LOAD_REGISTRANTS_UPLOAD_ERROR;
            if (upload == null || upload.ContentLength <= 0)
            {
                return(status);
            }
            status.ErrorMessage = EventGuestConstants.LOAD_REGISTRANTS_FILE_TYPE_ERROR;
            if (!upload.FileName.EndsWith(".csv"))
            {
                return(status);
            }
            DataTable csvTable = createNewDataTableFromUpload(upload);

            int[] firstLastEmailArray = createIntArrayForFirstLastEmailColumns(csvTable);
            if (intArrayHasNegativeValues(firstLastEmailArray))
            {
                return(status);
            }
            int registeredCount    = 0;
            int notRegisteredCount = 0;

            foreach (DataRow row in csvTable.Rows)
            {
                EventGuest tableGuest = repository.CreateEventGuestFromRowData(row, firstLastEmailArray);
                if (repository.AddEventGuestToDbContext(tableGuest))
                {
                    registeredCount++;
                }
                else
                {
                    notRegisteredCount++;
                }
            }
            status.SuccessfulUpload    = true;
            status.EventGuestsUploaded = registeredCount;
            status.ColumnsNotUploaded  = notRegisteredCount;
            return(status);
        }