コード例 #1
0
ファイル: LinkedIn.cs プロジェクト: tiptrace/Share
 public void LoadUser(string UserHash)
 {
     Db.UserSource usersource = (from item in db.UserSources where item.User.Hash == UserHash && item.SourceTypeId == 2 select item).FirstOrDefault();
     _oauth.Token       = usersource.Token;
     _oauth.TokenSecret = usersource.TokenSecret;
     _oauth.Verifier    = usersource.Verifier;
 }
コード例 #2
0
ファイル: Email.cs プロジェクト: tiptrace/Share
        public List <Target> getContacts(string UserHash)
        {
            List <Target> output = new List <Target>();


            Db.UserSource usersource = (from item in db.UserSources where item.User.Hash == UserHash && item.SourceTypeId == 6 select item).FirstOrDefault();


            var EmailList = (from item in db.Shares where item.ShareSession.UserId == usersource.UserId && item.TargetTypeId == 6 select new { item.TargetId, item.TargetName }).Distinct();


            foreach (var item in EmailList)
            {
                output.Add(new Target {
                    Identifier = item.TargetId, Name = item.TargetName, ProfilePicure = string.Empty, SourceType = 6, Network = "Email"
                });
            }

            return(output);
        }
コード例 #3
0
ファイル: Google.cs プロジェクト: tiptrace/Share
 public string GetAccessTokenFromDatabase(string UserHash)
 {
     Db.UserSource usersource = (from item in db.UserSources where item.User.Hash == UserHash && item.SourceTypeId == 3 select item).FirstOrDefault();
     return(usersource.Token);
 }
コード例 #4
0
ファイル: DefaultController.cs プロジェクト: tiptrace/Share
        public ActionResult Index(Web.Models.Share share)
        {
            bool   WithFacebookShare = false;
            string Response          = string.Empty;
            //process the Userhash if email is send
            string EmailIdentifier = share.ManualEmail;
            string EmailName       = share.ManualName;

            if (!string.IsNullOrEmpty(EmailIdentifier) && !string.IsNullOrEmpty(EmailName))
            {
                Db.User EmailUser = db.ProcessToken(this.UserHash, 6, EmailIdentifier, EmailName, EmailIdentifier, string.Empty, string.Empty, string.Empty).FirstOrDefault();
                this.UserHash = EmailUser.Hash;
            }

            //Save the session, and get the sharesessionId
            int?ShareSessionId = db.SaveShareSession(this.UserHash, share.Url.Id, share.ClientHash, share.Message).FirstOrDefault();
            int ShareCounter   = 0;

            List <string> UrlCodes = db.GetUniqueUrlCodes(share.Targets.Count()).ToList();

            if (ShareSessionId.HasValue)
            {
                foreach (Target item in share.Targets.Take(10))
                {
                    Db.Share DbShare = new Db.Share();

                    try
                    {
                        string ShortUrl = String.Format("http://link.tiptrace.com/{0}", UrlCodes[ShareCounter].ToString());

                        //store in DB
                        DbShare.TargetTypeId   = item.SourceType;
                        DbShare.TargetId       = item.Identifier;
                        DbShare.TargetName     = item.Name;
                        DbShare.DateAdded      = DateTime.Now;
                        DbShare.ShareSessionId = ShareSessionId.Value;
                        DbShare.ShortUrl       = UrlCodes[ShareCounter].ToString();


                        if (item.SourceType == 1) //facebook
                        {
                            Facebook.Postmessage(this.UserHash, item.Identifier, share.Message, share.Url, ShortUrl);
                            WithFacebookShare = true;
                            //throw new Exception("FOUT!!");
                        }
                        if (item.SourceType == 2) //linkedin
                        {
                            Response = LinkedIn.Postmessage(this.UserHash, item.Identifier, share.Message, share.Url, ShortUrl);
                        }
                        if (item.SourceType == 5) //twitter
                        {
                            Response = Twitter.Postmessage(this.UserHash, item.Identifier, share.Message, share.Url, ShortUrl);
                        }
                        if (item.SourceType == 3 || item.SourceType == 4) //Google || Hotmail
                        {
                            //Get the name of the sharer
                            Db.UserSource Source = (from usersource in db.UserSources where usersource.User.Hash == this.UserHash && usersource.SourceTypeId == item.SourceType select usersource).FirstOrDefault();

                            //Load and parse the template
                            string EmailTemplate = getEmailTemplate(share.ClientHash);
                            string EmailContent  = EmailTemplate.Replace("{SourceName}", Source.Name);
                            EmailContent = EmailContent.Replace("{SourceEmail}", Source.Identifier);
                            EmailContent = EmailContent.Replace("{TargetName}", item.Name);
                            EmailContent = EmailContent.Replace("{TargetEmail}", item.Identifier);
                            EmailContent = EmailContent.Replace("{Link}", string.Format("<a href='{0}'>{1}</a>", ShortUrl, share.Url.Value));
                            EmailContent = EmailContent.Replace("{Message}", share.Message);

                            Utility.Email.SendEmail(Source.Identifier, Source.Name, item.Identifier, item.Name, string.Format("Tip from {1}: {0}", share.Url.Title, Source.Identifier), EmailContent);
                        }
                        if (item.SourceType == 6) //email
                        {
                            //Load and parse the template
                            string EmailTemplate = getEmailTemplate(share.ClientHash);
                            string EmailContent  = EmailTemplate.Replace("{SourceName}", EmailName);
                            EmailContent = EmailContent.Replace("{SourceEmail}", EmailIdentifier);
                            EmailContent = EmailContent.Replace("{TargetName}", item.Name);
                            EmailContent = EmailContent.Replace("{TargetEmail}", item.Identifier);
                            EmailContent = EmailContent.Replace("{Link}", string.Format("<a href='{0}'>{1}</a>", ShortUrl, share.Url.Value));
                            EmailContent = EmailContent.Replace("{Message}", share.Message);

                            //Send the email
                            Utility.Email.SendEmail(EmailIdentifier, EmailName, item.Identifier, item.Name, string.Format("Tip from {1}: {0}", share.Url.Title, EmailIdentifier), EmailContent);
                        }

                        DbShare.ShareStatusID = 1;
                        share.Status          = "succes";
                    }
                    catch (Exception ex)
                    {
                        DbShare.ShareStatusID = 2;
                        DbShare.ShareStatus   = ex.Message + "" + Response;
                        share.Status          = "failed" + ex.Message;
                    }
                    finally
                    {
                        db.Shares.AddObject(DbShare);
                    }


                    ShareCounter++;
                }
                db.SaveChanges();

                share.ShareSessionId = ShareSessionId.Value;

                if (WithFacebookShare)
                {
                    Facebook.CloseChatConnection();
                }
            }

            return(Json(share, JsonRequestBehavior.AllowGet));
        }