Пример #1
0
        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);
        }
Пример #2
0
        public async Task <Contracts.Creation> AddCreation([FromUri] int userId, [FromBody] Contracts.Creation creation)
        {
            ValidateUserAsAuthenticated(userId);
            if (userId != creation.UserId)
            {
                ThrowHttpResponseException(HttpStatusCode.Unauthorized, "Cannot add creation for different user");
            }

            UserEntity author = await DbContext.UsersRepo.GetSingleOrDefaultAsync(userId);

            var authorString  = string.Format("{0} {1}, a.k.a {2}", author.FirstName, author.LastName, author.UserName);
            var fileData      = File.ReadAllBytes(creation.CreationPath);
            var rightCreation = new CreationRightsManager.Creation
            {
                Author         = authorString,
                Owner          = authorString,
                TimeOfCreation = DateTime.UtcNow,
                Data           = new MemoryStream(fileData)
            };

            creation.Author = creation.Owner = authorString;

            CreationCertificateData cert = _creationRightsManager.Register(rightCreation);

            creation.Footprint = cert.CreationFootprint;
            creation.Signature = cert.Signature;

            var entity = creation.ToEntity();

            entity.TimeOfCreation = cert.TimeOfCreation;
            var savedCreation = await DbContext.CreationsRepo.CreateAsync(entity);

            creation.CreationId = savedCreation.Id;

            return(creation);
        }