public async Task <IActionResult> CreateApp(string storeId, CreateAppViewModel vm) { var store = GetCurrentStore(); vm.StoreId = store.Id; if (!Enum.TryParse(vm.SelectedAppType, out AppType appType)) { ModelState.AddModelError(nameof(vm.SelectedAppType), "Invalid App Type"); } if (!ModelState.IsValid) { return(View(vm)); } var appData = new AppData { StoreDataId = store.Id, Name = vm.AppName, AppType = appType.ToString() }; var defaultCurrency = await GetStoreDefaultCurrentIfEmpty(appData.StoreDataId, null); switch (appType) { case AppType.Crowdfund: var emptyCrowdfund = new CrowdfundSettings { TargetCurrency = defaultCurrency }; appData.SetSettings(emptyCrowdfund); break; case AppType.PointOfSale: var empty = new PointOfSaleSettings { Currency = defaultCurrency }; appData.SetSettings(empty); break; } await _appService.UpdateOrCreateApp(appData); TempData[WellKnownTempData.SuccessMessage] = "App successfully created"; CreatedAppId = appData.Id; switch (appType) { case AppType.PointOfSale: return(RedirectToAction(nameof(UpdatePointOfSale), new { appId = appData.Id })); case AppType.Crowdfund: return(RedirectToAction(nameof(UpdateCrowdfund), new { appId = appData.Id })); default: return(RedirectToAction(nameof(ListApps), new { storeId = appData.StoreDataId })); } }
public async Task <IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm) { if (!string.IsNullOrEmpty(vm.TargetCurrency) && _currencies.GetCurrencyData(vm.TargetCurrency, false) == null) { ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency"); } try { _AppService.Parse(vm.PerksTemplate, vm.TargetCurrency).ToString(); } catch { ModelState.AddModelError(nameof(vm.PerksTemplate), "Invalid template"); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && !vm.StartDate.HasValue) { ModelState.AddModelError(nameof(vm.StartDate), "A start date is needed when the goal resets every X amount of time."); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && vm.ResetEveryAmount <= 0) { ModelState.AddModelError(nameof(vm.ResetEveryAmount), "You must reset the goal at a minimum of 1 "); } if (vm.DisplayPerksRanking && !vm.SortPerksByPopularity) { ModelState.AddModelError(nameof(vm.DisplayPerksRanking), "You must sort by popularity in order to display ranking."); } var parsedSounds = vm.Sounds.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ).Select(s => s.Trim()).ToArray(); if (vm.SoundsEnabled && !parsedSounds.Any()) { ModelState.AddModelError(nameof(vm.Sounds), "You must have at least one sound if you enable sounds"); } var parsedAnimationColors = vm.AnimationColors.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ).Select(s => s.Trim()).ToArray(); if (vm.AnimationsEnabled && !parsedAnimationColors.Any()) { ModelState.AddModelError(nameof(vm.AnimationColors), "You must have at least one animation color if you enable animations"); } if (!ModelState.IsValid) { return(View(vm)); } var app = await GetOwnedApp(appId, AppType.Crowdfund); if (app == null) { return(NotFound()); } var newSettings = new CrowdfundSettings() { Title = vm.Title, Enabled = vm.Enabled, EnforceTargetAmount = vm.EnforceTargetAmount, StartDate = vm.StartDate?.ToUniversalTime(), TargetCurrency = vm.TargetCurrency, Description = vm.Description, EndDate = vm.EndDate?.ToUniversalTime(), TargetAmount = vm.TargetAmount, CustomCSSLink = vm.CustomCSSLink, MainImageUrl = vm.MainImageUrl, EmbeddedCSS = vm.EmbeddedCSS, NotificationUrl = vm.NotificationUrl, NotificationEmail = vm.NotificationEmail, Tagline = vm.Tagline, PerksTemplate = vm.PerksTemplate, DisqusEnabled = vm.DisqusEnabled, SoundsEnabled = vm.SoundsEnabled, DisqusShortname = vm.DisqusShortname, AnimationsEnabled = vm.AnimationsEnabled, ResetEveryAmount = vm.ResetEveryAmount, ResetEvery = Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery), DisplayPerksRanking = vm.DisplayPerksRanking, SortPerksByPopularity = vm.SortPerksByPopularity, Sounds = parsedSounds, AnimationColors = parsedAnimationColors }; app.TagAllInvoices = vm.UseAllStoreInvoices; app.SetSettings(newSettings); await UpdateAppSettings(app); _EventAggregator.Publish(new AppUpdated() { AppId = appId, StoreId = app.StoreDataId, Settings = newSettings }); StatusMessage = "App updated"; return(RedirectToAction(nameof(UpdateCrowdfund), new { appId })); }
public async Task <IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm) { if (!string.IsNullOrEmpty(vm.TargetCurrency) && _AppsHelper.GetCurrencyData(vm.TargetCurrency, false) == null) { ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency"); } try { _AppsHelper.Parse(vm.PerksTemplate, vm.TargetCurrency).ToString(); } catch { ModelState.AddModelError(nameof(vm.PerksTemplate), "Invalid template"); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && !vm.StartDate.HasValue) { ModelState.AddModelError(nameof(vm.StartDate), "A start date is needed when the goal resets every X amount of time."); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && vm.ResetEveryAmount <= 0) { ModelState.AddModelError(nameof(vm.ResetEveryAmount), "You must reset the goal at a minimum of 1 "); } if (vm.DisplayPerksRanking && !vm.SortPerksByPopularity) { ModelState.AddModelError(nameof(vm.DisplayPerksRanking), "You must sort by popularity in order to display ranking."); } if (!ModelState.IsValid) { return(View(vm)); } var app = await GetOwnedApp(appId, AppType.Crowdfund); if (app == null) { return(NotFound()); } var newSettings = new CrowdfundSettings() { Title = vm.Title, Enabled = vm.Enabled, EnforceTargetAmount = vm.EnforceTargetAmount, StartDate = vm.StartDate, TargetCurrency = vm.TargetCurrency, Description = _AppsHelper.Sanitize(vm.Description), EndDate = vm.EndDate, TargetAmount = vm.TargetAmount, CustomCSSLink = vm.CustomCSSLink, MainImageUrl = vm.MainImageUrl, EmbeddedCSS = vm.EmbeddedCSS, NotificationUrl = vm.NotificationUrl, Tagline = vm.Tagline, PerksTemplate = vm.PerksTemplate, DisqusEnabled = vm.DisqusEnabled, SoundsEnabled = vm.SoundsEnabled, DisqusShortname = vm.DisqusShortname, AnimationsEnabled = vm.AnimationsEnabled, ResetEveryAmount = vm.ResetEveryAmount, ResetEvery = Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery), UseInvoiceAmount = vm.UseInvoiceAmount, UseAllStoreInvoices = vm.UseAllStoreInvoices, DisplayPerksRanking = vm.DisplayPerksRanking, SortPerksByPopularity = vm.SortPerksByPopularity }; app.SetSettings(newSettings); await UpdateAppSettings(app); _EventAggregator.Publish(new CrowdfundAppUpdated() { AppId = appId, StoreId = app.StoreDataId, Settings = newSettings }); StatusMessage = "App updated"; return(RedirectToAction(nameof(UpdateCrowdfund), new { appId })); }
public async Task <IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm, string command) { var app = GetCurrentApp(); if (app == null) { return(NotFound()); } vm.TargetCurrency = await GetStoreDefaultCurrentIfEmpty(app.StoreDataId, vm.TargetCurrency); if (_currencies.GetCurrencyData(vm.TargetCurrency, false) == null) { ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency"); } try { vm.PerksTemplate = _appService.SerializeTemplate(_appService.Parse(vm.PerksTemplate, vm.TargetCurrency)); } catch { ModelState.AddModelError(nameof(vm.PerksTemplate), "Invalid template"); } if (vm.TargetAmount is decimal v && v == 0.0m) { vm.TargetAmount = null; } if (!vm.IsRecurring) { vm.ResetEvery = nameof(CrowdfundResetEvery.Never); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && !vm.StartDate.HasValue) { ModelState.AddModelError(nameof(vm.StartDate), "A start date is needed when the goal resets every X amount of time."); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && vm.ResetEveryAmount <= 0) { ModelState.AddModelError(nameof(vm.ResetEveryAmount), "You must reset the goal at a minimum of 1 "); } if (vm.DisplayPerksRanking) { vm.SortPerksByPopularity = true; } var parsedSounds = vm.Sounds?.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ).Select(s => s.Trim()).ToArray(); if (vm.SoundsEnabled && (parsedSounds == null || !parsedSounds.Any())) { vm.SoundsEnabled = false; parsedSounds = new CrowdfundSettings().Sounds; } var parsedAnimationColors = vm.AnimationColors?.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ).Select(s => s.Trim()).ToArray(); if (vm.AnimationsEnabled && (parsedAnimationColors == null || !parsedAnimationColors.Any())) { vm.AnimationsEnabled = false; parsedAnimationColors = new CrowdfundSettings().AnimationColors; } if (!ModelState.IsValid) { return(View(vm)); } app.Name = vm.AppName; var newSettings = new CrowdfundSettings { Title = vm.Title, Enabled = vm.Enabled, EnforceTargetAmount = vm.EnforceTargetAmount, StartDate = vm.StartDate?.ToUniversalTime(), TargetCurrency = vm.TargetCurrency, Description = vm.Description, EndDate = vm.EndDate?.ToUniversalTime(), TargetAmount = vm.TargetAmount, CustomCSSLink = vm.CustomCSSLink, MainImageUrl = vm.MainImageUrl, EmbeddedCSS = vm.EmbeddedCSS, NotificationUrl = vm.NotificationUrl, Tagline = vm.Tagline, PerksTemplate = vm.PerksTemplate, DisqusEnabled = vm.DisqusEnabled, SoundsEnabled = vm.SoundsEnabled, DisqusShortname = vm.DisqusShortname, AnimationsEnabled = vm.AnimationsEnabled, ResetEveryAmount = vm.ResetEveryAmount, ResetEvery = Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery), DisplayPerksValue = vm.DisplayPerksValue, DisplayPerksRanking = vm.DisplayPerksRanking, SortPerksByPopularity = vm.SortPerksByPopularity, Sounds = parsedSounds, AnimationColors = parsedAnimationColors }; app.TagAllInvoices = vm.UseAllStoreInvoices; app.SetSettings(newSettings); await _appService.UpdateOrCreateApp(app); _eventAggregator.Publish(new AppUpdated() { AppId = appId, StoreId = app.StoreDataId, Settings = newSettings }); TempData[WellKnownTempData.SuccessMessage] = "App updated"; return(RedirectToAction(nameof(UpdateCrowdfund), new { appId })); }
public async Task <IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm) { if (!string.IsNullOrEmpty(vm.TargetCurrency) && _currencies.GetCurrencyData(vm.TargetCurrency, false) == null) { ModelState.AddModelError(nameof(vm.TargetCurrency), "Moneda invalida"); } try { _AppService.Parse(vm.PerksTemplate, vm.TargetCurrency).ToString(); } catch { ModelState.AddModelError(nameof(vm.PerksTemplate), "Plantilla inválida"); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && !vm.StartDate.HasValue) { ModelState.AddModelError(nameof(vm.StartDate), "Se necesita una fecha de inicio cuando el objetivo se restablece cada X cantidad de tiempo."); } if (Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery) != CrowdfundResetEvery.Never && vm.ResetEveryAmount <= 0) { ModelState.AddModelError(nameof(vm.ResetEveryAmount), "Debes restablecer el objetivo en un mínimo de 1. "); } if (vm.DisplayPerksRanking && !vm.SortPerksByPopularity) { ModelState.AddModelError(nameof(vm.DisplayPerksRanking), "Debes ordenar por popularidad para poder mostrar el ranking."); } var parsedSounds = vm.Sounds.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ).Select(s => s.Trim()).ToArray(); if (vm.SoundsEnabled && !parsedSounds.Any()) { ModelState.AddModelError(nameof(vm.Sounds), "Debes tener al menos un sonido si habilitas los sonidos"); } var parsedAnimationColors = vm.AnimationColors.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ).Select(s => s.Trim()).ToArray(); if (vm.AnimationsEnabled && !parsedAnimationColors.Any()) { ModelState.AddModelError(nameof(vm.AnimationColors), "Debe tener al menos un color de animación si habilita las animaciones"); } if (!ModelState.IsValid) { return(View(vm)); } var app = await GetOwnedApp(appId, AppType.Crowdfund); if (app == null) { return(NotFound()); } var newSettings = new CrowdfundSettings() { Title = vm.Title, Enabled = vm.Enabled, EnforceTargetAmount = vm.EnforceTargetAmount, StartDate = vm.StartDate?.ToUniversalTime(), TargetCurrency = vm.TargetCurrency, Description = _htmlSanitizer.Sanitize(vm.Description), EndDate = vm.EndDate?.ToUniversalTime(), TargetAmount = vm.TargetAmount, CustomCSSLink = vm.CustomCSSLink, MainImageUrl = vm.MainImageUrl, EmbeddedCSS = vm.EmbeddedCSS, NotificationUrl = vm.NotificationUrl, NotificationEmail = vm.NotificationEmail, Tagline = vm.Tagline, PerksTemplate = vm.PerksTemplate, DisqusEnabled = vm.DisqusEnabled, SoundsEnabled = vm.SoundsEnabled, DisqusShortname = vm.DisqusShortname, AnimationsEnabled = vm.AnimationsEnabled, ResetEveryAmount = vm.ResetEveryAmount, ResetEvery = Enum.Parse <CrowdfundResetEvery>(vm.ResetEvery), DisplayPerksRanking = vm.DisplayPerksRanking, SortPerksByPopularity = vm.SortPerksByPopularity, Sounds = parsedSounds, AnimationColors = parsedAnimationColors }; app.TagAllInvoices = vm.UseAllStoreInvoices; app.SetSettings(newSettings); await UpdateAppSettings(app); _EventAggregator.Publish(new AppUpdated() { AppId = appId, StoreId = app.StoreDataId, Settings = newSettings }); StatusMessage = "Aplicación actualizada"; return(RedirectToAction(nameof(UpdateCrowdfund), new { appId })); }