Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
        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));
        }