public ActionResult GetChangeRepCP(string emp, string cp, string judge) { string submit = judge; string location = cp; string empName = emp; if (judge.Equals("Cancel")) { RedirectToAction("CurrentRepCP", "DepartmentHead"); } else if (judge.Equals("Apply Change")) { if (location != null && empName != null) { Employee newRep = _employeeDAO.FindEmployeeByName(empName); string codeDepartment = newRep.CodeDepartment; string oldCollectionPoint = _collectionPointDAO.FindByDepartment(codeDepartment); Employee oldRep = _employeeDAO.FindDepartmentRep(codeDepartment); if (oldRep == null) { //if there is no oldRep then do not need to set idrole etc //but need set new rep _employeeDAO.ChangeNewRepCP(newRep.Name, location); //@Shutong: send notification here Employee e = _employeeDAO.FindEmployeeByName(newRep.Name); int IdEmployee = e.IdEmployee; var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.All.receiveNotification(IdEmployee); EmailClass emailClass = new EmailClass(); string message = "Hi " + newRep.Name + ", you are appointed as Department Rep. Collection Point is " + location; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message); //end of notification sending } else { // old rep is not null //change old rep back to employee //change the current employee to rep and change collection point _employeeDAO.PutOldRepBack(oldRep.Name); _employeeDAO.ChangeNewRepCP(newRep.Name, location); if (newRep.Name != oldRep.Name) { //@Shutong: send notification here int IdEmployee = oldRep.IdEmployee; var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.All.receiveNotification(IdEmployee); EmailClass emailClass = new EmailClass(); string message = "Hi " + oldRep.Name + ", you are not Department Rep anymore."; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(oldRep.Email, "SSIS System Email", message); IdEmployee = newRep.IdEmployee; hub.Clients.All.receiveNotification(IdEmployee); message = "Hi " + newRep.Name + ", you are appointed as Department Rep. Collection Point is " + location; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(newRep.Email, "SSIS System Email", message); //end of notification sending } //if rep didnot change but only cp changes else { if (oldCollectionPoint != location) { int IdEmployee = oldRep.IdEmployee; var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.All.receiveNotification(IdEmployee); EmailClass emailClass = new EmailClass(); string message = "Hi " + oldRep.Name + ", your collection point has been changed by your head."; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(oldRep.Email, "SSIS System Email", message); } } } return(RedirectToAction("CurrentRepCP", "DepartmentHead")); } } return(RedirectToAction("CurrentRepCP", "DepartmentHead")); }
public JsonResult ChangeRepAndCP(string newRep, string newCP, int id) { Employee newRepE = _employeeDAO.FindEmployeeByName(newRep); string codeDepartment = newRepE.CodeDepartment; string oldCollectionPoint = _collectionPointDAO.FindByDepartment(codeDepartment); Employee oldRep = _employeeDAO.FindDepartmentRep(codeDepartment); //change old rep to employee _employeeDAO.PutOldRepBack(oldRep.Name); _employeeDAO.ChangeNewRepCP(newRepE.Name, newCP); if (newRepE.Name != oldRep.Name) { //@Shutong: send notification here int IdEmployee = oldRep.IdEmployee; string message = "Hi " + oldRep.Name + ", you are not Department Rep anymore."; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, id, message); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = new System.Net.NetworkCredential(@"*****@*****.**", "woshishenaqq6!"); client.EnableSsl = true; //client.Timeout = 5000; client.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage mm = new MailMessage("*****@*****.**", oldRep.Email); mm.Subject = "SSIS System Email"; mm.Body = message; client.Send(mm); IdEmployee = newRepE.IdEmployee; message = "Hi " + newRepE.Name + ", you are appointed as Department Rep."; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, id, message); mm = new MailMessage("*****@*****.**", newRepE.Email); mm.Subject = "SSIS System Email"; mm.Body = message; client.Send(mm); //end of notification sending } //if rep didnot change but only cp changes else { if (oldCollectionPoint != newCP) { int IdEmployee = oldRep.IdEmployee; string message = "Hi " + oldRep.Name + ", your collection point has been changed by your head."; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, id, message); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = new System.Net.NetworkCredential(@"*****@*****.**", "woshishenaqq6!"); client.EnableSsl = true; //client.Timeout = 5000; client.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage mm = new MailMessage("*****@*****.**", oldRep.Email); mm.Subject = "SSIS System Email"; mm.Body = message; client.Send(mm); } } return(Json(new { status = "Ok" })); }