public async Task <IActionResult> CreateVendorCodesAsync(int numberOfCodes) { var allCodes = await _vendorCodeService.GetTypeAllAsync(); var code = allCodes.FirstOrDefault(); if (code == null) { code = await _vendorCodeService.AddTypeAsync(new VendorCodeType { Description = "Free Book Code", DonationOptionSubject = "Choose whether to receive your free book or donate it to a child", DonationOptionMail = "If you'd like to redeem your free book code, please visit <a href=\"/Profile/\">your profile</a> and select the redeem option. If you're not interested in redeeming it, you can select the option to donate it to a child.", MailSubject = "Here's your Free Book Code!", Mail = $"Congratulations, you've earned a free book! Your free book code is: {TemplateToken.VendorCodeToken}!", DonationMessage = "Your free book has been donated.Thank you!!!", DonationSubject = "Thank you for donating your free book!", DonationMail = "Thanks so much for the donation of your book.", Url = "http://freebook/?Code={Code}" }); } var sw = new Stopwatch(); sw.Start(); var generatedCount = await _vendorCodeService.GenerateVendorCodesAsync(code.Id, numberOfCodes); sw.Stop(); AlertSuccess = $"Generated {generatedCount} codes in {sw.Elapsed.TotalSeconds} seconds of type: {code.Description}"; return(View("Index")); }
public async Task <IActionResult> CreateVendorCodesAsync(int numberOfCodes) { var allCodes = await _vendorCodeService.GetTypeAllAsync(); var code = allCodes.FirstOrDefault(); if (code == null) { code = await _vendorCodeService.AddTypeAsync(new VendorCodeType { Description = "Free Book Code", MailSubject = "Here's your Free Book Code!", Mail = "Congratulations, you've earned a free book! Your free book code is {Code}!", }); } var sw = new Stopwatch(); sw.Start(); var generatedCount = await _vendorCodeService.GenerateVendorCodesAsync(code.Id, numberOfCodes); sw.Stop(); AlertSuccess = $"Generated {generatedCount} codes in {sw.Elapsed.TotalSeconds} seconds of type: {code.Description}"; return(View("Index")); }
public async Task <IActionResult> CreateVendorCodes(int numberOfCodes) { var allCodes = await _vendorCodeService.GetTypeAllAsync(); var code = allCodes.FirstOrDefault(); if (code == null) { code = await _vendorCodeService.AddTypeAsync(new VendorCodeType { Description = "Free Book Code", OptionSubject = "Choose whether to receive your free book or donate it to a child", OptionMail = "If you'd like to redeem your free book code, please visit <a href=\"/Profile/\">your profile</a> and select the redeem option. If you're not interested in redeeming it, you can select the option to donate it to a child.", MailSubject = "Here's your Free Book Code!", Mail = $"Congratulations, you've earned a free book! Your free book code is: {TemplateToken.VendorCodeToken}!", DonationMessage = "Your free book has been donated.Thank you!!!", DonationSubject = "Thank you for donating your free book!", DonationMail = "Thanks so much for the donation of your book.", Url = "http://freebook/?Code={Code}" }); } var jobToken = await _jobService.CreateJobAsync(new Job { JobType = JobType.GenerateVendorCodes, SerializedParameters = JsonConvert.SerializeObject( new JobDetailsGenerateVendorCodes { NumberOfCodes = numberOfCodes, VendorCodeTypeId = code.Id, CodeLength = 15 }) }); return(View("Job", new ViewModel.MissionControl.Shared.JobViewModel { CancelUrl = Url.Action(nameof(Index)), JobToken = jobToken.ToString(), PingSeconds = 5, SuccessRedirectUrl = "", SuccessUrl = Url.Action(nameof(Index)), Title = "Generating vendor codes..." })); }
public async Task <IActionResult> UpdateConfiguration(VendorCodeType vendorCodeType) { if (vendorCodeType == null) { AlertDanger = "Could not create empty vendor code type."; return(RedirectToAction(nameof(Index))); } if (!ModelState.IsValid) { vendorCodeType.DirectEmailTemplates = await _emailManagementService .GetUserTemplatesAsync(); return(View("Configure", vendorCodeType)); } try { var existingVendorCodeType = await _vendorCodeService.GetTypeAllAsync(); if (existingVendorCodeType?.Count > 0) { vendorCodeType.Id = existingVendorCodeType.First().Id; await _vendorCodeService.UpdateTypeAsync(vendorCodeType); } else { await _vendorCodeService.AddTypeAsync(vendorCodeType); } } catch (GraFieldValidationException gex) { foreach (var validationError in gex.FieldValidationErrors) { foreach (var errorMessage in validationError) { ModelState.AddModelError(validationError.Key, errorMessage); } } return(View("Configure", vendorCodeType)); } return(RedirectToAction(nameof(Index))); }