Example #1
0
        public void SchedulePost(string postIds)
        {
            PostManager mgr = new PostManager();
            mgr.SchedulePost(Convert.ToInt64(postIds), null);

            var obj = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<HeyVoteHub>();
            new PostManager().GetNotificationUserList(postIds).ForEach(x =>
            {
                var signalR = HeyVoteHub.MyUsers.Where(y => y.Value.Equals(x.NotifyUserIdf)).FirstOrDefault();
                if (!signalR.Equals(default(KeyValuePair<string, string>)))
                    obj.Clients.Client(signalR.Key).notifyUsers(new
                    {
                        Id = x.Id,
                        Title = x.Title,
                        UserIdf = x.UserIdf,
                        ImageIdf = x.ImageIdf,
                        Image1Idf = x.Image1Idf,
                        FolderPath = x.FolderPath,
                        CreatedOn = x.CreatedOn,
                        Caption1 = x.Caption1,
                        Caption2 = x.Caption2,
                        DisplayName = x.DisplayName,
                        PostId = x.PostId,
                        EndDate = x.EndDate
                    });
            });
        }
Example #2
0
 public bool Vote(long postId, bool voteOption, bool isWeb)
 {
     try
     {
         PostManager mgr = new PostManager();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.Vote(postId, tokenInfo.Idf, voteOption, tokenInfo.TerritoryId);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Example #3
0
 public List<NotificationInfo> GetNotificationByUser(int pageId, int pageSize, bool isWeb)
 {
     try
     {
         PostManager mgr = new PostManager();
         HelperMethods helperMgr = new HelperMethods();
         var userIdf = helperMgr.GetUserIdf(isWeb, HttpContext.Current);
         return mgr.GetNotificationByUser(userIdf, pageId, helperMgr.SetPageSize(pageSize, isWeb));
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Example #4
0
 public List<PostInfo> GetPostListByTerritoryId(int pageId, int pageSize, int territoryId, bool isWeb)
 {
     try
     {
         PostManager mgr = new PostManager();
         HelperMethods helperMgr = new HelperMethods();
         TokenInfo tokenInfo = helperMgr.GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.GetPostListByTerritoryId(tokenInfo.Idf, tokenInfo.FolderPath, pageId, helperMgr.SetPageSize(pageSize, isWeb), territoryId == 0 ? tokenInfo.TerritoryId : territoryId);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Example #5
0
        public string AddPost(PostInfo info, ResourceInfo resource1Info, ResourceInfo resource2Info, List<ContactInfo> lstContacts, bool isPicture, bool isVideo, bool isAudio, bool isWeb)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(info.Title) && !String.IsNullOrWhiteSpace(info.Caption1) && !String.IsNullOrWhiteSpace(info.Caption2)
                     && !String.IsNullOrWhiteSpace(resource1Info.DataUrl) && info.Duration >= 5 && info.Duration <= 60
                     && (info.IsPublic == true || info.ToContacts == true || (info.ToSelectedContacts == true && lstContacts.Count > 0))
                     && (info.TerritoryId != null || info.IsGlobal == true) && (isPicture || isVideo || isAudio) && (info.CategoryId == 1 || info.CategoryId == 2 || info.CategoryId == 3))
                {
                    PostManager mgr = new PostManager();

                    TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);

                    resource1Info.Data = JsonWebToken.Base64UrlDecode(resource1Info.DataUrl);

                    if (resource2Info != null && !String.IsNullOrWhiteSpace(resource2Info.DataUrl))
                        resource2Info.Data = JsonWebToken.Base64UrlDecode(resource2Info.DataUrl);

                    // Sets user token from cookie
                    info.UserIdf = tokenInfo.Idf;
                    info.EndDate = DateTime.UtcNow.AddMinutes(info.Duration);

                    if (info.IsPublic)
                    {
                        info.ToContacts = false;
                        info.ToSelectedContacts = false;
                    }
                    else if (info.ToContacts)
                    {
                        info.ToSelectedContacts = false;
                        info.IsPublic = false;
                    }
                    else if (info.ToSelectedContacts)
                    {
                        info.IsPublic = false;
                        info.ToContacts = false;
                    }

                    if (isPicture)
                    {
                        isVideo = false;
                        isAudio = false;
                    }
                    else if (isVideo)
                    {
                        isPicture = false;
                        isAudio = false;
                    }
                    else if (isAudio)
                    {
                        isVideo = false;
                        isPicture = false;
                    }

                    EnumPostType postType = isPicture ? EnumPostType.Picture : (isVideo ? EnumPostType.Video : (isAudio ? EnumPostType.Audio : EnumPostType.Picture));

                    var guids = mgr.AddPostImages(resource1Info, resource2Info, tokenInfo.FolderPath, postType);
                    long postId = mgr.AddPost(info, guids[0], guids[1], postType, tokenInfo.FolderPath);
                    if (info.ToSelectedContacts)
                    {
                        List<ContactInfo> lstFilteredContacts = new List<ContactInfo>();
                        ContactManager conMgr = new ContactManager();
                        lstContacts.ForEach(x =>
                        {
                            if (!String.IsNullOrWhiteSpace(x.ContactToken))
                            {
                                try
                                {
                                    TokenInfo contactToken = JsonWebToken.DecodeToken<TokenInfo>(x.ContactToken, CodeHelper.SecretAccessKey, true, false);
                                    x.ContactIdf = contactToken.Idf;
                                    lstFilteredContacts.Add(x);
                                }
                                catch (Exception)
                                {
                                    // if contact does not have all details, ignore it
                                }
                            }

                        });
                        conMgr.SavePostContacts(info.UserIdf, info.TerritoryId, info.IsGlobal, postId, lstFilteredContacts);
                    }

                    // schedule job
                    mgr.SchedulePost(postId, info.EndDate);

                    // send notification to all users either GCM or SignalR stating your contact has posted something
                    var obj = GlobalHost.ConnectionManager.GetHubContext<HeyVoteHub>();
                    new PostManager().GetNotificationUserList(postId.ToString()).ForEach(x =>
                    {
                        var signalR = HeyVoteHub.MyUsers.Where(y => y.Value.Equals(x.NotifyUserIdf)).FirstOrDefault();
                        if (!signalR.Equals(default(KeyValuePair<string, string>)))
                            obj.Clients.Client(signalR.Key).notifyUsers(new
                            {
                                Id = x.Id,
                                Title = x.Title,
                                UserIdf = x.UserIdf,
                                ImageIdf = x.ImageIdf,
                                Image1Idf = x.Image1Idf,
                                FolderPath = x.FolderPath,
                                CreatedOn = x.CreatedOn,
                                Caption1 = x.Caption1,
                                Caption2 = x.Caption2,
                                DisplayName = x.DisplayName,
                                PostId = x.PostId,
                                EndDate = x.EndDate,
                                isPost = x.isPost,
                                isFollow = x.isFollow,
                                isContact = x.isContact,
                                hasRead = false,
                                isViewed = false
                            });
                    });

                    return true.ToString();
                }
                return false.ToString();
            }
            catch (Exception ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }
Example #6
0
 public List<PostInfo> GetContactPostsList(string contactToken, int pageId, int pageSize, bool isWeb)
 {
     try
     {
         PostManager mgr = new PostManager();
         HelperMethods helperMgr = new HelperMethods();
         TokenInfo tokenInfo = helperMgr.GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.GetContactPostsList(tokenInfo.Idf, JsonWebToken.DecodeToken<TokenInfo>(contactToken, CodeHelper.SecretAccessKey, true, false).Idf, tokenInfo.TerritoryId, tokenInfo.FolderPath, pageId, helperMgr.SetPageSize(pageSize, isWeb));
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Example #7
0
 public bool DeletePost(long postId, bool isWeb)
 {
     try
     {
         PostManager mgr = new PostManager();
         HelperMethods helperMgr = new HelperMethods();
         TokenInfo tokenInfo = helperMgr.GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.DeletePost(tokenInfo.Idf, postId);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Example #8
0
 public bool ChangeNotificationStatus(long notificationId, bool isWeb)
 {
     try
     {
         PostManager mgr = new PostManager();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.ChangeNotificationStatus(tokenInfo.Idf, notificationId);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Example #9
0
 public List<CommentInfo> GetComments(long postId, int pageId, int pageSize, bool isWeb)
 {
     try
     {
         CommentManager mgr = new CommentManager();
         HelperMethods helperMgr = new HelperMethods();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         PostInfo post = new PostManager().GetPostById(tokenInfo.Idf, 0, tokenInfo.FolderPath, postId);
         if (post.isDone == true)
             return mgr.GetComments(tokenInfo.Idf, postId, pageId, helperMgr.SetPageSize(pageSize, isWeb));
         else
             return mgr.GetOwnComments(tokenInfo.Idf, postId, pageId, helperMgr.SetPageSize(pageSize, isWeb));
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }