public ActionResult ScanDirectories(FormCollection form) { int _registeredSolutions = 0; try { string[] directoriesChecked = form.AllKeys; List<string> directoriesToScan = _utilityService.ResolveDirectories(directoriesChecked); if (directoriesToScan != null) foreach (string directory in directoriesToScan) { string _solutionFile = string.Empty; if (_utilityService.HasDirectoryDotNETSolution(directory, out _solutionFile)) { Solution _newSolution = new Solution(); _newSolution.Name = _solutionFile; _newSolution.Description = _solutionFile; _newSolution.DateRegistered = DateTime.Now; _newSolution.FilePath = Path.Combine(directory, _solutionFile + ".sln"); _newSolution.SolutionTypeID = _solutionTypeService.GetDefaultSolutionTypeID(); _solutionService.CreateSolution(_newSolution); try { _solutionService.SaveSolution(); _registeredSolutions++; } catch { continue; } } } return RedirectToAction("Index", "Solutions").WithSuccess(_registeredSolutions + " found and registered automatically by BrowseDotNET."); } catch (Exception ex) { return RedirectToAction("ScanSolutions").WithError("Errors occured during scanning for .NET Solutions." + ex.Message); } }
public void CreateSolution(Solution solution) { solutionsRepository.Add(solution); }
public ActionResult DotNetSolution(SolutionViewModel solution) { try { if (ModelState.IsValid) { Solution newSolution = new Solution(); newSolution.Author = solution.Author; newSolution.Description = solution.Description; newSolution.FilePath = solution.FilePath.Trim(); newSolution.Name = solution.Name.Trim(); newSolution.SolutionTypeID = solution.SolutionTypeID; newSolution.Keys = _utilityService.ResolveKeys(solution.Keys); newSolution.Website = solution.Website; newSolution.DateRegistered = DateTime.Now; try { _solutionService.CreateSolution(newSolution); _solutionService.SaveSolution(); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } SetSolutionTypes(); return RedirectToAction("DotNetSolution").WithSuccess(solution.Name + " succesfully added."); } else { ModelState.AddModelError("", "Validation errors occured."); SetSolutionTypes(); return View(solution); } } catch (Exception ex) { SetSolutionTypes(); return View(solution).WithError(ex.Message); } }