public ArchiveModel(Guid?archiveId, String contentType, ArchiveStreamBindingModel bindingModel) { this.ArchiveId = archiveId?.ToString(); this.ArchiveName = bindingModel?.Archive?.FileName; this.UserToken = bindingModel?.UserToken; this.ContentType = contentType; }
/// <summary> /// InsertArchiveFormData. /// </summary> /// <param name="bindingModel"></param> /// <returns></returns> public async Task <Boolean> InsertArchiveFormData(ArchiveStreamBindingModel bindingModel) { Boolean result = false; ArchiveModel model = null; Guid archiveId = Guid.NewGuid(); String extension = MimeTypeMap.GetExtension(bindingModel?.Archive?.ContentType); String archivePath = String.Format(ConstantsConfiguration.PATH_IMAGES, archiveId, extension); FileStream archiveStream = new FileStream(archivePath, FileMode.Create, FileAccess.Write); try { bindingModel?.Archive?.OpenReadStream()?.CopyTo(archiveStream); archiveStream.Dispose(); if (!(File.ReadAllBytes(archivePath) is null)) { model = new ArchiveModel(archiveId, bindingModel?.Archive?.ContentType, bindingModel); result = await this._archiveRepository.InsertArchive(model); if (!result) { File.Delete(archivePath); } } } catch (Exception exception) { if (!(File.ReadAllBytes(archivePath) is null)) { File.Delete(archivePath); } throw exception; } return(result); }