Example #1
0
 public void AddComment(Comment comment)
 {
     try
     {
         _shipperHndBcontext.Comments.Add(comment);
         _shipperHndBcontext.SaveChanges();
     }
     catch (Exception e)
     {
         _logControl.AddLog(1, "CommentBusiness.cs/AddComment", "Type: " + e.GetType()
                            + " | Message: " + e.Message + " | InnerException: " +
                            e.InnerException);
     }
 }
Example #2
0
        public User GetUser(FacebookClient fc, string userid)
        {
            if (_shipperHndBcontext.Users.FirstOrDefault(x => x.Id.Equals(userid)) != null)
            {
                return(_shipperHndBcontext.Users.FirstOrDefault(x => x.Id.Equals(userid)));
            }
            string  userFetch = fc.Get(userid + "?fields=picture,name").ToString();
            JObject jsonUser  = JObject.Parse(userFetch);
            User    user      = new User
            {
                UserId = (string)jsonUser["id"],
                Name   = (string)jsonUser["name"],
                LatestViewNotificationTime = DateTime.Now
            };

            try
            {
                _shipperHndBcontext.Users.Add(user);
                _shipperHndBcontext.SaveChanges();
            }
            catch (Exception e)
            {
                _logControl.AddLog(0, "PostBusiness.cs/AddPosts", "Type: " + e.GetType()
                                   + " | Message: " + e.Message + " | InnerException: " + e.InnerException);
            }
            return(user);
        }
Example #3
0
        public List <JObject> GetJsonData(string dataFetch)
        {
            List <JObject> jos = new List <JObject>();

            try
            {
                if (dataFetch == "")
                {
                    return(jos);
                }
                JObject o = JObject.Parse(dataFetch);
                for (int i = 0; i < o["data"].Count(); i++)
                {
                    if (o["data"][i]["message"] == null && o["data"][i]["from"] != null)
                    {
                        jos.Add(JObject.Parse(o["data"][i].ToString()));
                    }
                    else
                    {
                        var jToken = o["data"][i]["message"];
                        if (jToken != null && (jToken.ToString().Length < 1000 && o["data"][i]["from"] != null))
                        {
                            jos.Add(JObject.Parse(o["data"][i].ToString()));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logControl.AddLog(1, "FetchData.cs/GetJsonData", "Type: " + e.GetType()
                                   + " | Message: " + e.Message + " | InnerException: " +
                                   e.InnerException);
                Thread.Sleep(1000);
            }
            return(jos);
        }
Example #4
0
 public void AddPosts(List <Post> posts)
 {
     foreach (Post post in posts)
     {
         try
         {
             _shipperHNDBcontext.Posts.Add(post);
             _shipperHNDBcontext.SaveChanges();
         }
         catch (Exception e)
         {
             if (e.GetType() == typeof(DbUpdateException))
             {
                 _logControl.AddLog(0, "PostBusiness.cs/AddPosts", "Type: " + e.GetType()
                                    + " | Message: " + e.Message + " | InnerException: " + e.InnerException);
                 _shipperHNDBcontext.Posts.Remove(post);
             }
         }
     }
 }
        public void GetPhone(Match match, User user)
        {
            PhoneNumber pn = new PhoneNumber
            {
                Phone = match.ToString()
            };

            try
            {
                if (user.PhoneNumbers.FirstOrDefault(y => y.Phone.Equals(pn.Phone)) == null)
                {
                    user.PhoneNumbers.Add(pn);
                    _shipperHndBcontext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                _logControl.AddLog(1, "PhoneNumberBusiness.cs/GetPhone",
                                   "Type: " + e.GetType() + " | Message: " + e.Message + " | InnerException: " + e.InnerException);
            }
        }
Example #6
0
        public string AddPosts(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return("Error: Empty data!");
            }

            try
            {
                JObject json = JObject.Parse(data);
                foreach (var jToken in json["list_posts"])
                {
                    string user_fullname = jToken["user_fullname"].ToString();
                    string user_picture  = jToken["user_picture"].ToString();
                    string user_url      = jToken["user_url"].ToString();
                    string user_id       = jToken["user_id"].ToString();
                    string message       = jToken["message"].ToString();
                    string post_id       = jToken["post_id"].ToString();
                    string full_picture  = jToken["full_picture"].ToString();

                    if (string.IsNullOrEmpty(user_url) ||
                        string.IsNullOrEmpty(message) ||
                        string.IsNullOrEmpty(post_id) ||
                        message.Length < 20
                        )
                    {
                        continue;
                    }
                    string check = message.Length >= 50 ? message.Substring(0, 50) : message;
                    if (_shipperHndBcontext.Posts.FirstOrDefault(x => x.PostId.Equals(post_id)) == null &&
                        _shipperHndBcontext.Posts.FirstOrDefault(x => x.Message.Contains(check)) == null)
                    {
                        User user;
                        if (!string.IsNullOrEmpty(user_id) && _shipperHndBcontext.Users.FirstOrDefault(x => x.UserId.Equals(user_id)) == null ||
                            string.IsNullOrEmpty(user_id) && _shipperHndBcontext.Users.FirstOrDefault(x => x.UserProfileUrl.Equals(user_url)) == null)
                        {
                            user = _shipperHndBcontext.Users.Add(new User
                            {
                                UserId             = user_id,
                                UserProfilePicture = user_picture,
                                Name           = user_fullname,
                                UserProfileUrl = user_url
                            });
                            try
                            {
                                _shipperHndBcontext.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                _logControl.AddLog(1, "AddPosts", ex.Message);
                                // ignored
                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(user_id))
                            {
                                user = _shipperHndBcontext.Users
                                       .Include(t => t.PhoneNumbers)
                                       .FirstOrDefault(t => t.UserProfileUrl.Equals(user_url));
                            }
                            else
                            {
                                user = _shipperHndBcontext.Users
                                       .Include(t => t.PhoneNumbers)
                                       .FirstOrDefault(t => t.UserId.Equals(user_id));
                            }
                        }

                        List <Location> locations = _postBusiness.DectectLocation(message);

                        List <Match> matches = _phoneNumberBusiness.DetetectPhoneNumber(message);
                        if (matches != null && matches.Count > 0)
                        {
                            foreach (Match match in matches)
                            {
                                _phoneNumberBusiness.GetPhone(match, user);
                            }
                        }

                        List <Location> addLocations = new List <Location>();
                        foreach (var location in locations)
                        {
                            addLocations.Add(_shipperHndBcontext.Locations.Add(location));
                        }

                        try
                        {
                            _shipperHndBcontext.SaveChanges();
                        }
                        catch (Exception exception)
                        {
                            _logControl.AddLog(1, "AddPosts", exception.Message);
                            continue;
                        }

                        Post post = new Post
                        {
                            PostId      = post_id,
                            Message     = message,
                            User        = user,
                            Locations   = addLocations,
                            CreatedTime = DateTime.Now,
                            FullPicture = full_picture
                        };

                        _shipperHndBcontext.Posts.Add(post);

                        try
                        {
                            _shipperHndBcontext.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            _logControl.AddLog(1, "AddPosts", e.Message);
                            // ignored
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logControl.AddLog(1, "AddPosts", e.Message);
                return(e.Message);
            }

            return("Success");
        }