public ActionResult Edit(AuthorEditModel model) { try { if (model.NewPhoto != null) { string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Authors/" + FilePathGenerator.GenerateFileName(model.NewPhoto.FileName)); if (!string.IsNullOrEmpty(model.PhotoPath) && System.IO.File.Exists(model.PhotoPath)) { System.IO.File.Delete(model.PhotoPath); } model.NewPhoto.SaveAs(filepath); model.PhotoPath = filepath; } var author = model.ToServiceAuthor(); service.UpdateAuthor(author); return(RedirectToAction("Index")); } catch (Exception ex) { logger.Error(ex); return(View("Error")); } }
public ActionResult Create(AuthorCreateModel model) { try { if (ModelState.IsValid) { int id; if (model.Photo != null) { string filepath = Server.MapPath("~/App_Data/Uploads/Covers/Authors/" + FilePathGenerator.GenerateFileName(model.Photo.FileName)); model.Photo.SaveAs(filepath); id = service.AddAuthor(model.ToServiceAuthor(filepath)); } else { id = service.AddAuthor(model.ToServiceAuthor()); } return(RedirectToAction("Details", new { id = id })); } return(View(model)); } catch (Exception ex) { logger.Error(ex); return(View("Error")); } }
public static string SaveFile(HttpServerUtilityBase server, HttpPostedFileBase file, string directory) { string filepath = server.MapPath(directory + FilePathGenerator.GenerateFileName(file.FileName)); file.SaveAs(filepath); return(filepath); }
public void FilePathGenerator_GenerateFilePath_ShouldReturnCorrectPath( string projectDir, string relativeOutputDir, string featureFile, string generatedCodeBehindName, string expected) { // ARRANGE var filePathGenerator = new FilePathGenerator(); // ACT string actual = filePathGenerator.GenerateFilePath(projectDir, relativeOutputDir, featureFile, generatedCodeBehindName); // ASSERT actual.Should().Be(expected); }
public void FilePathGenerator_GenerateFilePath_ShouldReturnCorrectPath_Linux( string projectDir, string relativeOutputDir, string featureFile, string generatedCodeBehindName, string expected) { Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); // ARRANGE var filePathGenerator = new FilePathGenerator(); // ACT string actual = filePathGenerator.GenerateFilePath(projectDir, relativeOutputDir, featureFile, generatedCodeBehindName); // ASSERT actual.Should().Be(expected); }
/// <summary> /// Constructor /// </summary> /// <param name="filePathGenerator"></param> public VlecisConfig(FilePathGenerator <CsvFileExtension> filePathGenerator) =>
public TableFileCodeBehindGenerator(TaskLoggingHelper log, TableCodeBehindGenerator tableCodeBehindGenerator) { Log = log ?? throw new ArgumentNullException(nameof(log)); _tableCodeBehindGenerator = tableCodeBehindGenerator; _filePathGenerator = new FilePathGenerator(); }