public ActionResult SaveJob(JobFormViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("CreateJob", model)); } if (!string.IsNullOrWhiteSpace(model.Id)) { UpdateJob(model); return(RedirectToAction("GetJobs")); } ; //Save jobRequirement to FileStorage/JobRequirements Folder string fileStoragePath = _fileSaver.SaveFile(model.JobRequirement, Request.RequestContext); //map the JobFormViewModel to the Job Entity Job jobModel = Mapper.Map <JobFormViewModel, Job>(model); jobModel.AcceptanceMailMessage = jobModel.AcceptanceMailMessage.Trim(); jobModel.RejectionMailMessage = jobModel.RejectionMailMessage.Trim(); jobModel.JobRequirementPath = fileStoragePath; jobModel.DatePublished = DateTime.Now; _jobRepo.CreateItem(jobModel); return(RedirectToAction("GetJobs")); }
public ActionResult Add(RimViewModel rim, IEnumerable <HttpPostedFileBase> files) { if (!ModelState.IsValid) { return(View(rim)); } var userId = this.User.Identity.GetUserId(); var picturesPaths = new List <string>(); var counter = 0; foreach (var file in files) { if (counter++ > 3) { break; } var path = DateTime.Now.Ticks.ToString() + file.FileName; picturesPaths.Add("/Content/Gallery/" + path); fileSaver.SaveFile("/Content/Gallery/" + path, file.InputStream); } this.rimsService.AddNewTireAd(userId, AutoMapperConfig.Configuration.CreateMapper().Map <Rim>(rim), picturesPaths); this.statisticsHubCorresponder.UpdateAdsCount(this.statisticsService.TotalAds()); return(Redirect("/")); }
public async Task <ProgramPackageInfo> StorePackageAsync(Program program, Stream fileStream, string packageFileName, IFileSaver fileSaver) { var versions = await this.versionReader.GetVersionsFromStream(packageFileName, fileStream , program.PrimaryAssembly.GetFileName()).ConfigureAwait(false); fileStream = await Utilities.ZipTheStreamIfNeeded(packageFileName, fileStream).ConfigureAwait(false); ProgramPackageInfo pkg = await this.telimenaPortalContext.ProgramPackages.Where(x => x.ProgramId == program.Id && x.Version == versions.appVersion && x.SupportedToolkitVersion == versions.toolkitVersion).OrderByDescending(x => x.Id).FirstOrDefaultAsync().ConfigureAwait(false); if (pkg == null) { pkg = new ProgramPackageInfo(packageFileName, program.Id, versions.appVersion, fileStream.Length, versions.toolkitVersion); this.telimenaPortalContext.ProgramPackages.Add(pkg); } else { pkg.UploadedDate = DateTimeOffset.UtcNow; } await fileSaver.SaveFile(pkg, fileStream, this.containerName, program.TelemetryKey).ConfigureAwait(false); return(pkg); }
public async Task <TelimenaToolkitData> StorePackageAsync(bool isBeta, bool introducesBreakingChanges, Stream fileStream, IFileSaver fileSaver) { string actualVersion = await this.versionReader.GetFileVersion(fileStream, DefaultToolkitNames.TelimenaAssemblyName, true).ConfigureAwait(false); fileStream.Position = 0; fileStream = await Utilities.ZipTheStreamIfNeeded(DefaultToolkitNames.TelimenaAssemblyName, fileStream).ConfigureAwait(false); TelimenaToolkitData data = await this.TelimenaPortalContext.TelimenaToolkitData.Where(x => x.Version == actualVersion).Include(nameof(TelimenaToolkitData.TelimenaPackageInfo)).FirstOrDefaultAsync().ConfigureAwait(false); if (data == null) { data = new TelimenaToolkitData(actualVersion); this.TelimenaPortalContext.TelimenaToolkitData.Add(data); } if (data.TelimenaPackageInfo == null) { TelimenaPackageInfo pkg = new TelimenaPackageInfo(actualVersion, fileStream.Length); data.TelimenaPackageInfo = pkg; } data.TelimenaPackageInfo.UpdateContentAndMetadata(isBeta, introducesBreakingChanges, actualVersion, fileStream.Length); await fileSaver.SaveFile(data.TelimenaPackageInfo, fileStream, this.containerName).ConfigureAwait(false); return(data); }
public async Task <UpdaterPackageInfo> StorePackageAsync(Updater updater, string minimumRequiredToolkitVersion, Stream fileStream, IFileSaver fileSaver) { string actualVersion = await this.streamVersionReader.GetFileVersion(fileStream, updater.FileName, true).ConfigureAwait(false); fileStream.Position = 0; fileStream = await Utilities.ZipTheStreamIfNeeded(updater.FileName, fileStream).ConfigureAwait(false); if (string.IsNullOrEmpty(minimumRequiredToolkitVersion)) { minimumRequiredToolkitVersion = "0.0.0.0"; } UpdaterPackageInfo pkg = await this.TelimenaPortalContext.UpdaterPackages.Where(x => x.FileName == updater.FileName && x.Version == actualVersion && x.MinimumRequiredToolkitVersion == minimumRequiredToolkitVersion && x.Updater.InternalName == updater.InternalName).OrderByDescending(x => x.Id).FirstOrDefaultAsync().ConfigureAwait(false); if (pkg == null) { pkg = new UpdaterPackageInfo(actualVersion, updater.FileName, fileStream.Length, minimumRequiredToolkitVersion); this.TelimenaPortalContext.UpdaterPackages.Add(pkg); pkg.Updater = updater; } pkg.UpdateContentAndMetadata(fileStream.Length); await fileSaver.SaveFile(pkg, fileStream, this.containerName, updater.PublicId).ConfigureAwait(false); return(pkg); }
public void CreateNotice(NoticeCreateModel model, int currentUserId) { using (var unitOfWork = _unitOfWorkFactory.Create()) { var notice = Mapper.Map <Notice>(model); notice.UserId = currentUserId; notice.CreatedOn = DateTime.Now; _fileSaver.SaveFile(notice, model.Image); var currentNotice = unitOfWork.Notices.Create(notice); foreach (var img in model.ImgsCollection) { var galleryModel = new GalleryImage { Image = _dbFileSaver.GetImageBytes(img), NoticeId = currentUserId }; unitOfWork.GalleryImages.Create(galleryModel); } unitOfWork.Notices.Create(notice); } }
public async Task <ProgramUpdatePackageInfo> StorePackageAsync(Program program, string packageName, Stream fileStream, string supportedToolkitVersion, bool isBeta, string releaseNotes, IFileSaver fileSaver) { var versions = await this.streamVersionReader.GetVersionsFromStream(packageName, fileStream , program.PrimaryAssembly.GetFileName()).ConfigureAwait(false); fileStream = await Utilities.ZipTheStreamIfNeeded(packageName, fileStream).ConfigureAwait(false); if (versions.toolkitVersion != null) { supportedToolkitVersion = versions.toolkitVersion; } ObjectValidator.Validate(() => Version.TryParse(supportedToolkitVersion, out Version _) , new InvalidOperationException($"[{supportedToolkitVersion}] is not a valid version string")); ObjectValidator.Validate(() => this.TelimenaPortalContext.ToolkitPackages.Any(x => x.Version == supportedToolkitVersion) , new ArgumentException($"There is no toolkit package with version [{supportedToolkitVersion}]")); ProgramUpdatePackageInfo pkg = await this.TelimenaPortalContext.UpdatePackages.Where(x => x.ProgramId == program.Id && x.Version == versions.appVersion #pragma warning disable 618 && x.SupportedToolkitVersion == supportedToolkitVersion).OrderByDescending(x => x.Id).FirstOrDefaultAsync().ConfigureAwait(false); #pragma warning restore 618 if (pkg == null) { pkg = new ProgramUpdatePackageInfo(packageName, program.Id, versions.appVersion, fileStream.Length, supportedToolkitVersion); this.TelimenaPortalContext.UpdatePackages.Add(pkg); } pkg.UpdateContentAndMetadata(isBeta, releaseNotes); await fileSaver.SaveFile(pkg, fileStream, this.containerName).ConfigureAwait(false); return(pkg); }
protected List <string> SaveFiles(HttpFileCollectionBase Files) { List <string> fileNames = _fileSaver.SaveFile(Files); return(fileNames); }
/// <summary> /// Writes ChangeLog, Version and Change files using given instance of <see cref="IFileSaver"/> /// </summary> /// <param name="changeLog">ChangeLog to serialize.</param> /// <param name="saver">Service to save json strings to file paths.</param> /// <returns>True if was successful, false otherwise.</returns> public async Task <bool> Serialize(ChangeLog changeLog, IFileSaver saver) { if (changeLog == null) { return(false); } try { changeLog.Validate(); } catch (ChangeLogValidationException) { await saver.CancelPublish(); throw; } if (!(await saver.SaveFile(Path.Combine("temp", "changelog.json"), changeLog.ToJson()))) { return(false); } foreach (VersionRef versionRef in changeLog.Versions) { Version version = await versionRef.GetVersion(false); version.Changes.RemoveAll(c => c == null); if (version == null) { continue; } try { version.Validate(); } catch (ChangeLogValidationException) { await saver.CancelPublish(); throw; } if (!(await saver.SaveFile(Path.Combine("temp", version.VersionName, "version.json"), version.ToJson()))) { return(false); } foreach (ChangeRef changeRef in version.Changes) { Change change = await changeRef.GetChange(false); if (change == null) { continue; } try { change.Validate(changeLog); } catch (ChangeLogValidationException) { await saver.CancelPublish(); throw; } if (!(await saver.SaveFile(Path.Combine("temp", version.VersionName, "changes", $"{change.Guid}.json"), change.ToJson()))) { return(false); } } } bool success = await saver.PublishFromTemp(); // Clear caches CachedChangeLog = null; CachedVersions = new List <Version>(); CachedChanges = new List <Change>(); return(success); }
private void View_SetNewAvatar(object sender, ManageAvatarEventArgs e) { usersService.ChangeAvatar(e.FileName, e.FileExtension, e.FilePath, e.UserId); fileSaver.SaveFile(e.FilePath + e.FileName, e.AllBytes); }