// Displays the HTML page public ActionResult Index() { cache.GetOrSet("employees", () => db.UltiPro); // Load Employees into Cache // Get correct username from windows authenticate Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); WindowsPrincipal principal = (WindowsPrincipal)User; string first_name; string last_name; string eecudfield; using (PrincipalContext pc = new PrincipalContext(ContextType.Domain)) { UserPrincipal up = UserPrincipal.FindByIdentity(pc, principal.Identity.Name); ViewData["UserName"] = up.Name; first_name = up.GivenName; last_name = up.Surname; eecudfield = Regex.Replace(User.Identity.Name, ".*\\\\(.*)", "$1", RegexOptions.None); } // Get an exact match of Nominator info from the database // var currUser = db.UltiPro.AsEnumerable().Select( user => user ).Where( user => user.first_name.Equals( first_name ) && user.last_name.Equals( last_name ) ); var currUser = db.UltiPro.SingleOrDefault(user => user.eecudfield01.Contains(eecudfield)); UltiPro us = currUser; // If no exact match //if( !currUser.Any() ) { // currUser = db.UltiPro.AsEnumerable().Select( user => user ).Where( user => user.first_name.Contains( first_name ) && user.last_name.Contains( last_name ) ); // Get an approximate match // us = (currUser.Any()) ? currUser.ToList<UltiPro>()[0] : null; //} //else us = currUser.ToList<UltiPro>()[0]; WindowsIdentity id = WindowsIdentity.GetCurrent(); ViewData["empID"] = (us != null) ? us.employee_number : ""; ViewData["WindowsID"] = id.Name; ViewData["nominator_last"] = (us != null) ? us.last_name : ""; ViewData["nominator_first"] = (us != null) ? us.first_name : ""; ViewData["nominator_middle"] = (us != null) ? us.middle_name : ""; ViewData["nominator_full_name"] = (us != null) ? ((us.middle_name != null) ? String.Format("{0} {1} {2}", us.first_name, us.middle_name, us.last_name) : String.Format("{0} {1}", us.first_name, us.last_hire_date)) : ""; return(View()); }
public async Task <JsonResult> CreateTeam(EOM_Nomination[] eOM_Nominations) { Dictionary <string, string> dict = new Dictionary <string, string>(); List <string> nominees = new List <string>(); List <string> groups = new List <string>(); string statMsg = String.Format("Nominated By: {0}\nNomination Reason: {1}\n\n\n", eOM_Nominations[0].Nominator_Employee_Full_Name, eOM_Nominations[0].Nomination_Reason); if (ModelState.IsValid) { foreach (EOM_Nomination entry in eOM_Nominations) { if (EntryInModel(entry)) { entry.Submission_Date = DateTime.Now; db.EOM_Nomination.Add(entry); await db.SaveChangesAsync(); // If group name if (entry.Nominee_Employee_Number == null) { statMsg += String.Format("Group: {0}\n", entry.Nominee_Emp_or_Team_Name); } // else nominee else { statMsg += String.Format("Nominee ID: {0}\nNominee Name: {1}\n\n", entry.Nominator_Employee_Number, entry.Nominee_Emp_or_Team_Name); } } } dict.Add("Message", "Success"); var nominator = db.UltiPro.AsEnumerable().Select(user => user).Where(user => user.employee_number == eOM_Nominations[0].Nominator_Employee_Number); UltiPro u = nominator.ToList()[0]; handleNotification(eOM_Nominations[0], statMsg); return(Json(dict, JsonRequestBehavior.AllowGet)); } dict.Add("Message", "Failure"); return(Json(dict, JsonRequestBehavior.AllowGet)); }
private void handleNotification(EOM_Nomination eom, string statMsg = null) { // Get nominator var nominator = db.UltiPro.AsEnumerable().Select(user => user).Where(user => user.employee_number == eom.Nominator_Employee_Number); UltiPro u = nominator.ToList()[0]; Mail m = new Mail(); string nominationType; // nominator email address string nominatorEmail = String.Format("{0}.{1}@lowndes-law.com", u.first_name, u.last_name); string eeucid = String.Format("{0}@lowndes-law.com", u.eecudfield01); // Email for single nomination if (statMsg == null) { // Send email to nomination submitter string messageToNominator = String.Format("Thank you for your nomination of {0}. This email is just a confirmation that your nomination was recorded successfully", eom.Nominee_Emp_or_Team_Name); m.SendMessage(nominatorEmail, eeucid, "Thank you for your Applause, Applause Nomination", messageToNominator); // Build msg for bccRecipients statMsg = String.Format("Nominated By: {0}\nNomination Reason: {1}\nNominee ID: {2}\nNominee Name: {3}\n", eom.Nominator_Employee_Full_Name, eom.Nomination_Reason, eom.Nominator_Employee_Number, eom.Nominee_Emp_or_Team_Name); nominationType = "New Applause, Applause Nomination"; } // Email for group nomination else { string messageToNominator = String.Format("Thank you for your teamwork award nomination. This email is a confirmation that your nomination was recorded successfully"); m.SendMessage(nominatorEmail, eeucid, "Thank you for your Teamwork Award Nomination", messageToNominator); nominationType = "New Teamwork Award Nomination"; } string[] bccRecipients = new string[] { "*****@*****.**", "*****@*****.**" }; string mainRecipient = "*****@*****.**"; m.SendMessage(mainRecipient, bccRecipients, eeucid, nominationType, statMsg); }