Example #1
0
        public ActionResult CreateMessage(EmployeeMessage item)
        {
            item.CreatedDate = DateTime.Now;
            item.CreatedBy   = new Employee
            {
                Id = GetEmployeeId
            };

            if (item.To.Id != item.CreatedBy.Id)
            {
                var employee = GetSession.Load <Employee>(item.To.Id);
                item.To = employee;

                /*	if (employee.Email.Contains("@")) {
                 *      new NotificationsController().Message(employee).Deliver();
                 *  }*/
            }
            GetSession.Save(item);

            return(RedirectToAction("Card", new { item.To.Id }));
        }
        public ActionResult Create(ForumFormModel model, int categoryId = 1)
        {
            if (ModelState.IsValid)
            {
                #region Replace url text with link
                string body = model.Body;

                var outputString = model.Body;

                Regex regx = new Regex(@"https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?", RegexOptions.IgnoreCase);

                MatchCollection mactches = regx.Matches(model.Body);
                foreach (Match match in mactches)
                {
                    outputString = outputString.Replace(match.Value, String.Format("<a href=\"{0}\" target=\"_blank\">לחץ כאן</a>", match.Value));
                }

                body = outputString;


                model.Body = body;
                #endregion


                var item = Mapper.Map <ForumFormModel, Forum>(model);
                item.CreatedBy = new Employee
                {
                    Id = GetEmployeeId
                };

                if (model.ParentId.HasValue)
                {
                    var forum = GetSession.Load <Forum>(model.ParentId);
                    item.Parent  = forum;
                    item.Subject = item.Parent.Subject; // Must be Uniqe!!!!
                }
                ViewData["catId"] = categoryId;
                item.CategoryId   = categoryId;
                ViewBag.list      = GetSession.QueryOver <ForumItem>().List();

                GetSession.Save(item);

                var    current_domain = MvcApplication.Config("current_domain").ToString();
                string host           = HttpContext.ApplicationInstance.Request.Url.Host;


                var forumItem = GetSession.QueryOver <ForumItem>().Where(x => x.Id == categoryId).SingleOrDefault().Admin;



                #region Send mail to forum users


                if (GetSession.Get <ForumItem>(Convert.ToInt64(categoryId)).isAvailableTooAll == false)
                {
                    Employee emp;
                    var      forum_users = GetSession.Get <ForumItem>(Convert.ToInt64(categoryId)).ForumUsers;
                    string[] ids         = forum_users.Split(',');

                    var list = new List <string>(ids);
                    list.Remove(GetEmployeeId.ToString());
                    ids = list.ToArray();

                    for (int i = 0; i < ids.Length; i++)
                    {
                        long id = Convert.ToInt64(ids[i]);
                        emp = GetSession.Get <Employee>(id);
                        sendMailTo(emp, categoryId);
                    }
                }



                #endregion



                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(forumItem.Email.ToString());
                mail.Subject    = "הודעה חדשה בפורום";
                mail.IsBodyHtml = true;
                mail.Body       = "<html><body>"
                                  + "<h1>שלום, " + forumItem.FirstName.ToString() + " !</h1>"
                                  + "<h2>הודעה חדשה בפורום</h2>"
                                  + " <a href='" + host + "/Forums/" + item.CategoryId.ToString() + "'>לחץ כאן על הקישור לכניסה לפורום</a>"
                                  + "</body></html>";

                SmtpClient smtp = new SmtpClient();
                //smtp.Send(mail);



                //SmtpClient client = new SmtpClient();
                //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "tagmedia1234");
                //client.Port = 587;
                //client.Host = "smtp.gmail.com";
                //client.EnableSsl = true;
                //MailAddress
                //    maFrom = new MailAddress("*****@*****.**", "Sender's Name"),
                //    maTo = new MailAddress(forumItem.Email.ToString(), "Recipient's Name");
                //MailMessage mmsg = new MailMessage(maFrom.Address, maTo.Address);
                //mmsg.Body =
                //    "<html><body>"
                //    + "<h1>שלום, " + forumItem.FirstName.ToString() + " !</h1>"
                //    + "<h2>הודעה חדשה בפורום</h2>"
                //    + " <a href='" + host + "/Forums/" + item.CategoryId.ToString() + "'>לחץ כאן על הקישור לכניסה לפורום</a>"
                //    + "</body></html>";
                //mmsg.IsBodyHtml = true;
                //mmsg.Subject = "הודעה חדשה בפורום";



                long ebatnya = 0;
                if (item.Parent != null)
                {
                    ebatnya = GetSession.QueryOver <ForumItem>().Where(x => x.Id == item.Parent.CategoryId).SingleOrDefault().Admin.Id;
                }
                else
                {
                    ebatnya = GetSession.QueryOver <ForumItem>().Where(x => x.Id == item.CategoryId).SingleOrDefault().Admin.Id;
                }



                if (item.CreatedBy.Id != ebatnya)
                {
                    smtp.Send(mail);
                }

                if (item.Parent != null)
                {
                    var theIdOfFather = GetSession.QueryOver <Forum>().Where(x => x.Parent == null).And(x => x.Subject == item.Subject).SingleOrDefault();



                    var theParentIsAdmin = GetSession.QueryOver <ForumItem>().Where(x => x.Id == item.Parent.CategoryId).SingleOrDefault();

                    if (item.CreatedBy.Id == theParentIsAdmin.Admin.Id)
                    {
                        var msgBody =

                            "<html><body>"
                            + "<h1>שלום, " + theIdOfFather.CreatedBy.FirstName.ToString() + " !</h1>"
                            + "<h2>הודעה חדשה בפורום</h2>"
                            + "<a href='" + host + "/Forums/" + item.CategoryId.ToString() + "'>לחץ כאן על הקישור לכניסה לפורום</a>"
                            + "</body></html>";



                        var msgSubject = "הודעה חדשה בפורום";

                        SendForumEmail(theIdOfFather.CreatedBy.Email.ToString(), msgSubject, msgBody);
                    }
                }


                return(RedirectToAction("Index"));
            }
            ViewData["catId"] = categoryId;



            return(View(model));
        }