Exemplo n.º 1
0
        public IActionResult EmailReport([FromBody] EmailReportViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var request = new EmailReportRequest {
                ClubId         = club.Guid,
                EventId        = model.EventId,
                EmailAddresses = model.EmailAddress
            };

            if (model.SendMeACopy.HasValue && model.SendMeACopy.Value)
            {
                var user = userManager.GetUserAsync(User).Result;
                request.EmailAddresses.Add(user.Email);
            }

            var response = eventService.EmailEventReport(request);

            return(response.RequestIsFulfilled ? Ok() : BadRequest(response.Errors) as IActionResult);
        }
Exemplo n.º 2
0
        public Response EmailEventReport(EmailReportRequest request)
        {
            var validationResult = emailReportRequestValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(Response.CreateResponse(validationResult.Messages));
            }


            var club = clubQuery.GetClub(request.ClubId);

            if (club == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist")));
            }

            var @event = eventQuery.GetEvent(request.EventId);

            if (@event == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified event does not exist")));
            }
            else if (@event.ClubId != request.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified event does not belong to this club")));
            }

            var report      = eventQuery.GetEventReport(request.EventId);
            var matchReport = DeserializeReport <MatchReport>(report.Report);

            if (matchReport == null)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified report does not have a body")));
            }

            var result = matchReport.GoalsScored > matchReport.GoalsConceeded ? "WON " : (matchReport.GoalsScored < matchReport.GoalsConceeded ? "LOST " : "TIED at");

            result = $"{result} {matchReport.GoalsScored} - {matchReport.GoalsConceeded}";
            var emailBody = $@"<html>
				<body>
					<h1>Match Report {@event.Title}</h1>
					<div>{@event.EventType.GetDescription()}<div>
                    <div>{@event.StartDate.ToString("ddd dd-MMM-yyyy h:mm tt")}</div>
                    <div>{@event.Location}</div>
                    <h3>{string.Join(", ", @event.Squads.Select(s => s.Name))} vs {matchReport.Opponent}</h3>
					<div><strong>Score:</strong> {result}</div>
					<div><strong>Scorers:</strong> {matchReport.Scorers}</div>
					<div><strong>Coach's Remarks:</strong>  {matchReport.CoachsRemarks}</div>
				</body>
			</html>"            ;

            var emailRequest = new EmailRequest {
                Subject = $"Match Report {@event.Title}",
                Body    = emailBody
            };

            foreach (var email in request.EmailAddresses)
            {
                emailRequest.BCC.Add(email);
            }

            emailSender.EmailAsync(emailRequest);
            return(Response.CreateSuccessResponse());
        }