public ActionResult SubmitForm(ContactViewModel model)
        {
            bool success = false;

            if (ModelState.IsValid)
            {
                success = _smtpService.SendEmail(model);
            }

            var contactPage = UmbracoContext.Content.GetById(false, model.ContactFormId);

            var successMessage = contactPage.Value <IHtmlString>("successMessage");
            var errorMessage   = contactPage.Value <IHtmlString>("errorMessage");

            return(PartialView("~/Views/Partials/Contact/result.cshtml", success ? successMessage : errorMessage));
        }
Beispiel #2
0
        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            try
            {
                var template = $"~/Views/Partials/{TemplateName}";

                var emailBody = File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(template))
                                .Replace("[[SUBJECT]]", Subject)
                                .Replace("[[HEADING]]", Heading)
                                .Replace("[[BODY]]", Message);

                _smtpService.SendEmail(emailBody, ToEmail, FromEmail, FromName, Subject, ReplyTo, Bcc, Cc);
                return(WorkflowExecutionStatus.Completed);
            }
            catch (Exception ex)
            {
                _logger.Error(typeof(CustomEmailWorkflow), ex);
                return(WorkflowExecutionStatus.Failed);
            }
        }
Beispiel #3
0
        public async Task <UserResponseDto> SaveUser(UserRequestDto userRequest)
        {
            var password       = _passwordGeneratorService.Generate(8);
            var hashedPassword = _hashingService.HashPassword(password);
            var user           = _mapper.Map <User>((hashedPassword, userRequest));

            var savedUser = await _userRepository.SaveUser(user);

            var userResponse = _mapper.Map <UserResponseDto>(savedUser);

            try
            {
                _smtpService.SendEmail(password, userResponse);
            }
            catch
            {
                await _userRepository.DeleteUser(userResponse.Id);

                throw;
            }

            return(userResponse);
        }
Beispiel #4
0
        public void Run()
        {
            var disposable = Observable.Defer(() =>
            {
                AppLogger.Information("Checking for new data...");

                return(_csvService
                       .GetCollectionFromFile <Person, CsvPersonMapper>(@"database.csv",
                                                                        _schedulerConfig.Value.StartingPoint)
                       .Buffer(_schedulerConfig.Value.PackageSize)
                       .Select(people =>
                {
                    var timer = Observable.Timer(TimeSpan.FromSeconds(_schedulerConfig.Value.TimeLimit))
                                .DoOnComplete(() => { AppLogger.Information($"Time limit have passed."); });

                    var sending = people.Select(person => _smtpService.SendEmail(person))
                                  .Concat()
                                  .DoOnNext(_ => { _schedulerConfig.Update(config => { config.StartingPoint += 1; }); })
                                  .Buffer(people.Count)
                                  .DoOnComplete(() => { AppLogger.Information($"Package sent."); });

                    return timer.Zip(sending, (time, result) => new OperationResult.Success())
                    .DoOnComplete(() =>
                    {
                        AppLogger.Information(
                            $"{_schedulerConfig.Value.PackageSize} mails sent in max of {_schedulerConfig.Value.TimeLimit} seconds.");
                    });
                })
                       .Concat());
            }).RepeatWhen(observable => observable.Delay(TimeSpan.FromSeconds(3)));

            using (disposable.Subscribe())
            {
                Console.Read();
            }
        }