private async Task <StoredFileModelBussines <int> > PrepareModel(StoredFileModelApi <int> model, int userId, IFormFile file)
        {
            var mappedModel = AutoMapperConfig.Mapper.Map <StoredFileModelBussines <int> >(model);

            if (mappedModel.StoredFolderId == null)
            {
                mappedModel.RootFolderId = await this.GetRootFolderIdByUserIdAsync(userId);
            }
            ;

            mappedModel.Title = Path.GetFileNameWithoutExtension(file.FileName);

            mappedModel.HashedTitle = Crypto.Hash("".GerRandomString()) +
                                      Path.GetExtension(file.FileName);

            mappedModel.SizeInKbs = file.Length.BytesToKilobytes();

            mappedModel.Extention = Path.GetExtension(file.FileName);

            var rootPath = await this.GetRootFolderPathByUserIdAsync(userId);

            mappedModel.Path = rootPath + "/" + mappedModel.HashedTitle;

            return(mappedModel);
        }
        private async Task <StoredFileModelApi <int> > ProceseFiles(StoredFileModelApi <int> model, int userId)
        {
            var response = new StoredFileModelApi <int>();

            if (!await this._subscriptionCapacityService.IsFreeForDataPack(model.File.Length, userId))
            {
                return(response);
            }

            var mappedModel = await PrepareModel(model, userId, model.File);

            var fs = new FileStream(
                mappedModel.Path,
                FileMode.CreateNew
                );

            await model.File.CopyToAsync(fs);

            fs.Close();

            mappedModel.ThumbnailPath = this._thumbnailHelper
                                        .CreateThumbnail(model.File.ContentType, model.File.OpenReadStream());

            response = AutoMapperConfig.Mapper.Map <StoredFileModelApi <int> >(
                await this._storedFileRepository.CreateAsync(mappedModel)
                );

            return(response);
        }
        public async Task <StoredFileModelApi <int> > CreateAsync(StoredFileModelApi <int> model, int userId)
        {
            var response = await ProceseFiles(model, userId);

            await this._subscriptionCapacityService.IncreaseTakenSpace(response.SizeInKbs, userId);

            return(response);
        }
        public async Task <StoredFileModelApi <int> > UpdateAsync(int Id, StoredFileModelApi <int> model)
        {
            var mapped = AutoMapperConfig.Mapper.Map <StoredFileModelBussines <int> >(model);

            return(AutoMapperConfig.Mapper.Map <StoredFileModelApi <int> >(
                       await this._storedFileRepository.UpdateAsync(Id, mapped)
                       ));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Update([FromBody] StoredFileModelApi <int> file, int Id)
        {
            var res = await this._storedFileService.UpdateAsync(Id, file);

            return(Ok(new ResponseModel <StoredFileModelApi <int> >(res)));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([FromForm] StoredFileModelApi <int> file, [FromRoute] int userId)
        {
            var res = await this._storedFileService.CreateAsync(file, userId);

            return(Ok(new ResponseModel <StoredFileModelApi <int> >(res)));
        }
 public Task <StoredFileModelApi <int> > CreateAsync(StoredFileModelApi <int> model)
 {
     throw new NotImplementedException();
 }