public async Task <IActionResult> AddYourEvent(EventSubmission eventSubmission)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.SubmissionError = GetErrorsFromModelState(ModelState);
                return(View("Add-Your-Event", eventSubmission));
            }

            if (eventSubmission.IsRecurring)
            {
                Enum.TryParse(eventSubmission.Frequency, out EventFrequency frequency);
                if (frequency != EventFrequency.None)
                {
                    eventSubmission.Occurrences = _dateCalculator.GetEventOccurences(frequency, (DateTime)eventSubmission.EventDate, (DateTime)eventSubmission.EndDate);
                }
            }

            var successCode = await _emailBuilder.SendEmailAddNew(eventSubmission);

            if (successCode == HttpStatusCode.OK)
            {
                return(RedirectToAction("ThankYouMessage"));
            }

            ViewBag.SubmissionError = "There was a problem submitting the event, please try again.";

            return(View("Add-Your-Event", eventSubmission));
        }
示例#2
0
        public virtual Task <HttpStatusCode> SendEmailEditEvent(EventSubmission eventDetail, string updatedByEmail)
        {
            var messageSubject = $"Edit event {eventDetail.Title}";

            _logger.LogInformation("Sending event edit form email");

            var emailBody = new EventEdit
            {
                Title          = eventDetail.Title,
                EventDate      = eventDetail.EventDate.HasValue ? ((DateTime)eventDetail.EventDate).ToString("dddd dd MMMM yyyy") : "-",
                EndDate        = eventDetail.EndDate.HasValue ? ((DateTime)eventDetail.EndDate).ToString("dddd dd MMMM yyyy") : "-",
                StartTime      = eventDetail.StartTime.HasValue ? ((DateTime)eventDetail.StartTime).ToString("HH:mm") : "-",
                EndTime        = eventDetail.EndTime.HasValue ? ((DateTime)eventDetail.EndTime).ToString("HH:mm") : "-",
                Frequency      = !string.IsNullOrEmpty(eventDetail.Frequency) ? eventDetail.Frequency : "-",
                Fee            = !string.IsNullOrEmpty(eventDetail.Fee) ? eventDetail.Fee : "-",
                Location       = !string.IsNullOrEmpty(eventDetail.Location) ? eventDetail.Location : "-",
                SubmittedBy    = !string.IsNullOrEmpty(eventDetail.SubmittedBy) ? eventDetail.SubmittedBy : "-",
                Description    = !string.IsNullOrEmpty(eventDetail.Description) ? eventDetail.Description : "-",
                SubmitterEmail = !string.IsNullOrEmpty(eventDetail.SubmitterEmail) ? eventDetail.SubmitterEmail : "-",
                Categories     = eventDetail.CategoriesList,
                GroupName      = string.IsNullOrEmpty(eventDetail.GroupName) ? string.Empty : $"Group name: {eventDetail.GroupName}",
                Occurrences    = eventDetail.Occurrences == 0 ? string.Empty : $"(occurs {eventDetail.Occurrences} times)",
            };

            return(_emailClient.SendEmailToService(new EmailMessage(messageSubject, _emailClient.GenerateEmailBodyFromHtml(emailBody),
                                                                    _fromEmail,
                                                                    _configuration.GetEventSubmissionEmail(_businessId.ToString()).ToString(),
                                                                    eventDetail.SubmitterEmail,
                                                                    null)));
        }
        public async void ItShouldReturnFeaturedEventsFirst()
        {
            var eventSubmission = new EventSubmission {
                SubmitterEmail = "*****@*****.**", EventDate = new DateTime(2017, 9, 9)
            };
            await _eventEmailBuilder.SendEmailAddNew(eventSubmission);

            LogTesting.Assert(_logger, LogLevel.Information, "Sending event submission form email");
        }
示例#4
0
        public async Task <IActionResult> SubmitEvent([FromForm] EventSubmission submission)
        {
            var mailgunDomain = _configuration["Gmail:Address"];
            var mailgunApiKey = _configuration["Gmail:AppPassword"];

            var handler = new EventSubmissionHandler(mailgunDomain, mailgunApiKey);
            await handler.HandleAsync(submission);

            TempData["SubmitEvent"] = true;

            return(View("Index"));
        }
示例#5
0
        public virtual Task <HttpStatusCode> SendEmailAddNew(EventSubmission eventSubmission)
        {
            var messageSubject = $"[Event date] - {eventSubmission.EventDate.Value.ToString("d MMMM yyyy")}, [Event] - {eventSubmission.Title}";

            _logger.LogInformation("Sending event submission form email");

            var attachments = new List <IFormFile>();

            if (eventSubmission.Image != null)
            {
                attachments.Add(eventSubmission.Image);
            }
            if (eventSubmission.Attachment != null)
            {
                attachments.Add(eventSubmission.Attachment);
            }

            var imagePath      = FileHelper.GetFileNameFromPath(eventSubmission.Image);
            var attachmentPath = FileHelper.GetFileNameFromPath(eventSubmission.Attachment);

            var emailBody = new EventAdd
            {
                Title          = eventSubmission.Title,
                EventDate      = eventSubmission.EventDate.HasValue ? ((DateTime)eventSubmission.EventDate).ToString("dddd dd MMMM yyyy") : "-",
                EndDate        = eventSubmission.EndDate.HasValue ? ((DateTime)eventSubmission.EndDate).ToString("dddd dd MMMM yyyy") : "-",
                StartTime      = eventSubmission.StartTime.HasValue ? ((DateTime)eventSubmission.StartTime).ToString("HH:mm") : "-",
                EndTime        = eventSubmission.EndTime.HasValue ? ((DateTime)eventSubmission.EndTime).ToString("HH:mm") : "-",
                Frequency      = !string.IsNullOrEmpty(eventSubmission.Frequency) ? eventSubmission.Frequency : "-",
                Fee            = !string.IsNullOrEmpty(eventSubmission.Fee) ? eventSubmission.Fee : "-",
                Location       = !string.IsNullOrEmpty(eventSubmission.Location) ? eventSubmission.Location : "-",
                SubmittedBy    = !string.IsNullOrEmpty(eventSubmission.SubmittedBy) ? eventSubmission.SubmittedBy : "-",
                Description    = !string.IsNullOrEmpty(eventSubmission.Description) ? eventSubmission.Description : "-",
                ImagePath      = !string.IsNullOrEmpty(imagePath) ? imagePath : "-",
                AttachmentPath = !string.IsNullOrEmpty(attachmentPath) ? attachmentPath : "-",
                SubmitterEmail = !string.IsNullOrEmpty(eventSubmission.SubmitterEmail) ? eventSubmission.SubmitterEmail : "-",
                Categories     = eventSubmission.CategoriesList,
                GroupName      = string.IsNullOrEmpty(eventSubmission.GroupName) ? string.Empty : $"Group name: {eventSubmission.GroupName}",
                Occurrences    = eventSubmission.Occurrences == 0 ? string.Empty : $"(occurs {eventSubmission.Occurrences} times)",
            };

            return(_emailClient.SendEmailToService(new EmailMessage(messageSubject, _emailClient.GenerateEmailBodyFromHtml(emailBody),
                                                                    _fromEmail,
                                                                    _configuration.GetEventSubmissionEmail(_businessId.ToString()).ToString(),
                                                                    eventSubmission.SubmitterEmail,
                                                                    attachments)));
        }
        public IActionResult AddYourEvent()
        {
            var eventSubmission = new EventSubmission();

            return(View("Add-Your-Event", eventSubmission));
        }