public async Task <IActionResult> Edit(ProjectCVM project) { try { var record = _mapper.Map <Project>(project); if (project.BannerPhotoFile != null) { string oldBannerPath = record.BannerPhotoPath; record.BannerPhotoPath = await _fileManager.UploadFile(_appEnvironment.WebRootPath, record.Id.ToString(), project.BannerPhotoFile); if (!string.IsNullOrWhiteSpace(oldBannerPath)) { _fileManager.DeleteFile(_appEnvironment.WebRootPath, oldBannerPath); } } if (project.PreviewPhotoFile != null) { string oldPreviewPath = record.PreviewPhotoPath; record.PreviewPhotoPath = await _fileManager.UploadFile(_appEnvironment.WebRootPath, record.Id.ToString(), project.PreviewPhotoFile); if (!string.IsNullOrWhiteSpace(oldPreviewPath)) { _fileManager.DeleteFile(_appEnvironment.WebRootPath, oldPreviewPath); } } if (project.VideoFile != null) { string oldVideoLink = record.VideoLink; record.VideoLink = await _fileManager.UploadFile(_appEnvironment.WebRootPath, record.Id.ToString(), project.VideoFile); if (!string.IsNullOrWhiteSpace(oldVideoLink)) { _fileManager.DeleteFile(_appEnvironment.WebRootPath, oldVideoLink); } } _db.Projects.Update(record); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(List))); } catch (Exception e) { return(View(project)); } }
public async Task <IActionResult> Create(ProjectCVM model) { try { if (ModelState.IsValid) { Project project = _mapper.Map <Project>(model); _db.Projects.Add(project); await _db.SaveChangesAsync(); if (model.BannerPhotoFile != null) { project.BannerPhotoPath = await _fileManager.UploadFile(_appEnvironment.WebRootPath, project.Id.ToString(), model.BannerPhotoFile); } if (model.PreviewPhotoFile != null) { project.PreviewPhotoPath = await _fileManager.UploadFile(_appEnvironment.WebRootPath, project.Id.ToString(), model.PreviewPhotoFile); } if (model.VideoFile != null) { project.VideoLink = await _fileManager.UploadFile(_appEnvironment.WebRootPath, project.Id.ToString(), model.VideoFile); } _db.Projects.Update(project); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(List))); } return(RedirectToAction(nameof(Create))); } catch (Exception e) { return(View(model)); } }
public IActionResult Create() { var project = new ProjectCVM(); return(View(project)); }