private void WriteChildForums(ForumsDetailsModel forums, string email)
        {
            var account = new AccountInfo();
            SetFullNameAndEmail();
            foreach (var forumItem in forums.SubForums)
            {
                var subscriptionModel = new Subscription()
                 {
                     CreatedBy = account.GetFullName(),
                     EmployeeEmail = account.GetEmailAddress(),
                     EmployeeName = account.GetUserName(), //User.Identity.Name.Replace("\\", "/"),
                     ForumName = forumItem.ForumFullPath,
                     IsActive = true,
                     IsDeleted = false,
                     IsSubscribed = true,
                     CreatedDate = DateTime.Now
                 };
                ForumSubscriptionService.InsertSubscription(subscriptionModel);

                if (forumItem.SubForums.Count > 0)
                    WriteChildForums(forumItem, email);
            }
        }
 private void SetFullNameAndEmail()
 {
     SetUserFullName();
     var account = new AccountInfo();
     if (String.IsNullOrEmpty(account.GetEmailAddress()))
         account.SetEmailAddress(SecurityService.GetLoggedInUserEmailAddress(account.GetUserName()));
 }
        private void WriteUpdateSubscription(string forumName, string email, string isSubscribed, bool subscribeParentOnly)
        {
            var account = new AccountInfo();
            SetFullNameAndEmail();

            #region Subscription database writing
            if (isSubscribed == "True")
            {
                var output = ConvertToForumDetailsListModel(ForumService.GetListofForums(forumName));
                var forum = new ForumsDetailsModel();
                forum.SubForums.AddRange(output);
                forum = null;
                var names = forumName.ForumSplit();
                foreach (var item in names)
                {
                    forum = (forum == null) ? output.FirstOrDefault(x => x.DisplayName == item) : forum.SubForums.FirstOrDefault(x => x.DisplayName == item);
                }

                var subscriptionModel = new Subscription()
                                        {
                                            CreatedBy = account.GetFullName(),
                                            EmployeeEmail = account.GetEmailAddress(),//email,
                                            EmployeeName = account.GetUserName(), //User.Identity.Name.Replace("\\", "/"),
                                            ForumName = forumName,
                                            IsActive = true,
                                            IsDeleted = false,
                                            IsSubscribed = true,
                                            CreatedDate = DateTime.Now
                                        };
                ForumSubscriptionService.InsertSubscription(subscriptionModel);
                if (!subscribeParentOnly)
                {
                    foreach (var forumItem in forum.SubForums)
                    {
                        subscriptionModel = new Subscription()
                        {
                            CreatedBy = account.GetFullName(),
                            EmployeeEmail = account.GetEmailAddress(),
                            EmployeeName = account.GetUserName(), //User.Identity.Name.Replace("\\", "/"),
                            ForumName = forumItem.ForumFullPath,
                            IsActive = true,
                            IsDeleted = false,
                            IsSubscribed = true,
                            CreatedDate = DateTime.Now
                        };
                        ForumSubscriptionService.InsertSubscription(subscriptionModel);

                        WriteChildForums(forumItem, email);
                    }
                }
                ForumSubscriptionService.SubscriptionRequestMail(forumName.ForumSplit().ForumJoin(), account.GetEmailAddress(), true);
            }
            #endregion

            #region un-Subscription database writing
            else if (isSubscribed == "False" && !subscribeParentOnly)
            {
                var output = ConvertToForumDetailsListModel(ForumService.GetListofForums(forumName));
                var forum = new ForumsDetailsModel();
                forum.SubForums.AddRange(output);
                forum = null;
                var names = forumName.ForumSplit();
                foreach (var item in names)
                {
                    forum = (forum == null) ? output.FirstOrDefault(x => x.DisplayName == item) : forum.SubForums.FirstOrDefault(x => x.DisplayName == item);
                }

                var subscriptionModel = new Subscription()
                {
                    CreatedBy = account.GetFullName(),
                    EmployeeEmail = account.GetEmailAddress(),
                    EmployeeName = account.GetUserName(), //User.Identity.Name.Replace("\\", "/"),
                    ForumName = forumName,
                    IsActive = true,
                    IsDeleted = false,
                    IsSubscribed = true,
                };
                subscriptionModel = ForumSubscriptionService.GetSubscriptions(subscriptionModel);
                if (subscriptionModel != null)
                {
                    subscriptionModel.IsActive = false;
                    subscriptionModel.IsDeleted = true;

                    ForumSubscriptionService.UpdateSubscription(subscriptionModel);
                }
                foreach (var forumItem in forum.SubForums)
                {
                    subscriptionModel = new Subscription()
                    {
                        CreatedBy = account.GetFullName(),
                        EmployeeEmail = account.GetEmailAddress(),
                        EmployeeName = account.GetUserName(), //User.Identity.Name.Replace("\\", "/"),
                        ForumName = forumItem.ForumFullPath,
                        IsActive = true,
                        IsDeleted = false,
                        IsSubscribed = true,
                    };
                    subscriptionModel = ForumSubscriptionService.GetSubscriptions(subscriptionModel);
                    if (subscriptionModel != null)
                    {
                        subscriptionModel.IsActive = false;
                        subscriptionModel.IsDeleted = true;

                        ForumSubscriptionService.UnsubscribeAllSubscriptions(subscriptionModel);
                    }
                    RemoveChildForums(forumItem);
                }
                ForumSubscriptionService.SubscriptionRequestMail(forumName.ForumSplit().ForumJoin(), account.GetEmailAddress(), false);
            }
            #endregion
        }
 private ForumsDetailsModel GetForumsDetailsModel(ForumsDetails forums)
 {
     var account = new AccountInfo();
     SetFullNameAndEmail();
     string imageFile = AppDomain.CurrentDomain.BaseDirectory + "/content/img/DefaultUser.png";
     var buffer = string.IsNullOrEmpty(forums.ProfileImgUrl) ? imageFile : forums.ProfileImgUrl;
     return new ForumsDetailsModel()
     {
         Name = forums.Name,
         DisplayName = forums.Name,
         LibraryName = forums.LibraryName,
         FolderPath = forums.FolderPath,
         Body = forums.Body,
         Id = forums.Id,
         CreatedBy = forums.CreatedBy,
         EditedBy = forums.EditedBy,
         CreatedDate = forums.CreatedDate,
         ParentFolderPath = forums.ParentFolderPath,
         TrimmedBody = forums.TrimmedBody,
         Replies = forums.Replies,
         LastUpdated = forums.LastUpdated,
         ModifiedDate = forums.ModifiedDate,
         ParentId = forums.ParentId,
         Permission = new SPPermissionModel() { CanAdd = forums.Permission.CanAdd },
         RootReply = forums.RootReply,
         Type = forums.Type,
         ProfileImgUrl = buffer,
         ForumFullPath = forums.ForumFullPath,
         EmployeeName = account.GetUserName(),  //User.Identity.Name,
         EmployeeEmail = account.GetEmailAddress(),
         IsSubscribed = false
     };
 }