예제 #1
0
        // GET: Profile
        public ActionResult Index(Guid? id)
        {
            User user = new User();
            if (id == null)
            {
                Guid UserID = new Guid(User.Identity.Name);

                user = db.Users.Find(UserID);
                
            }
            else
            {
                user = db.Users.Find(id);
            }
            ProfileModel profile = new ProfileModel();
            profile.UserID = user.UserID;
            profile.Surname = user.Surname;
            profile.Name = user.Name;
            profile.Email = user.Email;
            profile.ProfilePicture = user.ProfilePicture;

            List<Article> article = db.Articles.Where(x => x.UserID == profile.UserID).ToList();
            int countShare = 0;
            foreach (var item in article)
            {
                List<Share> share = db.Shares.Where(x => x.ArticleID == item.ArticleID).ToList();
                countShare = countShare + share.Count();
            }
            profile.NumArticles = article.Count();
            profile.NumShared = countShare;
            return View(profile);

        }
예제 #2
0
        public ActionResult Register(UserRegModel register)
        {
            if (ModelState.IsValid)
            {

                User user = new Knowledgeable.User();
                user = db.Users.Where(x => x.Email == register.Email).FirstOrDefault();
                if(user == null)
                {
                    user = new User();
                    user.UserID = Guid.NewGuid();
                    user.Email = register.Email;



                    user.Name = register.Name;
                    user.Surname = register.Surname;

                    string salt = BCrypt.Net.BCrypt.GenerateSalt(4);
                    string hashed1 = BCrypt.Net.BCrypt.HashPassword(register.Password, salt);
                    string hashed2 = BCrypt.Net.BCrypt.HashPassword(register.Password, hashed1);


                    user.Salt = salt;
                    user.Password = hashed2;
                    user.Active = false;

                    db.Users.Add(user);
                    db.SaveChanges();
                    

                    string name = register.Name;
                    string Subject = "Email Confirmation";
                    string mailContent = "<p>Thank you for your registration. Click on the link below to confirm your account.</p> <a href=\"http://localhost:23060/Login/EmailConfirmed/" + user.UserID + "\">Click Here</a>";

                    Utility.SendMail(name, user.Email, Subject, mailContent);

                    return RedirectToAction("ConfirmEmail");


                }
                else
                {
                    ViewBag.Error = "Email already exists.";
                    return View();

                }

            }
            return View();
        }
예제 #3
0
        // GET: Comment
        public PartialViewResult LoadComment(Guid id)
        {
            Guid UserID = new Guid(User.Identity.Name);


            List<Comment> comment = db.Comments.Where(x => x.ArticleID == id).OrderBy(x => x.DatePosted).ToList();
            List<CommentModel> commentModel = new List<CommentModel>();
            foreach(var item in comment)
            {
                List<SubComment> subComment = db.SubComments.Where(x => x.CommentID == item.CommentID).OrderBy(x => x.DatePosted).ToList();
                List<SubCommentModel> subCommentModel = new List<SubCommentModel>();
                User user = new User();
                string name;
                string ProfilePicture;
                foreach (var sub in subComment)
                {
                    user = db.Users.Find(sub.UserID);
                    name = user.Name + " " + user.Surname;
                    ProfilePicture = user.ProfilePicture;

                    subCommentModel.Add(new SubCommentModel
                    {

                        CommentID = sub.CommentID,
                        DatePosted = sub.DatePosted,
                        DownVote = sub.DownVote,
                        SubComment1 = sub.SubComment1,
                        SubCommentID = sub.CommentID,
                        UpVote = sub.UpVote,
                        UserID = sub.UserID,
                        userName = name,
                        ProfilePicture = ProfilePicture
                    });
                }

                user = db.Users.Find(item.UserID);
                name = user.Name + " " + user.Surname;
                ProfilePicture = user.ProfilePicture;

                commentModel.Add(new CommentModel
                {
                    ArticleID = item.ArticleID,
                    UserID = item.UserID,
                    userName = name,
                    ProfilePicture = ProfilePicture,
                    Comment1 = item.Comment1,
                    CommentID = item.CommentID,
                    DatePosted = item.DatePosted,
                    DownVote = item.DownVote,
                    UpVote = item.UpVote,
                    listSubcomment = subCommentModel
                });

            }

            return PartialView("_LoadComment", commentModel);
        }