public ActionResult ImportSubmissionLinks(ImportSubmissionLinksViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { int imported = 0, rejected = 0; var rejectedUrls = new List <SubmissionPageLink>(); var data = _bulkImporter.Execute(model.File.InputStream); foreach (var submissionPageLink in data) { var journal = journalRepository.FindByIssn(submissionPageLink.ISSN); if (journal == null || !DomainMatches(journal.Link, submissionPageLink.Url)) { rejected++; rejectedUrls.Add(submissionPageLink); continue; } journal.SubmissionPageLink = submissionPageLink.Url; imported++; } journalRepository.Save(); return(View("SubmissionLinksImportSuccessful", new SubmissionLinksImportedViewModel { AmountImported = imported, AmountRejected = rejected, RejectedUrls = rejectedUrls })); } catch (ArgumentException invalidFileException) { ModelState.AddModelError("generalError", invalidFileException.Message); } catch (DbEntityValidationException) { //foreach (var eve in e.EntityValidationErrors) //{ // Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",eve.Entry.Entity.GetType().Name, eve.Entry.State); // foreach (var ve in eve.ValidationErrors) // { // Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); // } //} //throw; } catch (Exception exception) { while (exception.InnerException != null) { exception = exception.InnerException; } ModelState.AddModelError("generalError", $"An error has ocurred: {exception.Message}"); } return(View(model)); }
public ActionResult ImportSubmissionLinks(ImportSubmissionLinksViewModel model) { if (!ModelState.IsValid) return View(model); try { int imported = 0, rejected = 0; var rejectedUrls = new List<SubmissionPageLink>(); var data = _bulkImporter.Execute(model.File.InputStream); foreach (var submissionPageLink in data) { var journal = journalRepository.FindByIssn(submissionPageLink.ISSN); if (journal == null || !DomainMatches(journal.Link, submissionPageLink.Url)) { rejected++; rejectedUrls.Add(submissionPageLink); continue; } journal.SubmissionPageLink = submissionPageLink.Url; imported++; } journalRepository.Save(); return View("SubmissionLinksImportSuccessful", new SubmissionLinksImportedViewModel { AmountImported = imported, AmountRejected = rejected, RejectedUrls = rejectedUrls }); } catch (ArgumentException invalidFileException) { ModelState.AddModelError("generalError", invalidFileException.Message); } catch (DbEntityValidationException) { //foreach (var eve in e.EntityValidationErrors) //{ // Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",eve.Entry.Entity.GetType().Name, eve.Entry.State); // foreach (var ve in eve.ValidationErrors) // { // Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); // } //} //throw; } catch (Exception exception) { while (exception.InnerException != null) exception = exception.InnerException; ModelState.AddModelError("generalError", $"An error has ocurred: {exception.Message}"); } return View(model); }