public static UserViewModel Create(ApplicationUser targetUser, ApplicationUser loggedUser)
        {
            return new UserViewModel
            {

            };
        }
Example #2
0
        protected override IAsyncResult BeginExecute(RequestContext requestContext,AsyncCallback callback,object state)
        {
            this.UserProfile =
                this.TwitterData.ApplicationUsers.All()
                .FirstOrDefault(u => u.UserName == requestContext.HttpContext.User.Identity.Name);

            return base.BeginExecute(requestContext, callback, state);
        }
 //        public static Expression<Func<ApplicationUser, ProfileDataPreviewViewModel>> Create
 //        {
 //            get {
 //                return u => new ProfileDataPreviewViewModel
 //                {
 //                    Username = u.UserName,
 //                    Fullname = u.Fullname,
 //                    Gender = u.Gender,
 //                    ProfileImageData = u.ProfileImageData,
 //                };
 //            }
 //        }
 public static ProfileDataPreviewViewModel Create(ApplicationUser targetUser, ApplicationUser loggedUser)
 {
     return new ProfileDataPreviewViewModel
     {
         Id = targetUser.Id,
         Username = targetUser.UserName,
         Fullname = targetUser.Fullname,
         Gender = targetUser.Gender,
         ProfileImageData = targetUser.ProfileImageData,
         IsFollowing = targetUser.Followers.Any(f => f.Id == loggedUser.Id)
     };
 }
        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 ApplicationUser { 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);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Username, Email = model.Email };
                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> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a local login before signing in the user
                var user = new ApplicationUser {UserName = model.UserName };
                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                string fileName = null;
                // check the avatar
                if (file != null && file.ContentLength > 0)
                {
                    string extension = Path.GetExtension(file.FileName.ToString())
                                        .Trim().ToLower();
                    if (extension == ".png" || extension == ".jpg")
                    {
                        fileName = Guid.NewGuid() + "_"
                                        + file.FileName.ToString();
                        file.SaveAs(Server.MapPath("~/Content/Avatars/" + fileName));
                    }
                }
                // Create a local login before signing in the user
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                    Avatar = fileName
                };

                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);

                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 //        public static Expression<Func<ApplicationUser, ProfileDataViewModel>> Create {
 //            get {
 //                return u => new ProfileDataViewModel
 //                {
 //                    UserName = u.UserName,
 //                    Fullname = u.Fullname,
 //                    Email = u.Email,
 //                    Gender = u.Gender,
 //                    ProfileImageData = u.ProfileImageData,
 //                    CoverImageData = u.CoverImageData,
 //                    IsFollowing = false
 //                };
 //            }
 //        }
 public static ProfileDataViewModel Create(ApplicationUser targetUser, ApplicationUser loggedUser)
 {
     return new ProfileDataViewModel
         {
             Id = targetUser.Id,
             Username = targetUser.UserName,
             Fullname = targetUser.Fullname,
             Email = targetUser.Email,
             Gender = targetUser.Gender,
             ProfileImageData = targetUser.ProfileImageData,
             CoverImageData = targetUser.CoverImageData,
             TweetsCount = targetUser.OwnTweets.Count,
             FollowingUsersCount = targetUser.FollowedFriends.Count,
             FollowersCount = targetUser.Followers.Count,
             FavoritesCount = targetUser.FavoritesTweets.Count,
             IsFollowing = targetUser.Followers.Any(f => f.Id == loggedUser.Id)
         };
 }
 public static TweetViewModel CreateView(Tweet t, ApplicationUser loggedUser)
 {
     return new TweetViewModel
     {
         Id = t.Id,
         Content = t.Content,
         Author = new UserViewModel
         {
             Username = t.Author.UserName,
             Fullname = t.Author.Fullname,
             ProfileImageData = t.Author.ProfileImageData
         },
         WallOwner = new UserViewModel
         {
             Username = t.WallOwner.UserName,
             Fullname = t.WallOwner.Fullname,
             ProfileImageData = t.WallOwner.ProfileImageData
         },
         PostedOn = t.PostedOn,
         RepliesCount = t.Replies.Count,
         FavoritesCount = t.Favorites.Count,
         IsFavorited = t.Favorites.Any(),
         Replies = t.Replies
             .OrderByDescending(r => r.PostedOn)
             .Take(3)
             .Select(r => new ReplyViewModel
             {
                 Id = r.Id,
                 Content = r.Content,
                 Author = new UserViewModel
                 {
                     Username = r.Author.UserName,
                     Fullname = r.Author.Fullname,
                     ProfileImageData = r.Author.ProfileImageData
                 },
                 PostedOn = r.PostedOn
             })
     };
 }