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 void InsertUserInfo(Users userInfo)
        {
            // this is the time this user is created and the first/last access
            userInfo.CreationDate = DateTime.Now;
            userInfo.LastAccessDate = userInfo.CreationDate;

            using (var webClient = new WebClient())
            {
                // appDataFolder is the place where profile pictures from LinkedIn are stored
                // appDataFolder location = "web application dir" / image_store"
                string picturesFolder = "image_store";
                string fileName = "";
                string profilePictureFilePath = "";

                DiskDataAccess.ProfilePicturePath(userInfo, picturesFolder, out fileName, out profilePictureFilePath);

                try
                {
                    // all LinedIn profile picture files are jpg files
                    webClient.DownloadFile(userInfo.PicLocation, profilePictureFilePath);
                    userInfo.PicLocation = "../" + "image_store" + "/" + fileName;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            User user = Mapper.Map<Users, User>(userInfo);
            _dataContext.Users.InsertOnSubmit(user);
            _dataContext.SubmitChanges();
        }
Beispiel #3
0
        /// <summary>
        /// Generate the file path where the profile picture of a new user will be saved in the disk
        /// </summary>
        /// <param name="userInfo">Users object of the new user</param>
        /// <param name="picturesFolder">Name of the picture folder</param>
        /// <param name="fileName">out: unique name of the file</param>
        /// <param name="profilePictureFilePath">out: path where to save new file</param>
        internal static void ProfilePicturePath(Users userInfo, string picturesFolder, out string fileName,
            out string profilePictureFilePath)
        {
            string picDataFolder = Path.Combine(HttpContext.Current.Server.MapPath(@"~/"), picturesFolder);

            string url = userInfo.PicLocation;

            Byte[] hashCode = (new SHA1Managed()).ComputeHash(Encoding.UTF8.GetBytes(url));
            var hashStringB = new StringBuilder();

            foreach (byte b in hashCode)
            {
                hashStringB.Append(b.ToString());
            }

            fileName = hashStringB.ToString();
            fileName += ".jpg";
            profilePictureFilePath = Path.Combine(picDataFolder, fileName);
        }
Beispiel #4
0
 public void TestInsertUser()
 {
     string userUniqueId = Guid.NewGuid().ToString().Substring(0, 18);
     var user = new Users
                    {
                        DisplayName = "John Fowler",
                        CreationDate = DateTime.Now,
                        Reputation = 100,
                        Downvotes = 12,
                        Upvotes = 11,
                        LastAccessDate = DateTime.Now,
                        PicLocation = String.Empty,
                        PublicProfileUrl = String.Empty,
                        UserUniqueid = userUniqueId,
                        SessionKey = Guid.NewGuid(),
                        Views = 120
                    };
     _userDataAccess.InsertUserInfo(user);
     Assert.IsNotNull(_userDataAccess.GetUserInfo(userUniqueId));
 }
Beispiel #5
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();
            }
        }
        public void ProfilePicturePathTest()
        {
            Users userInfo = new Users
                                 {
                                     CreationDate = null,
                                     DisplayName = "Roshan Dhananajaya",
                                     Downvotes = 0,
                                     Id = 0,
                                     LastAccessDate = null,
                                     PicLocation = string.Empty, // TODO: fill this up

                                 }; // TODO: Initialize to an appropriate value
            string picturesFolder = "image_store";
            string fileName = string.Empty; // generated by function
            string fileNameExpected = "794440113172189291352261931191312262321647247122116246.jpg";
            string profilePictureFilePath = string.Empty; // generated by function
            string profilePictureFilePathExpected =
                @"D:\WorkDir\DoitShareit\DoitShareIt.git\trunk\DSH.Main.Web\image_store\794440113172189291352261931191312262321647247122116246.jpg";

            DiskDataAccess.ProfilePicturePath(userInfo, picturesFolder, out fileName, out profilePictureFilePath);
            Assert.AreEqual(fileNameExpected, fileName);
            Assert.AreEqual(profilePictureFilePathExpected, profilePictureFilePath);
            //            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Beispiel #7
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 #8
0
        public Users UpdateUser(Users user)
        {
            var id = user.Id;
            var dbUser = from u in _dataContext.Users
                         where u.UserUniqueid == user.UserUniqueid
                         select u;
            if(dbUser.Count()>1) throw new UniqueUserViolationXception("There exist more than one user with the given user unique id");
            else if (!dbUser.Any()) throw new Exception("no user exists with given unique user id for update");
            else
            {
                dbUser.ToList()[0].DisplayName = user.DisplayName;
                dbUser.ToList()[0].CreationDate = user.CreationDate;
                dbUser.ToList()[0].Reputation = user.Reputation;
                dbUser.ToList()[0].DownVotes = user.Downvotes;
                dbUser.ToList()[0].UpVotes = user.Upvotes;
                dbUser.ToList()[0].LastAccessDate = user.LastAccessDate;
                dbUser.ToList()[0].PicLocation = user.PicLocation;
                dbUser.ToList()[0].PublicProfileUrl = user.PublicProfileUrl;
                dbUser.ToList()[0].UserUniqueid = user.UserUniqueid;
                dbUser.ToList()[0].SessionKey = user.SessionKey;
                dbUser.ToList()[0].Views = user.Views;

                _dataContext.SubmitChanges();
                return Mapper.Map<User, Access.DataModels.Users>(dbUser.ToArray()[0]);
            }
        }