Пример #1
0
 public async Task <VendorCodeType> UpdateTypeAsync(VendorCodeType vendorCodeType)
 {
     VerifyManagementPermission();
     vendorCodeType.SiteId = GetCurrentSiteId();
     return(await _vendorCodeTypeRepository.UpdateSaveAsync(GetClaimId(ClaimType.UserId),
                                                            vendorCodeType));
 }
Пример #2
0
 private async Task SendVendorDonationMailAsync(int userId,
                                                int?siteId,
                                                VendorCodeType codeType)
 {
     await _mailService.SendSystemMailAsync(new Mail
     {
         ToUserId             = userId,
         CanParticipantDelete = false,
         Subject = codeType.DonationSubject,
         Body    = codeType.DonationMail
     }, siteId);
 }
Пример #3
0
        private async Task SendVendorCodeMailAsync(int userId,
                                                   int?siteId,
                                                   VendorCodeType codeType,
                                                   string assignedCode)
        {
            string body = null;

            if (!codeType.Mail.Contains(TemplateToken.VendorCodeToken))
            {
                // the token isn't in the message, just append the code to the end
                body = $"{codeType.Mail} {assignedCode}";
            }
            else
            {
                if (string.IsNullOrEmpty(codeType.Url))
                {
                    // we have a token but no url, replace the token with the code
                    body = codeType.Mail.Replace(TemplateToken.VendorCodeToken, assignedCode);
                }
                else
                {
                    string url = null;
                    // see if the url has the token in it, if so swap in the code
                    if (!codeType.Url.Contains(TemplateToken.VendorCodeToken))
                    {
                        url = codeType.Url;
                    }
                    else
                    {
                        url = codeType.Url.Replace(TemplateToken.VendorCodeToken, assignedCode);
                    }
                    // token and url - make token clickable to go to url
                    body = codeType.Mail.Replace(TemplateToken.VendorCodeToken,
                                                 $"<a href=\"{url}\" _target=\"blank\">{assignedCode}</a>");
                    if (body.Contains(TemplateToken.VendorLinkToken))
                    {
                        body = body.Replace(TemplateToken.VendorLinkToken, url);
                    }
                }
            }

            await _mailService.SendSystemMailAsync(new Mail
            {
                ToUserId             = userId,
                CanParticipantDelete = false,
                Subject = codeType.MailSubject,
                Body    = body
            }, siteId);
        }
        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)));
        }