Exemple #1
0
        public async Task <PremiumFile> AddFileToLibrary(IFormFile file, PremiumFileType type, string orderId,
                                                         int?skinId = null)
        {
            if (file == null)
            {
                throw new ServerException("File does not exists");
            }

            string fileLibraryPath =
                $"premium/library/{httpContextReader.CurrentUserId}/{Enum.GetName(type)?.ToLower()}s";

            var uploadedFile = await filesManager.Upload(file, fileLibraryPath);

            var premiumFile = BaseFile.Create <PremiumFile>(uploadedFile.Path)
                              .SetOrderId(orderId)
                              .SetSkin(skinId)
                              .SetFileType(type)
                              .SetUserId(httpContextReader.CurrentUserId);

            if (await database.PremiumFileRepository.Insert(premiumFile, false))
            {
                return(premiumFile);
            }
            else
            {
                filesManager.Delete(uploadedFile.Path);
                throw new DatabaseException("Adding order file to database failed");
            }
        }
Exemple #2
0
        public void AddFile(string path)
        {
            var fileToAdd = BaseFile.Create <File>(path);

            Add(fileToAdd);
        }