Пример #1
0
        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" }));
        }