示例#1
0
        /*
         * First will search in subject about controllers name or site code or site name
         * if exist go to and insert in database and assign users
         * else go to search in body about same if exist make same
         * if not exist in subject or body Exit from function and don't assign any user in this case Admin will assign manually
         *
         */
        private void AssignAuto(EmailMessage email, int id)
        {
            List <int> controllerId;


            List <int> conIdSub = SubContainsCon(email);

            if (conIdSub[0] == -1)
            {
                List <int> conIdBody = BodyContainsCon(email);
                if (conIdBody[0] == -1)
                {
                    return;
                }
                else
                {
                    controllerId = conIdBody.Distinct().ToList();
                }
            }
            else
            {
                controllerId = conIdSub.Distinct().ToList();
            }


            EmailRepository updateEmail = new EmailRepository();
            string          emailRef    = "NPO#" + id;
            string          emails      = "";

            updateEmail.UpdateStutes(emailRef, id);
            if (controllerId.Count != 0)
            {
                for (int i = 0; i < controllerId.Count; i++)
                {
                    if (controllerId[i] != 0)
                    {
                        updateEmail.AddControllerId(controllerId[i], id);
                        DataTable dataTable = updateEmail.GetControllerAssignUsers(controllerId[i]);
                        foreach (DataRow item in dataTable.Rows)
                        {
                            updateEmail.AddUserEmail(Convert.ToInt32(item["UserId"]), id);
                            emails += item["EmailAddress"].ToString() + ",";
                        }
                    }
                }

                EntityEmail sendEmail = new EntityEmail();

                sendEmail.To      = emails;
                sendEmail.Body    = "you have a new Assign search By Email Reference : " + emailRef;
                sendEmail.Subject = "NPO Tool";

                MailHelper.SendMail(sendEmail);
            }
        }