public async Task <ActionResult> Edit(InternshipApplicationViewModel app) { await _appManager.UpdateApplication(app); await _appManager.SendStatusEmail(app); return(View("Details", _appManager.GetApplication(app.UserId))); }
public async Task SendStatusEmail(InternshipApplicationViewModel form) { var user = _dbContext.AspNetUsers.FirstOrDefault(u => u.Id == form.UserId); var status = GetStatuses().FirstOrDefault(s => s.Value == form.SelectedStatusId.ToString()); var body = "<p>Dear {0}, </p><p>{1}</p>"; var emailMessage = new MailMessage(); emailMessage.To.Add(new MailAddress("*****@*****.**")); emailMessage.From = new MailAddress("*****@*****.**"); emailMessage.Subject = "Internship Application Update"; string message = "Your Internship Application is still on pending.<br/><br/>" + "Best regards, <br/>" + "InternRecruiter.";; if (status.Text == "Accepted" && form.Date != "Not scheduled") { message = "Congratulations!<br/><br/>" + "The Human Resources team has Accepted your Internship Application.<br/>" + "You are scheduled for a Technical Test at our office on " + form.Date + "<br/><br/>" + "If the date doesn't suit you, please use our Contact page and contact us to change the date for the test. <br/><br/>" + "Best regards, <br/>" + "InternRecruiter."; } else if (status.Text == "Accepted" && form.Date == "Not scheduled") { message = "Congratulations!<br/><br/>" + "The Human Resources team has Accepted your Internship Application.<br/>" + "You are not scheduled for a Technical Test yet but you will be notified with another email when the Human Resources" + " team schedules you. <br/><br/>" + "Best regards, <br/>" + "InternRecruiter."; } else if (status.Text == "Rejected") { message = "We are sorry to tell you but your Internship Application has been Rejected.<br/>" + "We wish you good luck and we hope to see you again! <br/><br/>" + "Best regards, <br/>" + "InternRecruiter."; } emailMessage.Body = string.Format(body, user.UserName, message); emailMessage.IsBodyHtml = true; using (var smtp = new SmtpClient()) { //var credential = new NetworkCredential //{ // UserName = "******", // replace with valid value // Password = "******" // replace with valid value //}; //smtp.Credentials = credential; //smtp.Host = "smtp.mail.com"; //smtp.Port = 587; //smtp.EnableSsl = true; await smtp.SendMailAsync(emailMessage); } }
public ActionResult SubmitApplication() { var vm = new InternshipApplicationViewModel { Languages = _appManager.GetLanguages(), Technologies = _appManager.GetTechnologies() }; return(View(vm)); }
public async Task UpdateApplication(InternshipApplicationViewModel appForm) { var app = _dbContext.InternshipApplications.FirstOrDefault(a => a.UserId == appForm.UserId); var status = GetStatuses().FirstOrDefault(s => s.Value == appForm.SelectedStatusId.ToString()); if (app != null) { app.Status = status.Text; app.ScheduleDate = appForm.Date; } await _dbContext.SaveChangesAsync(); }
public async Task Add(InternshipApplicationViewModel appForm) { var app = _dbContext.InternshipApplications.FirstOrDefault(a => a.UserId == appForm.UserId); var languages = appForm.SelectedLanguages; var technologies = appForm.SelectedTechnologies; if (app == null) { var newApp = new DataAccess.InternshipApplication { UserId = appForm.UserId, Name = appForm.Name, Surname = appForm.Surname, PhoneNumber = appForm.PhoneNumber, PersonalProjects = appForm.PersonalProjects, University = appForm.University, Faculty = appForm.Faculty, StudyYear = appForm.StudyYear, WantsToBeHired = appForm.WantsToBeHired, RecommendForInternship = appForm.RecommendForInternship, Status = "Pending", ScheduleDate = "Not scheduled" }; foreach (var langId in languages) { var language = _dbContext.Languages.FirstOrDefault(l => l.Id == langId); newApp.Languages.Add(language); } foreach (var techId in technologies) { var technology = _dbContext.Technologies.FirstOrDefault(l => l.Id == techId); newApp.Technologies.Add(technology); } _dbContext.InternshipApplications.Add(newApp); await _dbContext.SaveChangesAsync(); } else { throw new Exception(); } }
public InternshipApplicationViewModel GetApplication(string id) { var app = _dbContext.InternshipApplications.FirstOrDefault(u => u.UserId == id); var user = _dbContext.AspNetUsers.FirstOrDefault(u => u.Id == id); var status = GetStatuses().FirstOrDefault(s => s.Text == app.Status); var selectedLangs = new List <string>(); foreach (var lang in app.Languages) { selectedLangs.Add(lang.Name); } var selectedTechs = new List <string>(); foreach (var tech in app.Technologies) { selectedTechs.Add(tech.Name); } var appViewModel = new InternshipApplicationViewModel { UserId = app.UserId, UserEmail = user.Email, Name = app.Name, Surname = app.Surname, PhoneNumber = app.PhoneNumber, PersonalProjects = app.PersonalProjects, University = app.University, Faculty = app.Faculty, StudyYear = app.StudyYear, WantsToBeHired = app.WantsToBeHired, RecommendForInternship = app.RecommendForInternship, SelectedL = string.Join(", ", selectedLangs.ToArray()), SelectedT = string.Join(", ", selectedTechs.ToArray()), Statuses = GetStatuses(), SelectedStatusId = int.Parse(status.Value), Status = status.Text, Date = app.ScheduleDate }; return(appViewModel); }
public async Task <ActionResult> SubmitApplication(InternshipApplicationViewModel form) { try { form.UserId = User.Identity.GetUserId(); await _appManager.Add(form); await _appManager.SendInternshipApplicationEmail(form); return(RedirectToAction("Index", "Home")); } catch (Exception) { return(RedirectToAction("Error", "Home", new ErrorViewModel { ErrorMessage = "You have already applied for the Internship!" })); } }
public async Task SendInternshipApplicationEmail(InternshipApplicationViewModel form) { var user = _dbContext.AspNetUsers.FirstOrDefault(u => u.Id == form.UserId); var body = "<p>Dear {0}, </p><p>{1}</p>"; var emailMessage = new MailMessage(); emailMessage.To.Add(new MailAddress(user.Email)); emailMessage.From = new MailAddress("*****@*****.**"); emailMessage.Subject = "New Internship Application"; var message = "Thank you for submitting an Internship Application. <br/><br/> " + "The Human Resources team will take a look at your application and will give you an answer it as soon as possible, " + "after the application has been Accepted or Rejected, you will be notified through an email.<br/><br/>" + "Best regards, <br/>" + "InternRecruiter."; emailMessage.Body = string.Format(body, user.UserName, message); emailMessage.IsBodyHtml = true; using (var smtp = new SmtpClient()) { await smtp.SendMailAsync(emailMessage); } }