public HttpResponseMessage Send(UsersEmailSendRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }

            _contactUsersService.Send(model);

            SuccessResponse response = new SuccessResponse();

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
示例#2
0
        public async Task Send(UsersEmailSendRequest model)
        {
            List <PersonBase> personList = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.PersonNotificationPreference_GetContactUsersPeople",
                                    inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@AspNetUserRoleId", model.AspNetUserRoleId ?? String.Empty);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                switch (set)
                {
                case 0:
                    PersonBase prsn = new PersonBase();

                    int ord          = 0;
                    prsn.Id          = reader.GetSafeInt32(ord++);
                    prsn.FirstName   = reader.GetSafeString(ord++);
                    prsn.MiddleName  = reader.GetSafeString(ord++);
                    prsn.LastName    = reader.GetSafeString(ord++);
                    prsn.PhoneNumber = reader.GetSafeString(ord++);
                    prsn.Email       = reader.GetSafeString(ord++);

                    if (personList == null)
                    {
                        personList = new List <PersonBase>();
                    }
                    personList.Add(prsn);
                    break;
                }
            }
                                    );
            if (personList != null)
            {
                foreach (PersonBase prsn in personList)
                {
                    string path           = HttpContext.Current.Server.MapPath("~/HTML_Templates/ContactUsersEmail.html");
                    string emailBody      = System.IO.File.ReadAllText(path);
                    string finalEmailHtml = emailBody.Replace("{{title}}", model.Title)
                                            .Replace("{{body}}", model.Body);

                    await _emailService.Send(SiteConfig.SiteAdminEmailAddress, "Operation Code", prsn.FullName, prsn.Email, model.Subject, model.PlainText, finalEmailHtml);
                }
            }
        }