private void UpdateEligibilityUploadDetail(EligibilityUpload eligibilityUploadDomain, List <EligibilityUploadLogViewModel> failedRecordsList, string fileName) { if (failedRecordsList.Any()) { try { var location = _mediaRepository.GetEligibilityUploadMediaFileLocation(); var failedFilePath = location.PhysicalPath + Path.GetFileNameWithoutExtension(fileName) + "_Failed.csv"; var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <EligibilityUploadLogViewModel>(); WriteCsv(failedFilePath, exporter, failedRecordsList); var failedRecords = new FileInfo(failedFilePath); var file = new File { Path = failedRecords.Name, FileSize = failedRecords.Length, Type = FileType.Csv, UploadedBy = new OrganizationRoleUser(1), UploadedOn = DateTime.Now }; file = _fileRepository.Save(file); eligibilityUploadDomain.FailedUploadCount = failedRecordsList.Count(); eligibilityUploadDomain.LogFileId = file.Id; } catch (Exception ex) { _logger.Error("Exception Raised while creating failed records CSV\n message: " + ex.Message + " stacktrace: " + ex.StackTrace); } } _eligibilityUploadRepository.Save(eligibilityUploadDomain); }
private void UpdateParsingStatus(EligibilityUpload eligibilityUploadDomain, long statusId, bool isCompleted = true) { eligibilityUploadDomain.StatusId = statusId;; eligibilityUploadDomain.ParseEndTime = DateTime.Now; eligibilityUploadDomain.ParseEndTime = isCompleted ? DateTime.Now : (DateTime?)null; _eligibilityUploadRepository.Save(eligibilityUploadDomain); }
public EligibilityUpload Save(EligibilityUpload domainObject) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var entity = Mapper.Map <EligibilityUpload, EligibilityUploadEntity>(domainObject); if (!adapter.SaveEntity(entity, true)) { throw new PersistenceFailureException("Could not save Eligibility Upload "); } return(Mapper.Map <EligibilityUploadEntity, EligibilityUpload>(entity)); } }
public ActionResult EligibilityUpload(HttpPostedFileBase eligibilityUploadFile, CustomerEligibilityUploadEditModel model) { try { if (Request.Files.Count < 1 || eligibilityUploadFile == null) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("No file has been uploaded. Please upload a csv file."); return(View(model)); } HttpPostedFileBase file = Request.Files[0]; var fileExtension = file.FileName.Split('.'); if ((fileExtension.Length >= 2 && fileExtension[fileExtension.Length - 1].ToLower() != "csv") || fileExtension.Length < 2) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("File uploaded is not a CSV"); return(View(model)); } try { var organization = _organizationRepository.GetOrganizationbyId(model.CorporateAccountId); } catch (Exception ex) { _logger.Error(string.Format("EligibilityUpload\nException occurred while retrieving account by accountId: {0}", model.CorporateAccountId)); _logger.Error(string.Format("Exception message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace)); model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Select valid corporate Account"); return(View(model)); } var uploadMediaLocation = _mediaRepository.GetEligibilityUploadMediaFileLocation(); var physicalPath = uploadMediaLocation.PhysicalPath; var fileUploadedName = (Path.GetFileNameWithoutExtension(file.FileName) + Path.GetExtension(file.FileName)).Replace("'", "").Replace("&", ""); var fileName = (Path.GetFileNameWithoutExtension(fileUploadedName) + "_" + DateTime.Now.ToString("MMddyyyyhhmmss") + Path.GetExtension(fileUploadedName)).Replace("'", "").Replace("&", ""); var fullPath = physicalPath + fileName; try { file.SaveAs(fullPath); } catch (Exception ex) { _logger.Error(string.Format("EligibilityUpload\nException occurred while saving file on server. FileName:{0} Path: {1}", fileUploadedName, fullPath)); _logger.Error(string.Format("Exception message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace)); model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Some internal error occurred"); return(View(model)); } var csvReader = IoC.Resolve <ICsvReader>(); var customerTable = csvReader.ReadWithTextQualifier(fullPath); if (customerTable.Rows.Count == 0) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Uploaded file has no data."); return(View(model)); } var columns = customerTable.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToArray(); var missingColumnNames = _corporateUploadHelper.CheckAllEligibilityColumnExist(columns); if (!string.IsNullOrEmpty(missingColumnNames)) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Missing Column Name(s) : " + missingColumnNames); return(View(model)); } var files = new Core.Application.Domain.File { Path = fileName, FileSize = file.ContentLength, Type = FileType.Csv, UploadedBy = new OrganizationRoleUser(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId), UploadedOn = DateTime.Now }; try { files = _fileRepository.Save(files); } catch (Exception ex) { _logger.Error(string.Format("EligibilityUpload\nException occurred while saving info in TblFile.")); _logger.Error(string.Format("Exception message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace)); model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Some internal error occurred"); return(View(model)); } var eligibilityUpload = new EligibilityUpload { FileId = files.Id, UploadTime = DateTime.Now, UploadedBy = _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId, AccountId = model.CorporateAccountId, StatusId = (long)EligibilityUploadStatus.Uploaded }; try { eligibilityUpload = _eligibilityUploadRepository.Save(eligibilityUpload); } catch (Exception ex) { _logger.Error(string.Format("EligibilityUpload\nException occurred while saving info in EligibilityUpload.")); _logger.Error(string.Format("Exception message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace)); model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Some internal error occurred"); return(View(model)); } if (eligibilityUpload != null && eligibilityUpload.Id > 0) { ModelState.Clear(); //const string message = "File uploaded successfully"; return(RedirectToAction("EligibilityUpload", "MassRegistration", new { message = "File uploaded successfully" })); } model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("File upload failed"); return(View(model)); } catch (Exception ex) { _logger.Error(string.Format("EligibilityUpload\nException occurred")); _logger.Error(string.Format("Exception message: {0}\n\tStackTrace:{1}", ex.Message, ex.StackTrace)); model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Some internal error occurred"); return(View(model)); } }