Exemple #1
0
        public IActionResult OnGet()
        {
            string tmp = HttpContext.Session.GetString("userId");

            if (tmp == "" || tmp == null)
            {
                return(Redirect("/SignIn"));
            }
            userId            = Convert.ToInt32(tmp);
            user              = _db.Users.Find(userId);
            iuniversity       = user.university;
            ihighSchool       = user.highSchool;
            ijuniorHighSchool = user.juniorHighSchool;
            iprimarySchool    = user.primarySchool;
            ihobbyMusic       = user.hobbyMusic;
            ihobbyBook        = user.hobbyBook;
            ihobbyMovie       = user.hobbyMovie;
            ihobbyGame        = user.hobbyGame;
            ihobbyAnime       = user.hobbyAnime;
            ihobbySport       = user.hobbySport;
            ihobbyOther       = user.hobbyOther;
            irealName         = user.realName;
            igender           = user.gender;
            ibirthday         = user.birthday;
            ihometown         = user.hometown;
            iemail            = user.email;
            imobile           = user.mobile;
            return(Page());
        }
        public IActionResult OnGet()
        {
            // 获取用户 ID
            int id = -1;
            IEnumerator <KeyValuePair <string, StringValues> > enumerator = HttpContext.Request.Query.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <string, StringValues> single = enumerator.Current;
                if (single.Key == "id")
                {
                    id = single.Value.ToString() != null?Convert.ToInt32(single.Value.ToString()) : 0;
                }
            }
            if (id > 0)
            {
                // 获取用户个人资料
                user = _db.Users.Find(id);
                if (user != null)
                {
                    WelcomeMessage = user.userName;
                    StudySchool    = user.university != null ? user.university : "未知的学校";
                    Email          = user.email;
                    imgUrl         = user.Avatar;
                    Department     = user.Department;
                    Description    = "你太懒了,还没有写个人简介哦!";   // TODO
                    Comments       = new List <string>(); // TODO
                    return(Page());
                }
            }
            // 获取用户 ID
            string tmp = HttpContext.Session.GetString("userId");

            if (tmp == "" || tmp == null)
            {
                return(Redirect("/SignIn"));
            }
            userId         = Convert.ToInt32(tmp);
            user           = _db.Users.Find(userId);
            WelcomeMessage = user.userName;
            StudySchool    = user.university != null ? user.university : "未知的学校";
            Email          = user.email;
            imgUrl         = user.Avatar;
            Department     = user.Department;
            Description    = "你太懒了,还没有写个人简介哦!";   // TODO
            Comments       = new List <string>(); // TODO
            return(Page());
        }
Exemple #3
0
        public IActionResult OnGet(int shareId)
        {
            // 获取 share
            Entities.Home.Status status = Context.Statuses.Find(shareId);
            if (status == null)
            {
                return(Redirect("/"));
            }
            Share = new Entities.Home.Share();
            Share.ShareContent = status.Content;
            Share.ID           = status.ID;
            Entities.Home.User user = Context.Users.SingleOrDefault(s => s.ID == status.UserID);
            Share.Username     = user.userName;
            Share.UserId       = user.ID;
            Share.Avatar       = user.Avatar;
            Share.like         = status.Like;
            Share.commentCount = Context.Comments.Where(s => s.StatusID == status.ID).Count();
            Share.Time         = status.Time.ToString();

            // 获取评论
            IQueryable <Comment> commentsQuery = from c in Context.Comments
                                                 where c.StatusID == Share.ID
                                                 select c;

            Comments = new List <CommentVo>();
            foreach (var comment in commentsQuery)
            {
                // 获取评论源头用户资讯
                Entities.Home.User commentByUser = Context.Users.Find(comment.UserId);
                if (commentByUser == null)
                {
                    continue;
                }
                CommentVo vo = new CommentVo(comment);
                vo.Username = commentByUser.userName;
                vo.Avatar   = commentByUser.Avatar;
                Comments.Add(vo);
            }

            return(Page());
        }
Exemple #4
0
        public IActionResult OnPost()
        {
            IEnumerator <KeyValuePair <string, StringValues> > enumerator = Request.Form.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <string, StringValues> single = enumerator.Current;
                if (single.Key == "userName")
                {
                    userName = single.Value.ToString();
                }
                if (single.Key == "userPass")
                {
                    userPass = single.Value.ToString();
                }
            }
            try
            {
                var userList = from u in _db.Users
                               where u.userName == userName
                               select u;
                Entities.Home.User user = userList.First();
                if (user != null && user.password == userPass)
                {
                    HttpContext.Session.Clear();
                    HttpContext.Session.Set("userId", System.Text.Encoding.Default.GetBytes(user.ID.ToString()));
                    HttpContext.Session.Set("userName", System.Text.Encoding.Default.GetBytes(user.userName));
                }

                if (user.type == 100)
                {
                    return(Redirect("/Examine/Examine"));
                }

                return(Redirect("/Homepage/UserHome"));
            }
            catch
            {
                return(Redirect("/SignIn"));
            }
        }
Exemple #5
0
        public IActionResult OnPost()
        {
            Entities.Home.User newUser = new Entities.Home.User();
            IEnumerator <KeyValuePair <string, StringValues> > enumerator = Request.Form.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <string, StringValues> single = enumerator.Current;
                if (single.Key == "userName")
                {
                    userName = single.Value.ToString();
                }
                if (single.Key == "userPass")
                {
                    userPass = single.Value.ToString();
                }
                if (single.Key == "userPassAgain")
                {
                    userPassAgain = single.Value.ToString();
                }
            }
            if (userPass != userPassAgain)
            {
                return(Content("Á½´ÎÃÜÂë²»Ò»ÖÂ"));
            }
            newUser.userName = userName;
            newUser.password = userPass;
            newUser.type     = 1;
            newUser.state    = 0;
            try
            {
                _db.Users.Add(newUser);
                _db.SaveChanges();
                _db.Entry(newUser);
                return(Redirect("/SignIn"));
            }
            catch
            {
                return(Redirect("/SignUp"));
            }
        }
        public IActionResult OnGet([FromQuery] string userId)
        {
            if (userId == null)
            {
                return(Redirect("/"));
            }
            int id = int.Parse(userId);

            // 获取用户资讯
            Entities.Home.User user = _db.Users.Find(id);
            if (user == null)
            {
                return(Redirect("/"));
            }
            Name        = user.userName;
            StudySchool = user.university != null ? user.university : "未知的学校";
            imgUrl      = user.Avatar;
            Department  = user.Department;
            Description = "他太懒了,还没有写个人简介哦!"; // TODO
            return(Page());
        }
Exemple #7
0
        public void OnGet()
        {
            int size = 10;             // todo

            IEnumerable <Entities.Home.Status> statusesIE = Context.Statuses.ToList();
            List <Entities.Home.Status>        statuses   = new List <Entities.Home.Status>();

            if (statuses.Count() < size)
            {
                statuses = statusesIE.ToList();
            }
            else
            {
                statuses = statusesIE.ToList().GetRange(0, size);
            }

            List <Share> shares = new List <Share>();

            foreach (Entities.Home.Status status in statuses)
            {
                Share share = new Share();
                share.ShareContent = status.Content;
                share.ID           = status.ID;
                Entities.Home.User user = Context.Users.SingleOrDefault(s => s.ID == status.UserID);
                share.Username     = user.userName;
                share.UserId       = user.ID;
                share.Avatar       = user.Avatar;
                share.like         = status.Like;
                share.commentCount = Context.Comments.Where(s => s.StatusID == status.ID).Count();
                share.Time         = status.Time.ToLongTimeString();

                shares.Add(share);
            }

            this.Shares = shares;
        }
Exemple #8
0
 public UserInfoModel(MyContext db)
 {
     _db  = db;
     user = _db.Users.Find(userId);
 }
Exemple #9
0
        public IActionResult OnPost()
        {
            user = _db.Users.Find(Convert.ToInt32(HttpContext.Session.GetString("userId")));
            IEnumerator <KeyValuePair <string, StringValues> > enumerator = Request.Form.GetEnumerator();

            while (enumerator.MoveNext())
            {
                KeyValuePair <string, StringValues> single = enumerator.Current;
                if (single.Key == "iuniversity")
                {
                    user.university = single.Value.ToString();
                }
                if (single.Key == "ihighSchool")
                {
                    user.highSchool = single.Value.ToString();
                }
                if (single.Key == "ijuniorHighSchool")
                {
                    user.juniorHighSchool = single.Value.ToString();
                }
                if (single.Key == "iprimarySchool")
                {
                    user.primarySchool = single.Value.ToString();
                }
                if (single.Key == "ihobbyMusic")
                {
                    user.hobbyMusic = single.Value.ToString();
                }
                if (single.Key == "ihobbyBook")
                {
                    user.hobbyBook = single.Value.ToString();
                }
                if (single.Key == "ihobbyMovie")
                {
                    user.hobbyMovie = single.Value.ToString();
                }
                if (single.Key == "ihobbyGame")
                {
                    user.hobbyGame = single.Value.ToString();
                }
                if (single.Key == "ihobbyAnime")
                {
                    user.hobbyAnime = single.Value.ToString();
                }
                if (single.Key == "ihobbySport")
                {
                    user.hobbySport = single.Value.ToString();
                }
                if (single.Key == "ihobbyOther")
                {
                    user.hobbyOther = single.Value.ToString();
                }
                if (single.Key == "irealName")
                {
                    user.realName = single.Value.ToString();
                }
                if (single.Key == "igender")
                {
                    user.gender = single.Value.ToString() != null?Convert.ToInt32(single.Value.ToString()) : 0;
                }
                if (single.Key == "ibirthday")
                {
                    DateTime           dt;
                    DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
                    dtFormat.ShortDatePattern = "yyyy-MM-dd";
                    dt            = Convert.ToDateTime(single.Value.ToString(), dtFormat);
                    user.birthday = dt;
                }
                if (single.Key == "ihometown")
                {
                    user.hometown = single.Value.ToString();
                }
                if (single.Key == "iemail")
                {
                    user.email = single.Value.ToString();
                }
                if (single.Key == "imobile")
                {
                    user.mobile = single.Value.ToString();
                }
            }
            try
            {
                _db.Users.Update(user);
                _db.SaveChanges();
                return(Redirect("/Homepage/UserInfo"));
            }
            catch
            {
                return(Redirect("/Homepage/UserInfo"));
            }
        }