Exemplo n.º 1
0
        public async Task <Response> SendEmail(RegisterInviteAddRequest model)
        {
            string   dateInput      = model.Expiration.ToString();
            DateTime parsedDate     = DateTime.Parse(dateInput);
            var      newDate        = parsedDate.ToString();
            string   serverPath     = System.Configuration.ConfigurationManager.AppSettings["emailTemplate"];
            string   rootPath       = HttpContext.Current.Server.MapPath(serverPath);
            string   serverFileName = "InviteEmailTemplate.html";
            string   fqn            = Path.Combine(rootPath, serverFileName);

            {
                var      client                 = new SendGridClient(sendGridKey);
                var      from                   = new EmailAddress("*****@*****.**", "project");
                var      subject                = "Invitation to Project";
                var      to                     = new EmailAddress(model.Email, model.FirstName);
                string   testTemplate           = File.ReadAllText(fqn);
                string   TemplateWithLink       = testTemplate.Replace("{the_link}", "https://project.com/register/" + model.Token);
                var      fullName               = $"{model.FirstName} {model.LastName}";
                string   TemplateWithFirstName  = TemplateWithLink.Replace("{FirstName}", fullName);
                string   TemplatewithExpiration = TemplateWithFirstName.Replace("{expired}", newDate);
                var      plainTextContent       = TemplatewithExpiration;
                var      htmlContent            = TemplatewithExpiration;
                var      msg                    = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
                Response response               = await client.SendEmailAsync(msg);

                return(response);
            }
        }
Exemplo n.º 2
0
        public int Insert(RegisterInviteAddRequest model)
        {
            int id = 0;

            this._dataProvider.ExecuteNonQuery(
                "RegisterInvite_Insert",
                inputParamMapper : delegate(SqlParameterCollection paramList)
            {
                SqlParameter param = new SqlParameter
                {
                    ParameterName = "@Id",
                    SqlDbType     = System.Data.SqlDbType.Int,
                    Direction     = System.Data.ParameterDirection.Output
                };
                paramList.Add(param);
                paramList.AddWithValue("@FirstName", model.FirstName);
                paramList.AddWithValue("@MiddleInitial", model.MiddleInitial);
                paramList.AddWithValue("@LastName", model.LastName);
                paramList.AddWithValue("@Email", model.Email);
                paramList.AddWithValue("@Token", model.Token);
                paramList.AddWithValue("@Expiration", model.Expiration);
                paramList.AddWithValue("@ModifiedBy", model.ModifiedBy);
                paramList.AddWithValue("@RoleId", model.RoleId);
                paramList.AddWithValue("@OrgId", model.OrgId);
                paramList.AddWithValue("@FundSourceId", model.FundSourceId);
            },
                returnParameters : delegate(SqlParameterCollection paramList)
            {
                id = (int)paramList["@Id"].Value;
            });
            return(id);
        }