Example #1
0
        public async Task <HttpResponseMessage> RejectionNotice(string phoneNumber, string email, string name, string jobId, string jobTitle, string company)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(jobId))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            // find application
            Application app = null;
            Applicant   a   = await ApplicantFactory.GetApplicantByEmail(email);

            if (a == null)
            {
                if (!string.IsNullOrEmpty(phoneNumber) && !string.IsNullOrEmpty(name))
                {
                    a = new Applicant()
                    {
                        Phone = phoneNumber, Email = email, Name = name
                    };
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            if (!a.Applications.Keys.Contains(jobId))
            {
                if (!string.IsNullOrEmpty(jobTitle) && !string.IsNullOrEmpty(company))
                {
                    app = new Application()
                    {
                        Id = jobId, Applied = DateTime.Parse("1/1/2017"), State = ConversationType.None, Title = jobTitle, Company = company
                    };
                    a.Applications.Add(jobId, app);
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            app = a.Applications[jobId];

            // do job matching
            var jobTitles = Express.GetJobSuggestions(app.Title);

            var jobSuggestionHtml = new StringBuilder();
            var filteredJobTitles = jobTitles.Take(3).ToList <string>();

            foreach (var title in filteredJobTitles)
            {
                jobSuggestionHtml.Append("<li><a href='#'>" + title + "</a>");
            }

            // send the email
            dynamic channelData = new ExpandoObject();

            channelData.HtmlBody = string.Format(Resources.rejectionEmailTemplate, a.Name, app.Title, filteredJobTitles.Count, jobSuggestionHtml.ToString());
            channelData.Subject  = string.Format("Job Application Response: {0}", app.Title);

            var payload = new MessagePayload()
            {
                FromId      = ConfigurationManager.AppSettings["Office356_Email"],
                ToId        = email,
                ChannelData = channelData,
                ServiceUrl  = ConfigurationManager.AppSettings["BotFramework_EmailServiceUrl"]
            };
            var credentials = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"], ConfigurationManager.AppSettings["MicrosoftAppPassword"]);
            var response    = await Bot.SendMessage(payload, credentials);

            // save the conversation state so when the recipient responds we know in what context they replied in
            app.State = ConversationType.RejectionNotice;
            await ApplicantFactory.PersistApplicant(a);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }