예제 #1
0
        public async Task <Guid> AddDocument(Stream fileStream, string fileName)
        {
            if (fileStream == null)
            {
                throw new ArgumentNullException(nameof(fileStream));
            }

            var extension = Path.GetExtension(fileName);

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException($"{fileName} cannot be empty");
            }

            if (string.IsNullOrEmpty(extension))
            {
                throw new ArgumentException($"{extension} cannot be empty");
            }

            using (var unitOfWork = new DocumentUOW(_frissFileSystemContext, _frissDbContext))
            {
                var documentId = Guid.NewGuid();

                _documentRepository.Add(new Document()
                {
                    Id             = documentId,
                    CreatedDate    = DateTime.UtcNow,
                    LastAccessDate = null,
                    FileName       = fileName,
                    OwnerName      = "TODO",
                    Size           = fileStream.Length
                });

                _fileRepository.AddFile(documentId, extension, fileStream);

                await unitOfWork.SaveChanges();

                return(documentId);
            }
        }
예제 #2
0
        public Entity GetEntityFromPlatform()
        {
            var originalEntity = _userService.CurrentUser();

            if (originalEntity == null)
            {
                return(null);
            }

            var entity = _entitiesRepository.GetEntitiesByIds(new[] { originalEntity.id }).FirstOrDefault();

            if (entity != null)
            {
                entity.ImageUrl      = originalEntity.imageUrl;
                entity.Name          = originalEntity.name;
                entity.OriginalEmail = entity.OriginalEmail;
                entity.LastActivity  = SystemTime.Now();

                _entitiesRepository.Update(entity);

                return(entity);
            }

            entity = new Entity
            {
                Id            = ObjectId.GenerateNewId(),
                OriginalId    = originalEntity.id,
                Name          = originalEntity.name,
                ImageUrl      = originalEntity.imageUrl,
                OriginalEmail = originalEntity.email,
                LastActivity  = SystemTime.Now(),
                MemberSince   = SystemTime.Now()
            };

            _entitiesRepository.Add(entity);

            return(entity);
        }