示例#1
0
 public bool AddItemToRoot(ForumItem item)
 {
     if (item == null)
         return false;
     AllItems.Add(item);
     return true;
 }
示例#2
0
        private bool AddItem(ForumItem toAdd, List<ForumItem> current)
        {
            if (current == null || toAdd == null)
                return false;

            foreach (ForumItem item in current)
            {
                if (item.ID == toAdd.PerentId)
                {
                    if (item.SubItems == null)
                        item.SubItems = new List<ForumItem>();
                    item.SubItems.Add(toAdd);
                    return true;
                }
                if(AddItem(toAdd, item.SubItems))
                    return true;
            }
            return false;
        }
示例#3
0
        public static bool AddNewForumItem(string sessionId, int userId, ForumItem item)
        {
            try
            {
                int result = new DataAccess(ConnectionString).ExecuteNonQuerySP("SP_AddNewForumItem",
                        "@SessionID", sessionId,
                        "@UserID", userId,
                        "@CourseID", item.CourseId,
                        "@Title", item.Title,
                        "@Content", item.Content,
                        "@ParentID", item.PerentId);

                return result > 0;
            }
            catch (Exception)
            {
                return false;
            }
        }
示例#4
0
 public bool AddItemByPerantID(ForumItem item)
 {
     if (item.PerentId == -1)
         return AddItemToRoot(item);
     return AddItem(item, AllItems);
 }
示例#5
0
 public bool AddNewForumItem(string sessionId, int userId, ForumItem item)
 {
     return CMDal.AddNewForumItem(sessionId, userId, item);
 }
示例#6
0
        public static Forum GetCourseForum(string sessionId, int userId, int courseId)
        {
            Forum forum = new Forum();
            try
            {
                DataTable table = new DataAccess(ConnectionString).ExecuteQuerySP("SP_GetCourseForum",
                        "@SessionID", sessionId,
                        "@UserID", userId,
                        "@CourseID", courseId);

                if (table == null || table.Rows.Count == 0)
                    return forum;
                foreach (DataRow row in table.Rows)
                {
                    int id, perrentId, rate, rUsers;
                    ParseCellDataToInt(row["Id"], out id);
                    ParseCellDataToInt(row["Rate"], out rate);
                    ParseCellDataToInt(row["RatingUsers"], out rUsers);
                    ParseCellDataToInt(row["RootId"], out perrentId);
                    ForumItem fi = new ForumItem();
                    fi.Title = ParseCellDataToString(row["Title"]);
                    fi.Content = ParseCellDataToString(row["Content"]);
                    fi.OwnerName = ParseCellDataToString(row["UserName"]);
                    fi.ID = id;
                    if (rate == 0 && rUsers == 0)
                        fi.Rate = -1;
                    else
                        fi.Rate = ((double)rate / rUsers);
                    fi.PerentId = perrentId;
                    fi.TimeAdded = ParseCellDataToDateTime(row["TimeAdded"]);
                    forum.AddItemByPerantID(fi);
                }
                return forum;
            }
            catch (Exception)
            {
                return forum;
            }
        }
 /// <summary>
 /// Send email notification when new fourm item submited.
 /// </summary>
 /// <param name="sendTo">The user list that will get the email.</param>
 /// <param name="fi">the FourmItem propertise</param>
 /// <param name="courseName">The course name that the FourmItem was submited.</param>
 public static void SendQandANotification(List<User> sendTo, ForumItem fi, string courseName)
 {
     if (fi == null)
         return;
     foreach (User user in sendTo)
     {
         if (user != null)
         {
             string template = GetEmailTamplateByType(EmailType.QAndA);
             template = string.Format(template, user.UserName, fi.OwnerName, courseName, fi.Title, fi.Content);
             SendMail(user.Email, "Fourm update at " + courseName, template);
         }
     }
 }