//
        public ActionResult Comment(int id, string commentText)
        {
            if (Session["email"] != null)
            {
                using (BitBookContext db = new BitBookContext())
                {
                    string userEmail = "";
                    userEmail = Session["email"].ToString();

                    var user = db.Users.FirstOrDefault(x => x.Email.Equals(userEmail));



                    UserComment aUserComment = new UserComment();
                    aUserComment.PostId   = id;
                    aUserComment.UserId   = user.Id;
                    aUserComment.PostText = commentText;

                    db.UserComments.Add(aUserComment);
                    db.SaveChanges();

                    return(RedirectToAction("Home", "Registration"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
        //User list Who like the post
        public ActionResult WhoLike(int id)
        {
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();

                var userList = db.LikePosts.Where(x => x.PostId == id).ToList();

                ViewBag.Number = userList.Count();
                ViewBag.User   = userList.ToList();
                return(View());

                //string userEmail = "";
                //userEmail = Session["email"].ToString();

                //var user = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                //var userFriend = db.UserFriends.Where(p => p.UserId == user.Id
                //                                         && p.FriendId == aUser.Id).FirstOrDefault();
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
        //Add basic informations
        public ActionResult BasicInformation()
        {
            if (Session["email"] != null)
            {
                //Email already exist
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();

                var user = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                //check alread exist user
                if (db.BasicInfos.Any(x => x.UserId.Equals(user.Id)))
                {
                    //Update user Info.

                    return(RedirectToAction("Home", "Registration"));
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
        //Post a post
        public ActionResult PostContent(HttpPostedFileBase file)
        {
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();
                string postImage = null;
                var    user      = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();


                if (ModelState.IsValid)
                {
                    if (file != null)
                    {
                        if (file.ContentLength > 0)
                        {
                            //Cover Photo

                            postImage = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);

                            string physicalPath = System.IO.Path.Combine(Server.MapPath("~/Images/postImages"), postImage);

                            // save image in folder
                            file.SaveAs(physicalPath);
                        }
                    }

                    UserPost aUserPost = new UserPost();

                    aUserPost.PostText = Request.Form["PostText"];
                    aUserPost.UserId   = user.Id;
                    if (file != null)
                    {
                        aUserPost.ImageUrl = postImage;
                    }
                    aUserPost.CurrretTime = DateTime.Now;
                    db.UserPosts.Add(aUserPost);
                    db.SaveChanges();
                    return(RedirectToAction("Home", "Registration"));



                    return(RedirectToAction("Home", "Registration"));
                }
                return(RedirectToAction("Home", "Registration"));
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
Beispiel #5
0
        public bool IsEmailAleadyExist(string email)
        {
            bool isValidate = false;

            BitBookContext _db = new BitBookContext();

            if (_db.Users.Any(x => x.Email.Equals(email)))
            {
                isValidate = true;
            }

            return(isValidate);
        }
Beispiel #6
0
 public ActionResult IsEmailExist(string Email)
 {
     using (BitBookContext db = new BitBookContext())
     {
         try
         {
             var email = db.Users.Single(m => m.Email == Email);
             return(Json(false, JsonRequestBehavior.AllowGet));
         }
         catch (Exception)
         {
             return(Json(true, JsonRequestBehavior.AllowGet));
         }
     }
 }
Beispiel #7
0
        public ActionResult ChangeCover(HttpPostedFileBase file)
        {
            if (Session["email"] != null)
            {
                BitBookContext aBitBookContext = new BitBookContext();
                string         postImage       = null;
                if (ModelState.IsValid)
                {
                    if (file != null)
                    {
                        if (file != null)
                        {
                            if (file.ContentLength > 0)
                            {
                                //Cover Photo

                                postImage = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);

                                string physicalPath = System.IO.Path.Combine(Server.MapPath("~/Images/coverPic"), postImage);

                                // save image in folder
                                file.SaveAs(physicalPath);
                            }

                            string userEmail = null;
                            userEmail = Session["Email"].ToString();
                            var user = aBitBookContext.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                            var usr = aBitBookContext.BasicInfos.Where(x => x.UserId.Equals(user.Id)).FirstOrDefault();

                            usr.CoverPicUrl = postImage;
                            aBitBookContext.BasicInfos.Attach(usr);
                            aBitBookContext.Entry(usr).Property(x => x.CoverPicUrl).IsModified = true;
                            aBitBookContext.Configuration.ValidateOnSaveEnabled = false;

                            aBitBookContext.SaveChanges();
                            return(RedirectToAction("UserProfile", "Registration"));
                        }
                    }
                    return(RedirectToAction("Home", "Registration"));
                }
                return(RedirectToAction("Home", "Registration"));
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
        //Undfriend or cancel
        public ActionResult Unfriend(int friendId)
        {
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();
                //1stupdate
                var user = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                var userFriend = db.UserFriends.Where(p => p.UserId == user.Id &&
                                                      p.FriendId == friendId).FirstOrDefault();


                if (userFriend == null)
                {
                    return(RedirectToAction("Home", "Registration"));
                }
                else
                {
                    //userFriend.Friendstatus = 2;
                    //db.UserFriends.Attach(userFriend);
                    //db.Entry(userFriend).Property(x => x.Friendstatus).IsModified = true;
                    //db.Configuration.ValidateOnSaveEnabled = false;
                    db.UserFriends.Remove(userFriend);
                    db.SaveChanges();
                    //second update

                    var userFriend2 = db.UserFriends.Where(p => p.UserId == friendId &&
                                                           p.FriendId == user.Id).FirstOrDefault();


                    //userFriend2.Friendstatus = 2;
                    //db.UserFriends.Attach(userFriend2);
                    //db.Entry(userFriend2).Property(x => x.Friendstatus).IsModified = true;
                    //db.Configuration.ValidateOnSaveEnabled = false;
                    db.UserFriends.Remove(userFriend2);
                    db.SaveChanges();
                    db.SaveChanges();
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
Beispiel #9
0
        public bool SaveUserRegistraion(User aUser)
        {
            bool     isSaved = false;
            DateTime temp;

            if (aUser != null && aUser.FirstName != null && aUser.Email != null && aUser.Password != null && aUser.ConfirmPassword != null && aUser.Gender != null && DateTime.TryParse(aUser.DateOfBirth.ToString(), out temp))
            {
                BitBookContext _db = new BitBookContext();

                _db.Users.Add(aUser);
                int rowAffected = _db.SaveChanges();
                isSaved = rowAffected > 0;
            }

            return(isSaved);
        }
        //specific user profile
        public ActionResult Profile(int id)
        {
            if (Session["email"] != null)
            {
                //check that user id is exist
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();

                var userInfo = db.Users.FirstOrDefault(x => x.Email.Equals(userEmail));
                var user     = db.BasicInfos.FirstOrDefault(x => x.UserId.Equals(id));

                if (user != null && userInfo.Id != id)
                {
                    //if friend


                    //else not friend
                    ViewBag.UserInfo = user;
                }

                else
                {
                    return(RedirectToAction("UserProfile", "Registration"));
                }


                //BitBookContext db = new BitBookContext();

                //string userEmail = "";
                //userEmail = Session["email"].ToString();

                //var user = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                //var userInfo = db.BasicInfos.Where(x => x.UserId.Equals(user.Id)).FirstOrDefault();
                //ViewBag.UserInfo = userInfo;
                return(View());
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
 //Remove Post
 public ActionResult RemovePost(int id)
 {
     if (Session["email"] != null)
     {
         BitBookContext db        = new BitBookContext();
         string         userEmail = "";
         userEmail = Session["email"].ToString();
         //1stupdate
         var user      = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();
         var postState = db.UserPosts.Where(p => p.Id == id && p.UserId == user.Id).FirstOrDefault();
         db.UserPosts.Remove(postState);
         db.SaveChanges();
         return(RedirectToAction("Home", "Registration"));
     }
     else
     {
         return(RedirectToAction("Login", "Registration"));
     }
 }
        //Send Friend Request

        public ActionResult SendRequest(int friendId)
        {
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();

                var user       = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();
                var userFriend = db.UserFriends.Where(p => p.UserId == user.Id &&
                                                      p.FriendId == friendId).FirstOrDefault();
                //if own user

                if (user.Id == friendId || userFriend != null)
                {
                    return(RedirectToAction("UserProfile", "Registration"));
                }
                else
                {
                    UserFriend aUserFriend = new UserFriend();
                    aUserFriend.UserId       = user.Id;
                    aUserFriend.FriendId     = friendId;
                    aUserFriend.Friendstatus = 1;

                    db.UserFriends.Add(aUserFriend);
                    db.SaveChanges();

                    aUserFriend.UserId       = friendId;
                    aUserFriend.FriendId     = user.Id;
                    aUserFriend.Friendstatus = 3;

                    db.UserFriends.Add(aUserFriend);
                    db.SaveChanges();
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
        //User Profile
        //User Profile
        public ActionResult UserProfile()
        {
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();

                var user = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                var userInfo = db.BasicInfos.Where(x => x.UserId.Equals(user.Id)).FirstOrDefault();
                ViewBag.UserInfo = userInfo;
                return(View());
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
        //Frind Request
        public ActionResult RequestF()
        {
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();

                var user = db.Users.FirstOrDefault(x => x.Email.Equals(userEmail));

                var userFriend = db.UserFriends.Where(p => p.UserId == user.Id && p.Friendstatus == 3).ToList();
                ViewBag.Number = userFriend.Count();
                ViewBag.User   = userFriend.ToList();
                return(View());
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
Beispiel #15
0
        public ActionResult Login(LogViewModel lg)
        {
            if (ModelState.IsValid)
            {
                using (BitBookContext aBitBookContext = new BitBookContext())
                {
                    var log = aBitBookContext.Users.Where(a => a.Email.Equals(lg.Email) && a.Password.Equals(lg.Password)).FirstOrDefault();
                    if (log != null)
                    {
                        Session["email"] = log.Email;
                        return(RedirectToAction("UserHome", "UserRegistration"));
                    }

                    else
                    {
                        Response.Write("<script> alert('Invalid Password')</script>");
                    }
                }
            }
            return(View());
        }
        //Search action
        public ActionResult SearchUser(string searchTerm)
        {
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();
                List <User>    users;
                if (string.IsNullOrWhiteSpace(searchTerm))
                {
                    users = null;
                }
                else
                {
                    users = db.Users.Where(x => x.FirstName.StartsWith(searchTerm)).ToList();
                }

                return(View(users));
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
Beispiel #17
0
        public ActionResult ChangePassword(ChangePass changePass)
        {
            if (Session["Email"] != null)
            {
                if (ModelState.IsValid)
                {
                    using (BitBookContext aBitBookContext = new BitBookContext())
                    {
                        var log = aBitBookContext.Users.FirstOrDefault(a => a.Password.Equals(changePass.NewPassword));
                        if (log != null)
                        {
                            Response.Write("<script> alert('You entered same password')</script>");
                        }
                        else
                        {
                            string userEmail = null;
                            userEmail = Session["Email"].ToString();
                            var usr = aBitBookContext.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                            usr.Password = changePass.NewPassword;
                            aBitBookContext.Users.Attach(usr);
                            aBitBookContext.Entry(usr).Property(x => x.Password).IsModified = true;
                            aBitBookContext.Configuration.ValidateOnSaveEnabled             = false;

                            aBitBookContext.SaveChanges();

                            Response.Write("<script> alert('Password changed')</script>");
                            //return RedirectToAction("Home", "Registration");
                        }
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }

            return(View());
        }
        public ActionResult EditBasicInfo(BasicInfoViewModel aBasicInfoViewModel)
        {
            BitBookContext db        = new BitBookContext();
            string         userEmail = "";

            userEmail = Session["email"].ToString();

            var user = db.Users.FirstOrDefault(x => x.Email.Equals(userEmail));
            //save new record in database
            BasicInfo aBasicInfo = new BasicInfo();

            aBasicInfo                = db.BasicInfos.SingleOrDefault(x => x.UserId == user.Id);
            aBasicInfo.About          = aBasicInfoViewModel.About;
            aBasicInfo.AreaOfInterest = aBasicInfoViewModel.AreaOfInterest;
            aBasicInfo.Location       = aBasicInfoViewModel.Location;
            aBasicInfo.Education      = aBasicInfoViewModel.Education;
            aBasicInfo.Experience     = aBasicInfoViewModel.Experience;
            //Save in db
            db.BasicInfos.AddOrUpdate(aBasicInfo);
            db.SaveChanges();

            return(RedirectToAction("UserProfile", "Registration"));
        }
        //like a post

        public ActionResult LikeUserPost(int id)
        {
            if (Session["email"] != null)
            {
                using (BitBookContext db = new BitBookContext())
                {
                    string userEmail = "";
                    userEmail = Session["email"].ToString();

                    var user       = db.Users.FirstOrDefault(x => x.Email.Equals(userEmail));
                    var likeStatus = db.LikePosts.FirstOrDefault(a => a.UserId.Equals(user.Id) && a.PostId.Equals(id));
                    if (likeStatus == null)
                    {
                        LikePost aLikePost = new LikePost();
                        aLikePost.PostId      = id;
                        aLikePost.UserId      = user.Id;
                        aLikePost.CurrretTime = DateTime.Now;

                        db.LikePosts.Add(aLikePost);
                        db.SaveChanges();

                        return(RedirectToAction("Home", "Registration"));
                    }

                    else
                    {
                        Response.Write("<script> alert('You already like ')</script>");
                    }
                }
                return(RedirectToAction("Home", "Registration"));
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }
        public ActionResult Login(LogViewModel lg)
        {
            if (ModelState.IsValid)
            {
                using (BitBookContext aBitBookContext = new BitBookContext())
                {
                    var log = aBitBookContext.Users.FirstOrDefault(a => a.Email.Equals(lg.Email) && a.Password.Equals(lg.Password));
                    //var userInfoId = aBitBookContext.BasicInfos.FirstOrDefault(a => a.UserId == log.Id);
                    if (log != null)
                    {
                        Session["email"] = log.Email;


                        return(RedirectToAction("BasicInformation", "Registration"));
                    }

                    else
                    {
                        Response.Write("<script> alert('Invalid Email Or Password')</script>");
                    }
                }
            }
            return(View());
        }
Beispiel #21
0
        public ActionResult AddBasicInfo(HttpPostedFileBase file)
        {
            string userEmail = "";

            userEmail = Session["email"].ToString();
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();


                var user = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();
                ////var userId = db.BasicInformaionts.FirstOrDefault(x => x.UserId.Equals(user.Id));


                if (db.BasicInformaionts.Any(x => x.UserId.Equals(user.Id)))
                {
                    //Update user Info.

                    return(RedirectToAction("Display", "UserRegistration"));
                }
                else
                {
                    if (file != null)
                    {
                        //ProfilePic
                        string ProfilePicName      = System.IO.Path.GetFileName(file.FileName);
                        string physicalPathProfile = Server.MapPath("~/image/ProfilePic/" + ProfilePicName);

                        // save image in folder
                        file.SaveAs(physicalPathProfile);

                        //CoverPic
                        string CoverPicName      = System.IO.Path.GetFileName(file.FileName);
                        string physicalPathCover = Server.MapPath("~/image/CoverPic/" + CoverPicName);

                        // save image in folder
                        file.SaveAs(physicalPathCover);


                        //save new record in database
                        BasicInfo newRecord = new BasicInfo();
                        newRecord.AreaOfInterest  = Request.Form["AreaOfInterest"];
                        newRecord.Location        = Request.Form["Location"];
                        newRecord.Experience      = Request.Form["Experience"];
                        newRecord.Education       = Request.Form["Education"];
                        newRecord.UserId          = user.Id;
                        newRecord.ProfilePhotoUrl = ProfilePicName;


                        newRecord.CoverPhotoUrl = CoverPicName;
                        db.BasicInformaionts.Add(newRecord);
                        db.SaveChanges();
                        return(RedirectToAction("Display", "UserRegistration"));
                    }
                    else
                    {
                        return(RedirectToAction("AddBasicInfo", "UserRegistration"));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login", "UserRegistration"));
            }
        }
        //File and BasicInfo Upload
        public ActionResult BasicInfoUpload(IEnumerable <HttpPostedFileBase> files)
        {
            //Checked login
            if (Session["email"] != null)
            {
                BitBookContext db = new BitBookContext();

                string userEmail = "";
                userEmail = Session["email"].ToString();

                var user = db.Users.Where(x => x.Email.Equals(userEmail)).FirstOrDefault();

                //check alread exist user
                if (db.BasicInfos.Any(x => x.UserId.Equals(user.Id)))
                {
                    //Update user Info.

                    return(RedirectToAction("Home", "Registration"));
                }
                //else not exist
                else
                {
                    if (ModelState.IsValid)
                    {
                        if (files != null)
                        {
                            string coverImg   = null;
                            string profileImg = null;

                            IList <HttpPostedFileBase> list = (IList <HttpPostedFileBase>)files;



                            if (list[0] != null)
                            {
                                if (list[0].ContentLength > 0)
                                {
                                    //Cover Photo

                                    coverImg = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(list[0].FileName);

                                    string physicalPath = System.IO.Path.Combine(Server.MapPath("~/Images/coverPic"), coverImg);

                                    // save image in folder
                                    list[0].SaveAs(physicalPath);
                                }
                            }

                            if (list[1] != null)
                            {
                                if (list[1].ContentLength > 0)
                                {
                                    //Profile Photo

                                    profileImg = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(list[1].FileName);

                                    string physicalPathCover = System.IO.Path.Combine(Server.MapPath("~/images/profilePic"), profileImg);

                                    // save image in folder
                                    list[1].SaveAs(physicalPathCover);;
                                }
                            }
                            //User Id find

                            //save new record in database
                            BasicInfo aBasicInfo = new BasicInfo();
                            aBasicInfo.UserId         = user.Id;
                            aBasicInfo.CoverPicUrl    = coverImg;
                            aBasicInfo.ProfilePicUrl  = profileImg;
                            aBasicInfo.About          = Request.Form["About"];
                            aBasicInfo.AreaOfInterest = Request.Form["AreaOfInterest"];
                            aBasicInfo.Location       = Request.Form["Location"];
                            aBasicInfo.Education      = Request.Form["Education"];
                            aBasicInfo.Experience     = Request.Form["Experience"];
                            //Save in db
                            db.BasicInfos.Add(aBasicInfo);
                            db.SaveChanges();
                        }
                    }
                    //Update user Info
                }

                return(RedirectToAction("Home", "Registration"));
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }
        }