//[ValidateModel] public async Task <Player> Create(NewPlayer newPlayer) { var player = new Player() { Id = Guid.NewGuid(), Name = newPlayer.Name, CreationTime = DateTime.UtcNow }; return(await _IRepo.Create(player)); }
public async Task <int> Upload(IFormFile file) { var fileModel = file.ToModel(); var id = await _fileRepository.Create(fileModel); return(id); }
public async Task <IActionResult> UpLoad() { try { var file = Request.Form.Files[0]; var fileupload = new Domain.FileManagement.File(); fileupload.SetContentType(file.ContentType); fileupload.SetFileName(file.FileName); using (var memorystream = new MemoryStream()) { await file.CopyToAsync(memorystream); fileupload.SetUploadedFile(memorystream.ToArray()); } fileupload.SetType(Domain.FileManagement.FileType.CV); var result = await _repo.Create(fileupload); return(Ok(result.Id.ToString())); } catch (Exception e) { return(BadRequest(e.Message)); } }
public bool TryCreateAndSetPcBase(String path) { if (_userPasses == null) { return(false); } var newPcBase = new FileRepository(_userPasses.BasePassword); var connectResult = newPcBase.Create(path); if (!newPcBase.Create(path)) { return(false); } return(TrySetPcBase(path)); }
public async Task Create_FilePathIsNull_ThrowsArgumentNullException() { var sut = new FileRepository(_requestFactory); await Assert.ThrowsAsync <ArgumentNullException>( () => sut.Create(0, null, "branchName", "content", "commitMessage")); }
public async Task Create_ValidParameters_SetsCorrectResourceAndMethod() { var sut = new FileRepository(_requestFactory); await sut.Create(0, "filePath", "branchName", "content", "commitMessage"); _requestFactory.Received().Create("projects/{projectId}/repository/files", Method.Post); }
public int CreateFile(FileModel fileModel) { int id = FileRepository.Create(fileModel); CacheRepository.Add(fileModel, $"{FileCache}-{fileModel.Id}"); UnitOfWork.Save(); return(id); }
public async Task Create_EncodingIsSet_AddsEncodingParameter() { const string expected = "encoding"; var sut = new FileRepository(_requestFactory); await sut.Create(0, "filePath", "branchName", "content", "commitMessage", expected); _request.Received().AddParameterIfNotNull("encoding", expected); }
public async Task Create_ValidParameters_AddsProjectIdUrlSegment() { const uint expected = 0; var sut = new FileRepository(_requestFactory); await sut.Create(expected, "filePath", "branchName", "content", "commitMessage"); _request.Received().AddUrlSegment("projectId", expected); }
public async Task Create_ValidParameters_AddsContentParameter() { const string expected = "content"; var sut = new FileRepository(_requestFactory); await sut.Create(0, "filePath", "branchName", expected, "commitMessage"); _request.Received().AddParameter("content", expected); }
/// <summary>Creates a new empty repository.</summary> /// <remarks>Creates a new empty repository.</remarks> /// <param name="bare"> /// true to create a bare repository; false to make a repository /// within its working directory /// </param> /// <returns>the newly created repository, opened for access</returns> /// <exception cref="System.IO.IOException">the repository could not be created in the temporary area /// </exception> private FileRepository CreateRepository(bool bare) { FilePath gitdir = CreateUniqueTestGitDir(bare); FileRepository db = new FileRepository(gitdir); NUnit.Framework.Assert.IsFalse(gitdir.Exists()); db.Create(); toClose.AddItem(db); return(db); }
/// <summary>Creates a new empty repository.</summary> /// <remarks>Creates a new empty repository.</remarks> /// <param name="bare"> /// true to create a bare repository; false to make a repository /// within its working directory /// </param> /// <returns>the newly created repository, opened for access</returns> /// <exception cref="System.IO.IOException">the repository could not be created in the temporary area /// </exception> private FileRepository CreateRepository(bool bare) { string uniqueId = Runtime.CurrentTimeMillis() + "_" + (testCount++); string gitdirName = "test" + uniqueId + (bare ? string.Empty : "/") + Constants.DOT_GIT; FilePath gitdir = new FilePath(trash, gitdirName).GetCanonicalFile(); FileRepository db = new FileRepository(gitdir); NUnit.Framework.Assert.IsFalse(gitdir.Exists()); db.Create(); toClose.AddItem(db); return(db); }
public async Task <ActionResult> UpdateAvatar(IFormFile file) { var avatar = file.ToModel(); var fileId = await _fileRepository.Create(avatar); var user = await _userManager.GetUserAsync(User); user.AvatarFileId = fileId; await _userRepository.Update(user); return(Ok()); }
public static void Init(string folderName) { if (GitBash.Exists) { GitBash.Run("init", folderName); } else { var gitFolder = Path.Combine(folderName, Constants.DOT_GIT); var repo = new FileRepository(gitFolder); repo.Create(); var dir = Directory.CreateDirectory(gitFolder); dir.Attributes = FileAttributes.Directory | FileAttributes.Hidden; } }
public void CreateCorrectlyAddedFile() { const long parentId = 1; const Syntax syntax = Syntax.JavaScript; const string name = "NewFileTest"; const string content = "NewFileTestContent"; const int expectedLength = fileCount + 1; var repo = new FileRepository(_context); repo.Create(parentId, syntax, name, content); var res = repo.GetAll(); Assert.Equal(expectedLength, res.Count()); }
/// <summary> /// Sauvegarde le fichier. /// </summary> /// <param name="bytes">Bytes du fichiers.</param> /// <param name="fileName">Nom du fichier.</param> /// <returns>Entite fichier.</returns> public FileModel SaveFile(byte[] bytes, string fileName) { FileModel fileModel = new FileModel { FileName = fileName }; _fileRepository.Create(fileModel); File.WriteAllBytes($@"/app/ged/{fileModel.Id}{Path.GetExtension(fileName)}", bytes); fileModel.Key = $@"{fileModel.Id}{Path.GetExtension(fileName)}"; fileModel.Url = $@"/app/ged/{fileModel.Key}"; _fileRepository.Update(fileModel); return(fileModel); }
public async Task <ActionResult> DoneChallenge(int challengeId, IFormFile proofFile) { var userId = _userManager.GetUserId(User); var fileModel = proofFile.ToModel(); var fileModelId = await _fileRepository.Create(fileModel); var userChallenge = _userChallengeRepository .FirstOrDefault(uc => uc.UserId == userId && uc.ChallengeId == challengeId); userChallenge.Status = ChallengeStatus.Done; userChallenge.ProofFileId = fileModelId; userChallenge.DoneDateTime = DateTime.Now; await _userChallengeRepository.Update(userChallenge); return(Ok()); }
public long Add(ServiceAction action) { Debug.Assert(action.Type.NeedMakeFile); //Возраждение удаленного дела File file = FileRepository.GetByActionId(action.Id); if (file != null && file.IsDeleted) { file.IsDeleted = false; FileRepository.Update(file); return(file.Id); } //Создание нового дела var status = FileStageService.GetStatusForStage(FileStages.NewFile); if (status == null) { throw new DomainException(string.Format("Не определен статус для новых дел")); } file = new File { Caption = action.Customer, Date = action.Date, Expert = action.User, Ogv = action.Service.Organization, Action = action, CurrentStatus = status }; //операторные скобки UnitOfWork.BeginTransaction() and UnitOfWork.Commit() //не используем, поскольку предполагается использование этого метода //в уже созданнных FileRepository.Create(file); FileStatusService.SetStatus(file.Id, status.Id, DateTime.Now, string.Empty); return(file.Id); }
public IHttpActionResult PostFile(FileViewModel fileViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // if ParentId is not a folder if (fileViewModel.ParentId != null && !FileRepository.FolderExists(fileViewModel.ParentId.Value)) { return(BadRequest(ModelState)); } var fileEntity = fileViewModel.ToFileEntity(); fileEntity.SeqNum = fileViewModel.GetNextSeqNumber(FileRepository, fileEntity); fileEntity.Type = EntityType.File; FileRepository.Create(fileEntity); return(CreatedAtRoute("DefaultApi", new { id = fileViewModel.Id }, fileEntity.ToFileViewModel())); }
/// <summary> /// Sauvegarde le fichier. /// </summary> /// <param name="bytes">Bytes du fichiers.</param> /// <param name="fileName">Nom du fichier.</param> /// <returns>Entite fichier.</returns> public FileModel SaveFile(byte[] bytes, string fileName) { FileModel fileModel = new FileModel { FileName = fileName, Key = $@"prod/--ID--{Path.GetExtension(fileName)}" }; _fileRepository.Create(fileModel); fileModel.Key = $@"prod/{fileModel.Id}{Path.GetExtension(fileName)}"; PutObjectRequest request = new PutObjectRequest() { InputStream = new MemoryStream(bytes), BucketName = _bucketName, Key = fileModel.Key }; PutObjectResponse response = _amazonS3Client.PutObjectAsync(request).Result; fileModel.Url = $@"https://{_bucketName}.s3.eu-west-3.amazonaws.com/{fileModel.Key}"; _fileRepository.Update(fileModel); return(fileModel); }
public async Task <string> CreateFromBase64( FilesTypes fileType, Guid entityId, Guid creatorId, SrbacRoles creatorRole, string contentBase64 = null, string fileName = null ) { try { if (string.IsNullOrWhiteSpace(contentBase64)) { return(null); } if (string.IsNullOrWhiteSpace(fileName)) { fileName = Guid.NewGuid().ToString(); } var name = Path.GetFileNameWithoutExtension(fileName); var extension = GetFileExtension(contentBase64); using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); var fileModel = await _fileRepository.Create(new FileModel { EntityType = fileType, Extension = extension, Name = name, EntityId = entityId, CreatorId = creatorId }); var path = Path.Combine( _fileStorageConfiguration.AbsolutePath, fileType.ToString(), entityId.ToString() ); Directory.CreateDirectory(path); var filePath = Path.Combine(path, $"{fileModel.Id.ToString()}.{extension}"); await File.WriteAllBytesAsync(filePath, Convert.FromBase64String(contentBase64)); await _auditService.Success( AuditOperationTypes.CreateFile, "", fileModel, fileModel.Id, creatorId, creatorRole ); scope.Complete(); return(await GetFileUrl(entityId, fileType)); } catch (Exception e) { await _auditService.Error( AuditOperationTypes.CreateFile, e.Message, new AuditErrorObjectContainer { Model = new FileModel { EntityType = fileType, Name = fileName, EntityId = entityId }, Error = e }, null, creatorId, creatorRole ); throw; } }