public async Task <bool> AddCustomInterior(IFormFile interiorFile, int estateId) { if (interiorFile == null) { throw new ServerException("Interior file does not exists"); } var user = await userService.GetUserWithCharacters(httpContextReader.CurrentUserId) ?? throw new EntityNotFoundException("User not found"); var estate = await characterService.HasAnyCharacterEstate(user.Characters, estateId) ?? throw new NoPermissionsException("You are not owner of this estate"); using (var transaction = database.BeginTransaction().Transaction) { await tempDatabaseCleaner.ClearGameTempObjectsAndInteriors(); var order = new OrderBuilder() .SetOperation(PremiumOperation.Interior) .SetCost(PremiumConstants.AddCustomInteriorCost) .SetUser(httpContextReader.CurrentUserId) .SetEstate(estateId) .Build(); if (await orderService.CreateOrder(order) == null) { throw new DatabaseException("Inserting order failed"); } var premiumFile = await premiumUserLibraryManager.AddFileToLibrary(interiorFile, PremiumFileType.Interior, order.Id) ?? throw new DatabaseException("Adding interior file to library failed"); await filesManager.ReplaceInFile(premiumFile.Path, "edf:", string.Empty); var(gameTempObjects, gameTempInterior) = customInteriorManager.InitGameTempObjectsAndInteriors(estate, premiumFile); await customInteriorManager.ExecuteAddCustomInterior(premiumFile, gameTempObjects, gameTempInterior); if (await purchaseService.CreatePurchase(PremiumConstants.AddCustomInterior, httpContextReader.CurrentUserId, PremiumConstants.AddCustomInteriorCost) == null) { throw new PremiumOperationException( "Adding custom skin failed"); } transaction.Complete(); } return(true); }
public async Task <bool> ChangeUploadedInteriorFile(IFormFile newFile, string oldFileId) { if (newFile == null) { throw new ServerException("File does not exist"); } var oldPremiumFile = await database.PremiumFileRepository.GetFileWithOrderAndEstate(oldFileId) ?? throw new EntityNotFoundException("Premium file not found"); ValidateOldFileExpiration(oldPremiumFile); using (var transaction = database.BeginTransaction().Transaction) { await tempDatabaseCleaner.ClearGameTempObjectsAndInteriors(); await DeleteOldPremiumFileAndUpdateOrder(oldPremiumFile); var newPremiumFile = await AddFileToLibrary(newFile, (PremiumFileType)oldPremiumFile.FileType, oldPremiumFile.OrderId) ?? throw new DatabaseException("Adding new interior file to premium library failed"); await filesManager.ReplaceInFile(newPremiumFile.Path, "edf:", string.Empty); var(gameTempObjects, gameTempInterior) = customInteriorManager.InitGameTempObjectsAndInteriors(oldPremiumFile.Estate, newPremiumFile); await customInteriorManager.ExecuteAddCustomInterior(newPremiumFile, gameTempObjects, gameTempInterior); transaction.Complete(); } filesManager.Delete(oldPremiumFile.Path); return(true); }