Ejemplo n.º 1
0
        public ActionResult Create(long?parentId, int categoryId = 1)
        {
            var model = new ForumFormModel();

            if (parentId.HasValue)
            {
                var parent = GetSession.Get <Forum>(parentId);
                model.ParentId      = parentId;
                model.ParentSubject = parent.Subject;
                model.Subject       = model.ParentSubject;
            }
            ViewData["catId"] = categoryId;

            ViewBag.list = GetSession.QueryOver <ForumItem>().List();
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult AutoCreate()
        {
            int categoryId = 1;


            var cats = GetSession.QueryOver <Forum>()
                       .OrderBy(x => x.CategoryId).Desc().List();

            List <int> categories = new List <int>();

            foreach (Forum forum in cats)
            {
                if (!categories.Contains(forum.CategoryId))
                {
                    categories.Add(forum.CategoryId);
                }
            }
            if (categories.Count() > 0)
            {
                categoryId = categories[0] + 1;
            }


            ForumFormModel model = new ForumFormModel()
            {
                Body          = "פורום חדש",
                CategoryTitle = "פורום חדש",
                Subject       = "פורום חדש",
                CategoryId    = categoryId
            };

            var item = Mapper.Map <ForumFormModel, Forum>(model);

            item.CreatedBy = new Employee
            {
                Id = GetEmployeeId
            };
            ViewData["catId"] = categoryId;
            GetSession.Save(item);

            return(RedirectToAction("List", new { categoryId = categoryId }));
        }
Ejemplo n.º 3
0
        public ActionResult AutoCreate()
        {
            int categoryId = 1;
          

            var cats = GetSession.QueryOver<Forum>()
            .OrderBy(x => x.CategoryId).Desc().List();

            List<int> categories = new List<int>();

            foreach (Forum forum in cats)
            {
                if (!categories.Contains(forum.CategoryId))
                    categories.Add(forum.CategoryId);
            }
            if (categories.Count() > 0)
                categoryId = categories[0]+1;
              

            ForumFormModel model = new ForumFormModel()
            {
                Body = "פורום חדש",
                CategoryTitle = "פורום חדש",
                Subject = "פורום חדש",
                CategoryId = categoryId
            };

            var item = Mapper.Map<ForumFormModel, Forum>(model);
            item.CreatedBy = new Employee
            {
                Id = GetEmployeeId
            };
            ViewData["catId"] = categoryId;
            GetSession.Save(item);

            return RedirectToAction("List", new { categoryId = categoryId });
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public ActionResult Create(long? parentId, int categoryId = 1)
        {
            var model = new ForumFormModel();

            if (parentId.HasValue)
            {
                var parent = GetSession.Get<Forum>(parentId);
                model.ParentId = parentId;
                model.ParentSubject = parent.Subject;
                model.Subject = model.ParentSubject;
            }
            ViewData["catId"] = categoryId;

            ViewBag.list = GetSession.QueryOver<ForumItem>().List();
            return View(model);
        }
Ejemplo n.º 6
0
        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));
        }