public async Task <GroupCreation> AttachFile(int groupId, int userId, GroupCreation groupCreation) { GroupUserEntity userGroup = await DbContext.GroupsUsersRepo.GetByUserIdAndGroupId(userId, groupId); if (userGroup == null) { ThrowHttpResponseException(System.Net.HttpStatusCode.Unauthorized, "Access is denied."); } ValidateUserAsAuthenticated(userGroup.UserId); CreationEntity creation = await DbContext.CreationsRepo.GetSingleOrDefaultAsync(groupCreation.CreationId); if (creation == null) { ThrowHttpResponseException(System.Net.HttpStatusCode.NotFound, string.Format("Creation with id {0} not found.", groupCreation.CreationId)); } GroupCreationEntity groupCreationEntity = await DbContext.GroupCreationsRepo.CreateAsync( new GroupCreationEntity() { CreationId = creation.Id, GroupId = groupCreation.GroupId, }).ConfigureAwait(false); return(groupCreationEntity.ToContract()); }
public async Task <Contracts.Creation> ChangeOwner([FromUri] int userId, [FromUri] int creationId, [FromBody] int newOwnerId) { ValidateUserAsAuthenticated(userId); CreationEntity entity = await ValidateCreation(creationId, userId); UserEntity newOwner = await DbContext.UsersRepo.GetSingleOrDefaultAsync(newOwnerId); var newOwnerString = string.Format("{0} {1}, a.k.a {2}", newOwner.FirstName, newOwner.LastName, newOwner.UserName); Contracts.Creation contractFromEntity = entity.ToContract(); contractFromEntity.Owner = newOwnerString; var fileData = File.ReadAllBytes(entity.FilePath); var rightCreation = new CreationRightsManager.Creation { Author = contractFromEntity.Author, Owner = contractFromEntity.Owner, TimeOfCreation = entity.TimeOfCreation, Data = new MemoryStream(fileData) }; CreationCertificateData cert = _creationRightsManager.Register(rightCreation); contractFromEntity.Footprint = cert.CreationFootprint; contractFromEntity.Signature = cert.Signature; await DbContext.CreationsRepo.UpdateAsync(contractFromEntity.ToEntity()); return(contractFromEntity); }
public static Creation ToContract(this CreationEntity creation) { return(new Creation { CreationId = creation.Id, CreationName = creation.Name, CreationPath = creation.FilePath, UserId = creation.UserId, Author = creation.Author, Owner = creation.Owner, Footprint = creation.CreationFootprint, Signature = creation.Signiture }); }