Beispiel #1
0
        public ActionResult Login(Users login)
        {
            Session["id"] = login.UserUniqueid;
            Session["userurl"] = login.PublicProfileUrl;
            Session["userfname"] = login.DisplayName;
            Session["userpic"] = login.PicLocation;

            #region

            /*          fake data to login for testing with out a internet connnectoin
            Session["id"] = "szaF9K6odR";
            Session["userurl"] = "http://www.linkedin.com/in/roshandhananajaya";
            Session["userfname"] = "Roshan Dhananajaya";
            Session["userpic"] = "its getting it from the database coz im not  a new user";
            */

            #endregion

            var current = new UserDataAccess();
            Users thisUser = current.GetUserInfo(Session["id"].ToString());
            if (thisUser == null)
            {
                current.InsertUserInfo(login);
            }

            return Json(login);
        }
Beispiel #2
0
        public JsonResult Searchuser(string searchText)
        {
            List<Users> searchUser = new List<Users>();
            UserDataAccess current = new UserDataAccess();
            searchUser = current.MatchUser(searchText, 5);

            return Json(searchUser, JsonRequestBehavior.AllowGet);
        }
        public List<Access.DataModels.Comment> GetComments(int postId)
        {
            var comments = from c in _dataContext.Posts
                           where c.ParentId == postId
                           select c;

            var result = new List<Access.DataModels.Comment>();
            var querry = comments.ToList();
            var userDataAccess = new UserDataAccess();
            for (int i = 0; i < querry.Count(); i++)
            {
                var p = Mapper.Map<Post, Access.DataModels.Comment>(querry[i]);
                p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
                result.Add(p);
            }
            return result;
        }
Beispiel #4
0
        public ActionResult FrequentUser()
        {
            var userDataAccess = new UserDataAccess();
            var userId = (string) Session["id"];

            Users thisUserInfo = userDataAccess.GetUserInfo(userId);

            var frequentUserList = (new UserFrequency()).FrequentUsers(thisUserInfo.Id);

            //          List<UserFrequency> ResultList = userDataAccess.

            return Json(new
                            {
                                Status = "SUCCESS",
                                Result = frequentUserList
                            }, JsonRequestBehavior.AllowGet);
        }
Beispiel #5
0
        public ActionResult GetUser(int id)
        {
            try
            {
                var userDataAccess = new UserDataAccess();
                Users user = userDataAccess.GetUser(id);

                return Json(new
                                {
                                    Status = "SUCCESS",
                                    Result = Json(user)
                                }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return Json(new
                                {
                                    Status = "FAILED",
                                    Result = ""
                                }, JsonRequestBehavior.AllowGet);
            }
        }
Beispiel #6
0
        public List<Access.DataModels.Post> GetNewPosts(int postType,string time)
        {
            if (postType == 0)
            {
                var posts = from p in _dataContext.Posts
                            where
                                p.PostTypeId != (int) Access.DataModels.PostTypes.Comment && p.IsAnonymous == false &&
                                p.LastActivityDate > Convert.ToDateTime(time)
                            select p;

                var result = new List<Access.DataModels.Post>();
                var querry = posts.ToList();
                UserDataAccess userDataAccess = new UserDataAccess();
                for (int i = 0; i < querry.Count(); i++)
                {
                    var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]);
                    p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
                    result.Add(p);
                }
                return result;
            }
            else if ((_dataContext.PostTypes.Any(row => row.Id == postType) != true)) throw new InvalidPostTypeTypeXception("the given post type does not exist");
            else
            {
                var posts = from p in _dataContext.Posts
                            where p.PostTypeId == postType && p.IsAnonymous == false && p.LastActivityDate > Convert.ToDateTime(time)
                            select p;
                var result = new List<Access.DataModels.Post>();
                var querry = posts.ToList();
                var userDataAccess = new UserDataAccess();
                for (int i = 0; i < querry.Count(); i++)
                {
                    var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]);
                    p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
                    result.Add(p);
                }
                return result;
            }
        }
Beispiel #7
0
        public ActionResult Create(Users user)
        {
            try
            {
                // Creat new user in database

                // todo: validate

                // putting new user to database with linq
                var userDataAccess = new UserDataAccess();
                userDataAccess.InsertUserInfo(user);

                return Json(new
                                {
                                    //  after creating new user in database return something from here
                                }, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                // return a "Coudn't create new user" message
                return View();
            }
        }
Beispiel #8
0
 public PostController()
 {
     _postDataAccess = new PostDataAccess();
     _userDataAccess = new UserDataAccess();
 }
Beispiel #9
0
        public JsonResult Userprofile(string id)
        {
            Users me = new Users();
            var current = new UserDataAccess();

                me = (id == null) ? current.GetUserInfo(Session["id"].ToString()) : current.GetUserInfo(id);

            return Json(me);
        }
Beispiel #10
0
        public ActionResult GetUserPicUrl(int id)
        {
            try
            {
                var userDataAccess = new UserDataAccess();
                string url = userDataAccess.GetUserPicUrl(id);

                return Json(new
                                {
                                    Status = "SUCCESS",
                                    Result = url
                                }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return Json(new
                                {
                                    Status = "FAILED",
                                    Result = ""
                                }, JsonRequestBehavior.AllowGet);
            }
        }
Beispiel #11
0
        public List<DSH.Access.DataModels.Post> GetUserPosts(string userUniqeId)
        {
            // Return Post of the paritculer user whos UniqeId is provided
            var userDataAccess = new UserDataAccess();
            var user = userDataAccess.GetUserInfo(userUniqeId);

            var userPost = from post in _dataContext.Posts
                           where post.OwnerUserId == user.Id && post.PostTypeId != (int)Access.DataModels.PostTypes.Comment && post.IsAnonymous==false
                           orderby post.LastActivityDate descending
                           select post;
            return Mapper.Map<List<DSH.DataAccess.Post>, List<DSH.Access.DataModels.Post>>((List<Post>) userPost.ToList().Take(10));
        }
Beispiel #12
0
        public ActionResult UserInfo(string id)
        {
            // todo: get the user info using the *id* and return the approprieate userInfo json object

            var userDataAccess = new UserDataAccess();
            Users users = userDataAccess.GetUserInfo(id);

            return Json(new
                            {
                                // todo: code code code .............
                                user_info = users
                            }, JsonRequestBehavior.AllowGet);
        }
Beispiel #13
0
        public ActionResult Index()
        {
            var userDataAccess = new UserDataAccess();
            var userId = (string) Session["id"];

            Users userInfo = userDataAccess.GetUserInfo(userId);

            return Json(new
                            {
                                userInfo.Reputation,
                                userInfo.CreationDate,
                                userInfo.DisplayName,
                                userInfo.Views,
                                userInfo.Upvotes,
                                userInfo.Downvotes,
                                userInfo.PublicProfileUrl
                            }, JsonRequestBehavior.AllowGet);
        }
Beispiel #14
0
 public VoteController()
 {
     _postDataAccess = new PostDataAccess();
     _userDataAccess = new UserDataAccess();
     _voteDataAccess = new VoteDataAccess();
 }
Beispiel #15
0
 public Access.DataModels.Post GetPost(int postId)
 {
     var post = _dataContext.Posts.Single(p => p.Id == postId);
     if (post == null)
     {
         throw new InvalidPostIdXception("there esist no post with the given post id");
     }
     else
     {
         var p = Mapper.Map<Post, Access.DataModels.Post>(post);
         UserDataAccess userDataAccess = new UserDataAccess();
         p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
         return p;
     }
 }
 public CommentController()
 {
     _commentDataAccess = new CommentDataAccess();
     _userDataAccess = new UserDataAccess();
 }
Beispiel #17
0
        //public List<Access.DataModels.Post> GetMorePosts(int postType,int startIndex,int maxAmount)
        //{
        //}
        public List<Access.DataModels.Post> GetPosts(int postType,int taggedUserId,int maxAmount, bool includeAnonymous=false)
        {
            if (postType == 0)
            {
                if(includeAnonymous)
                {
                    var posts = from p in _dataContext.Posts
                                where p.PostTypeId != (int)Access.DataModels.PostTypes.Comment && p.TaggedUserId==taggedUserId
                                orderby p.LastActivityDate descending
                                select p;
                    var result = new List<Access.DataModels.Post>();
                    var querry = posts.ToList();
                    var userDataAccess = new UserDataAccess();
                    for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++)
                    {
                        var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]);
                        p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
                        result.Add(p);
                    }
                    return result;
                }else
                {
                    var posts = from p in _dataContext.Posts
                                where p.PostTypeId != (int)Access.DataModels.PostTypes.Comment && p.IsAnonymous==false && p.TaggedUserId == taggedUserId
                                orderby p.LastActivityDate descending
                                select p;
                    var result = new List<Access.DataModels.Post>();
                    var querry = posts.ToList();
                    var userDataAccess = new UserDataAccess();
                    for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++)
                    {
                        var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]);
                        p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
                        result.Add(p);
                    }
                    return result;
                }

            }
            else if ((_dataContext.PostTypes.Any(row => row.Id == postType) != true)) throw new InvalidPostTypeTypeXception("the given post type does not exist");
            else
            {

                if(includeAnonymous)
                {
                    var posts = from p in _dataContext.Posts
                                where p.PostTypeId == postType && p.TaggedUserId == taggedUserId
                                orderby p.LastActivityDate descending
                                select p;
                    var result = new List<Access.DataModels.Post>();
                    var querry = posts.ToList();
                    var userDataAccess = new UserDataAccess();
                    for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++)
                    {
                        var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]);
                        p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
                        result.Add(p);
                    }
                    return result;
                }else
                {
                    var posts = from p in _dataContext.Posts
                                where p.PostTypeId == postType && p.IsAnonymous == false && p.TaggedUserId==taggedUserId
                                orderby p.LastActivityDate descending
                                select p;
                    var result = new List<Access.DataModels.Post>();
                    var querry = posts.ToList();
                    var userDataAccess = new UserDataAccess();
                    for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++)
                    {
                        var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]);
                        p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId);
                        result.Add(p);
                    }
                    return result;
                }
            }
        }