예제 #1
0
 private void UpdateParsingStatus(MergeCustomerUpload upload, MergeCustomerUploadStatus status)
 {
     upload.StatusId = (long)status;
     if (MergeCustomerUploadStatus.Parsing == status)
     {
         upload.ParseStartTime = DateTime.Now;
     }
     else
     {
         upload.ParseEndTime = DateTime.Now;
     }
     upload = _mergeCustomerUploadRepository.Save(upload);
 }
예제 #2
0
        public ActionResult Upload(MergeCustomerEditModel model)
        {
            var sampleMediaLocation = _mediaRepository.GetSamplesLocation();
            var uploadMediaLocation = _mediaRepository.GetMergeCustomerUploadMediaFileLocation();

            model.UploadCsvMediaUrl = sampleMediaLocation.Url;

            HttpPostedFileBase postedFile = Request.Files[0];

            if (postedFile == null || postedFile.ContentLength < 1)
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("No file has been uploaded. Please upload a csv file.");
                return(View(model));
            }

            if (System.IO.Path.GetExtension(postedFile.FileName).ToLower() != ".csv")
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Please upload a csv file!");
                return(View(model));
            }

            var physicalPath = uploadMediaLocation.PhysicalPath;

            var fileContent = System.IO.Path.GetFileNameWithoutExtension(postedFile.FileName) + "_" + DateTime.Now.ToString("MMddyyyyhhmmss") + System.IO.Path.GetExtension(postedFile.FileName);

            var fullPath = physicalPath + fileContent;

            postedFile.SaveAs(fullPath);

            var customerTable = _csvReader.ReadWithTextQualifier(fullPath);

            if (customerTable.Rows.Count == 0)
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Uploaded file has no data.");
                return(View(model));
            }
            var missingColumnNames = _mergeCustomerUploadHelper.CheckForColumns(customerTable.Rows[0]);

            if (!string.IsNullOrEmpty(missingColumnNames))
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Missing Column Name(s) : " + missingColumnNames);
                return(View(model));
            }

            var file = new File
            {
                Path       = fileContent,
                FileSize   = postedFile.ContentLength,
                Type       = FileType.Csv,
                UploadedBy = new OrganizationRoleUser(_session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId),
                UploadedOn = DateTime.Now
            };

            file = _fileRepository.Save(file);

            var mergeCustomerUpload = new MergeCustomerUpload
            {
                FileId     = file.Id,
                StatusId   = (long)MergeCustomerUploadStatus.Uploaded,
                UploadedBy = _session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId,
                UploadTime = DateTime.Now
            };

            mergeCustomerUpload = _mergeCustomerUploadRepository.Save(mergeCustomerUpload);

            if (mergeCustomerUpload != null && mergeCustomerUpload.Id > 0)
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("File Uploaded Successfull.");
            }

            return(View(model));
        }