public UserViewModel(User user)
 {
     this.Id = user.Id;
     this.UserName = user.UserName;
     this.Age = user.Age;
     this.Sex = user.Sex;
 }
        public UserProfileViewModel(User user,
            ICollection<Tweet> tweets,
            ICollection<User> followers,
            ICollection<User> following,
            ICollection<Tweet> favorites)
        {
            this.User = new UserViewModel(user);
            this.Tweets = new HashSet<TweetViewModel>();
            foreach (var tweet in tweets)
            {
                this.Tweets.Add(new TweetViewModel(tweet));
            }

            this.Followers = new HashSet<UserViewModel>();
            foreach (var follower in followers)
            {
                this.Followers.Add(new UserViewModel(follower));
            }

            this.Following = new HashSet<UserViewModel>();
            foreach (var followed in following)
            {
                this.Following.Add(new UserViewModel(followed));
            }

            this.Favorites = new HashSet<TweetViewModel>();
            foreach (var tweet in favorites)
            {
                this.Favorites.Add(new TweetViewModel(tweet));
            }
        }
        protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
        {
            if (requestContext.HttpContext.User.Identity.IsAuthenticated)
            {
                var username = requestContext.HttpContext.User.Identity.Name;
                var user = this.Data.Users.All().FirstOrDefault(x => x.UserName == username);
                this.UserProfile = user; // set user to UserProfile
            }

            return base.BeginExecute(requestContext, callback, state);
        }
示例#4
0
		async void Tweet()
		{
			var id = await twitter.Tweet(Text);
			if (!String.IsNullOrEmpty(id))
			{
				Tweets.Insert(0, new TweetContent(id, Text, MySelf));
				MySelf = new User(MySelf.Name, MySelf.Image, MySelf.TweetCount + 1);
				Status = "ツイートを送信しました";
			}
			else
			{
				Status = "ツイートに失敗しました";
			}
			Text = "";
		}
        public ActionResult EditDetails(string username, User userData)
        {
            var currentUserData = this.Data.Users.All()
                .Where(u => u.UserName == username)
                .FirstOrDefault();
            if (currentUserData == null)
            {
                return this.HttpNotFound();
            }

            if (ModelState.IsValid)
            {
                currentUserData.FullName = userData.FullName != null ? userData.FullName : currentUserData.FullName;
                currentUserData.Email = userData.Email != null ? userData.Email : currentUserData.Email;
                currentUserData.AvatarUrl = userData.AvatarUrl != null ? userData.AvatarUrl : currentUserData.AvatarUrl;
                currentUserData.PhoneNumber = userData.PhoneNumber != null ? userData.PhoneNumber : currentUserData.PhoneNumber;
                currentUserData.ContactInfo = userData.ContactInfo != null ? userData.ContactInfo : currentUserData.ContactInfo;
                this.Data.SaveChanges();
            }

            return this.View(currentUserData);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = new User { UserName = model.UserName, Email = model.Email, FullName = model.FullName };
                var result = await this.UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await this.SignInManager.SignInAsync(user, false, false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    return this.RedirectToAction("Index", "Home");
                }

                this.AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return this.View(model);
        }
        public async Task<ActionResult> ExternalLoginConfirmation(
            ExternalLoginConfirmationViewModel model,
            string returnUrl)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                return this.RedirectToAction("Index", "Manage");
            }

            if (this.ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await this.AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return this.View("ExternalLoginFailure");
                }
                var user = new User { UserName = model.Email, Email = model.Email };
                var result = await this.UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await this.UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await this.SignInManager.SignInAsync(user, false, false);
                        return this.RedirectToLocal(returnUrl);
                    }
                }
                this.AddErrors(result);
            }

            this.ViewBag.ReturnUrl = returnUrl;
            return this.View(model);
        }
示例#8
0
文件: Twitter.cs 项目: achukun/CSharp
		public TweetContent(string id, string text, User user)
		{
			this.id = id;
			this.text = text;
			this.user = user;
		}
 public ActionResult Home(User user)
 {
     return View(user);
 }
 protected BaseController(ITwitterData data, User userProfile)
     : this(data)
 {
     this.UserProfile = userProfile;
 }