예제 #1
0
파일: Email.cs 프로젝트: GSerjo/CodeProject
 public static Email From(EmailRequest request)
 {
     int randomValue = new Random().Next(1000);
     if (randomValue % 2 == 0)
     {
         return new HappyEmail(request);
     }
     return new QuickEmail(request);
 }
예제 #2
0
        /// <summary>
        /// <para>Performs the Listing Method:
        /// Send an email to the seller of a classified.
        /// </para><para>
        /// Serializes the given EmailRequest into xml.
        /// Creates a query string using the listingId provided .
        /// </para><para>
        /// All the parameters are required.
        /// </para>
        /// REQUIRES AUTHENTICATION.
        /// </summary>
        /// <param name="emailRequest">The object that will be serialized into xml and then sent in a POST message.</param>
        /// <param name="listingId">The id of the listing that youwant to email about.</param>
        /// <returns>XDocument.</returns>
        public XDocument EmailSellerOfClassified(EmailRequest emailRequest, string listingId)
        {
            if (_listing == null)
            {
                _listing = new ListingMethods(_connection);
            }

            return _listing.EmailSellerOfClassified(emailRequest, listingId);
        }
예제 #3
0
파일: Email.cs 프로젝트: GSerjo/CodeProject
 protected Email(EmailRequest request)
 {
     Recipient = request.Recipient;
 }
예제 #4
0
 private EmailRequest<MessageMetaData, PopeyeTemplateVariables> BuildEmailRequest()
 {
     var request = new EmailRequest<MessageMetaData, PopeyeTemplateVariables>
     {
         Body = new EmailRequestBody<MessageMetaData, PopeyeTemplateVariables>
         {
             From = new PopeyeEmail
             {
                 Email = "*****@*****.**",
                 Name = "dev test"
             },
             To = new[]
             {
                 new PopeyeEmail
                 {
                     Email = "*****@*****.**",
                     Name = "email to"
                 }
             },
             MetaData = new MessageMetaData
             {
                 Company = new Company
                 {
                     Uid = "123",
                     Name = "dev test company id"
                 },
                 Document = new Document { DocumentNumber = "PaySlip 001", DocumentType = ResourceType.PaySlip }
             },
             Template = new PopeyeTemplate<PopeyeTemplateVariables>
             {
                 Name = "generic",
                 Variables = new PopeyeTemplateVariables
                 {
                     CompanyName = "MYOB",
                     Text = "this is the email content",
                     Html = string.Empty,
                     HeadingColour = string.Empty,
                 }
             },
             Subject = "Test Email" + DateTime.Now,
             WebHook = new PopeyeWebhook {Url = @"https://localhost:8080", Headers = new PopeyeWebhookHeaders()},
         },
        
     };
     return request;
 }
예제 #5
0
 public HappyEmail(EmailRequest request) : base(request)
 {
 }
 /// <summary>
 /// <para>Performs the Listing Method:
 /// Send an email to the seller of a classified.
 /// </para><para>
 /// Serializes the given EmailRequest into xml.
 /// Creates a query string using the listingId provided .
 /// </para><para>
 /// All the parameters are required.
 /// </para>
 /// REQUIRES AUTHENTICATION.
 /// </summary>
 /// <param name="emailRequest">The object that will be serialized into xml and then sent in a POST message.</param>
 /// <param name="listingId">The id of the listing that youwant to email about.</param>
 /// <returns>XDocument.</returns>
 public XDocument EmailSellerOfClassified(EmailRequest emailRequest, string listingId)
 {
     var query = String.Format(Constants.Culture, "{0}/{1}/emailseller{2}", Constants.LISTINGS, listingId, Constants.XML);
     return _connection.Post(emailRequest, query);
 }
예제 #7
0
 /// <summary>
 /// Sends the mail.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="request">The request.</param>
 /// <returns></returns>
 public async Task SendMailAsync <T>(EmailRequest <T> request) where T : class
 => await SendMailAsync((EmailRequest)request).ConfigureAwait(false);
예제 #8
0
        public async Task <IActionResult> GetOwnerByEmailAsync(EmailRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var owner = await _dataContext.Owners
                        .Include(o => o.User)
                        .Include(o => o.Properties)
                        .ThenInclude(p => p.PropertyType)
                        .Include(o => o.Properties)
                        .ThenInclude(p => p.PropertyImages)
                        .Include(o => o.Contracts)
                        .ThenInclude(c => c.Lessee)
                        .ThenInclude(l => l.User)
                        .FirstOrDefaultAsync(o => o.User.Email.ToLower() == request.Email.ToLower());

            if (owner == null)
            {
                return(NotFound());
            }

            var response = new OwnerResponse
            {
                Id          = owner.Id,
                FirstName   = owner.User.FirstName,
                LastName    = owner.User.LastName,
                Address     = owner.User.Address,
                Document    = owner.User.Document,
                Email       = owner.User.Email,
                PhoneNumber = owner.User.PhoneNumber,
                Properties  = owner.Properties?.Select(p => new PropertyResponse
                {
                    Address   = p.Address,
                    Contracts = p.Contracts?.Select(c => new ContractResponse
                    {
                        EndDate   = c.EndDate,
                        Id        = c.Id,
                        IsActive  = c.IsActive,
                        Lessee    = ToLessesResponse(c.Lessee),
                        Price     = c.Price,
                        Remarks   = c.Remarks,
                        StartDate = c.StartDate
                    }).ToList(),
                    HasParkingLot  = p.HasParkingLot,
                    Id             = p.Id,
                    IsAvailable    = p.IsAvailable,
                    Neighborhood   = p.Neighborhood,
                    Price          = p.Price,
                    PropertyImages = p.PropertyImages?.Select(pi => new PropertyImageResponse
                    {
                        Id       = pi.Id,
                        ImageUrl = pi.ImageFullPath
                    }).ToList(),
                    PropertyType = p.PropertyType.Name,
                    Remarks      = p.Remarks,
                    Rooms        = p.Rooms,
                    SquareMeters = p.SquareMeters,
                    Stratum      = p.Stratum
                }).ToList()
            };

            return(Ok(response));
        }
예제 #9
0
        public async Task <Response> RecoverPasswordAsync(string urlBase, string servicePrefix, string controller, EmailRequest emailRequest)
        {
            try
            {
                string        request = JsonConvert.SerializeObject(emailRequest);
                StringContent content = new StringContent(request, Encoding.UTF8, "application/json");
                HttpClient    client  = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };

                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, content);

                string answer = await response.Content.ReadAsStringAsync();

                Response obj = JsonConvert.DeserializeObject <Response>(answer);
                return(obj);
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message,
                });
            }
        }
예제 #10
0
 /// <summary>
 /// Sends the mail.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns></returns>
 public override async Task SendMailAsync(EmailRequest request)
 => await base.SendMailAsync(request).ConfigureAwait(false);
예제 #11
0
        public async Task <IHttpActionResult> EmailCheck([FromBody] EmailRequest model)
        {
            dynamic expando = new ExpandoObject();

            var apiResponse = new ApiResponse
            {
                Success = false,
                Message = "Bad Request"
            };

            try
            {
                if (!ModelState.IsValid)
                {
                    expando.Description = "EMAIL_REQUIRED_OR_INVALID";
                    apiResponse.Data    = expando;
                    return(Content(HttpStatusCode.BadRequest, apiResponse));
                }

                var hasNotCompleted = await _validationService.HasNotCompletedPreviousWonFlow(model.Email);

                if (hasNotCompleted.Status)
                {
                    expando.Description     = "USER_HAS_NOT_COMPLETED_PREVIOUS_FLOW";
                    expando.ParticipationId = hasNotCompleted.ParticipationId;
                    expando.ParticipantId   = hasNotCompleted.ParticipantId;
                    apiResponse.Data        = expando;
                    apiResponse.Success     = true;
                    apiResponse.Message     = "User should continue previous flow";
                    return(Ok(apiResponse));
                }

                var isOpen = await _validationService.IsOpenHoursForParticipationAsync();

                if (!isOpen)
                {
                    expando.Description = "PARTICIPATION_CLOSED";
                    apiResponse.Data    = expando;
                    return(Content(HttpStatusCode.BadRequest, apiResponse));
                }

                var canParticipate = await _validationService.CanUserParticipateAsync(model.Email);

                if (!canParticipate.status)
                {
                    expando.Description = canParticipate.errorMessage;
                    apiResponse.Data    = expando;
                    return(Content(HttpStatusCode.BadRequest, apiResponse));
                }

                var participateResult = await _participationService.GetOrCreateEmailValidatedParticipationAsync(model.Email);

                expando.Description = participateResult.creationStatus ?
                                      "PARTICIPATION_CREATED_SUCCESSFULLY" :
                                      "PARTICIPATION_ALREADY_CREATED";
                expando.ParticipationId = participateResult.participationId;
                expando.ParticipantId   = participateResult.participantId;
                apiResponse.Success     = true;
                apiResponse.Message     = "Email validation successfull";
                apiResponse.Data        = expando;

                return(Ok(apiResponse));
            }
            catch (Exception e)
            {
                apiResponse.Success = false;
                apiResponse.Message = e.Message;
                expando.Description = $"Error occured in {e.Source}: {e.StackTrace}";
                apiResponse.Data    = expando;

                return(Content(HttpStatusCode.InternalServerError, apiResponse));
            }
        }
예제 #12
0
        public async Task <IActionResult> GetGroupBets(EmailRequest emailRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var groupBetsPlayer = await _context.GroupBetPlayers
                                  .Include(p => p.Player)
                                  .ThenInclude(u => u.User)
                                  .ThenInclude(f => f.FavoriteTeam)
                                  .ThenInclude(l => l.League)

                                  .Include(g => g.GroupBet)
                                  .ThenInclude(t => t.Tournament)

                                  .Include(g => g.GroupBet)
                                  .ThenInclude(p => p.Admin)
                                  .ThenInclude(p => p.User)
                                  .ThenInclude(f => f.FavoriteTeam)
                                  .ThenInclude(l => l.League)

                                  .Include(g => g.GroupBet)
                                  .ThenInclude(p => p.GroupBetPlayers)
                                  .ThenInclude(p => p.Player)
                                  .ThenInclude(u => u.User)
                                  .ThenInclude(f => f.FavoriteTeam)
                                  .ThenInclude(l => l.League)

                                  .Include(g => g.GroupBet)
                                  .ThenInclude(p => p.GroupBetPlayers)
                                  .ThenInclude(p => p.Player)
                                  .ThenInclude(p => p.Predictions)
                                  .ThenInclude(p => p.Match)
                                  .ThenInclude(p => p.Local)
                                  .ThenInclude(p => p.League)

                                  .Include(g => g.GroupBet)
                                  .ThenInclude(p => p.GroupBetPlayers)
                                  .ThenInclude(p => p.Player)
                                  .ThenInclude(p => p.Predictions)
                                  .ThenInclude(p => p.Match)
                                  .ThenInclude(p => p.Visitor)
                                  .ThenInclude(p => p.League)

                                  .Include(g => g.GroupBet)
                                  .ThenInclude(p => p.GroupBetPlayers)
                                  .ThenInclude(p => p.Player)
                                  .ThenInclude(p => p.Predictions)
                                  .ThenInclude(p => p.Match)
                                  .ThenInclude(p => p.Group)
                                  .ThenInclude(p => p.Tournament)

                                  .Where(o => o.Player.User.Email.ToLower() == emailRequest.Email.ToLower() && o.GroupBet.Tournament.IsActive)
                                  .OrderBy(a => a.GroupBet.Name)
                                  .ToListAsync();

            var response = new List <GroupBetResponse>();

            foreach (var groupBetPlayer in groupBetsPlayer)
            {
                var group = new GroupBetResponse
                {
                    Id           = groupBetPlayer.GroupBet.Id,
                    Admin        = _converterHelper.ToPlayerResponse(groupBetPlayer.GroupBet.Admin),
                    CreationDate = groupBetPlayer.GroupBet.CreationDate,
                    LogoPath     = groupBetPlayer.GroupBet.LogoPath,
                    Name         = groupBetPlayer.GroupBet.Name,
                    Tournament   = _converterHelper.ToTournamentResponse(await _context.Tournaments.FirstOrDefaultAsync(a => a.Id == groupBetPlayer.GroupBet.Tournament.Id)),

                    GroupBetPlayers = groupBetPlayer.GroupBet.GroupBetPlayers.Select(p => new GroupBetPlayerResponse
                    {
                        Id         = p.Id,
                        IsAccepted = p.IsAccepted,
                        IsBlocked  = p.IsBlocked,
                        Points     = p.Points,
                        Player     = new PlayerResponse2
                        {
                            FirstName   = p.Player.User.FirstName,
                            LastName    = p.Player.User.LastName,
                            NickName    = p.Player.User.NickName,
                            PicturePath = p.Player.User.Picture,
                            Id          = p.Player.Id,
                            Points      = p.Player.User.Points,
                            Team        = new TeamResponse
                            {
                                Id         = p.Player.User.FavoriteTeam.Id,
                                Initials   = p.Player.User.FavoriteTeam.Initials,
                                LeagueId   = p.Player.User.FavoriteTeam.League.Id,
                                LeagueName = p.Player.User.FavoriteTeam.League.Name,
                                Name       = p.Player.User.FavoriteTeam.Name,
                                LogoPath   = p.Player.User.FavoriteTeam.LogoPath,
                            },
                            UserId      = p.Player.User.Id,
                            Predictions = p.Player.Predictions.Select(h => new PredictionResponse2
                            {
                                Id           = h.Id,
                                GoalsLocal   = h.GoalsLocal,
                                GoalsVisitor = h.GoalsVisitor,
                                Points       = h.Points,
                                MatchId      = h.Match.Id,
                                PlayerId     = h.Player.Id,
                                TournamentId = h.Match.Group.Tournament.Id,
                                NameLocal    = h.Match.Local.Name,
                                NameVisitor  = h.Match.Visitor.Name
                            }).ToList()
                        },
                    }).ToList()
                };

                response.Add(group);
            }

            return(Ok(response));
        }
예제 #13
0
        private bool _SendEmail(JobEmailFormModel form, JobDetailsFullModel job)
        {
            var subject = string.IsNullOrWhiteSpace(this.EmailSubject) ? "Job for you" : this.EmailSubject;

            var content = _GetHtmlEmailContent();

            var emailSender = new SitefinityEmailSender();

            // ideally there should be a common method to get a job's url
            // doing this due to lack of such method
            var jobUrl = Request.Url.Scheme + "://" + Request.Url.Authority;

            if (!string.IsNullOrWhiteSpace(JobDetailsPageId))
            {
                jobUrl += SitefinityHelper.GetPageUrl(JobDetailsPageId);

                if (job.ClassificationURL != null)
                {
                    jobUrl += "/" + job.ClassificationURL;
                }

                jobUrl += "/" + job.JobID;
            }


            dynamic templateData = new ExpandoObject();

            templateData.Job       = new ExpandoObject();
            templateData.Job.Id    = job.JobID;
            templateData.Job.Title = job.Title;
            templateData.Job.Url   = jobUrl;
            templateData.Domain    = HttpContext.GetCurrentDomain();

            var result = false;

            // if the email is not set then create one using current site's domain name
            var fromEmail = this.EmailFromEmail;

            if (string.IsNullOrEmpty(fromEmail))
            {
                fromEmail = "noreply@" + Request.Url.Host;
            }

            if (form.EmailFriend)
            {
                var from = new MailAddress(fromEmail, form.Name);

                var replyToCollection = new MailAddressCollection();
                replyToCollection.Add(new MailAddress(form.Email, form.Name));

                templateData.Sender = from;

                if (form.FriendMessage == null)
                {
                    templateData.Message = string.Empty;
                }
                else
                {
                    templateData.Message = Regex.Replace(form.FriendMessage, "<.*?>", String.Empty).Replace("\n", "<br />");
                }

                foreach (var item in form.Friend)
                {
                    var emailRequest = new EmailRequest
                    {
                        To        = new MailAddress(item.Email, item.Name),
                        ReplyTo   = replyToCollection,
                        From      = from,
                        Subject   = subject,
                        EmailBody = content
                    };

                    templateData.Recipient = emailRequest.To;

                    if (emailSender.SendEmail(emailRequest, templateData))
                    {
                        result = true;
                    }
                }
            }
            else
            {
                // if the name is not set then use current site's name
                var fromName = this.EmailFromName;
                if (string.IsNullOrEmpty(fromName))
                {
                    fromName = new MultisiteContext().CurrentSite.Name;
                }

                var emailRequest = new EmailRequest
                {
                    To        = new MailAddress(form.Email, form.Name),
                    From      = new MailAddress(fromEmail, fromName),
                    Subject   = subject,
                    EmailBody = content
                };

                templateData.Recipient = emailRequest.To;
                templateData.Sender    = emailRequest.From;
                templateData.Message   = string.Empty;

                result = emailSender.SendEmail(emailRequest, templateData);
            }

            return(result);
        }
예제 #14
0
 public async Task Send([FromBody] EmailRequest request)
 {
     await sender.SendAsync(request);
 }
예제 #15
0
 public EmailResponse Send(EmailRequest request)
 {
     return _factory.Send(request);
 }
예제 #16
0
 public EmailResponse SendWithDynamicHtml(EmailRequest request)
 {
     throw new NotImplementedException();
 }
예제 #17
0
 public EmailResponse SendWithHtml(EmailRequest request)
 {
     return _factory.SendWithHtml(request);
 }
예제 #18
0
 public EmailResponse Send(EmailRequest request)
 {
     throw new NotImplementedException();
 }
예제 #19
0
 public QuickEmail(EmailRequest request) : base(request)
 {
 }
예제 #20
0
 /// <summary>
 /// Map e-mail request to e-mail address object
 /// </summary>
 /// <param name="request">E-mail request object</param>
 public static EmailAddress Map(this EmailRequest request)
 => new EmailAddress(request.Email, request.Name);