public static IEnumerable<ApplicationUserViewModel> ApplicationUserToViewModel(ApplicationUser me, IEnumerable<ApplicationUser> users)
        {
            var vUsers = new List<ApplicationUserViewModel>();
            foreach (var user in users)
            {
                var vUser = AutoMapper.Mapper.Map<ApplicationUser, ApplicationUserViewModel>(user);
                var isMyFriend = me.Id != user.Id && me.Friends.Contains(user.Id);
                vUser.IsMyFriend = isMyFriend;
                vUser.IsFriendRequestSent = !isMyFriend && user.FriendRequests.Contains(me.Id);
                vUser.AvatarUrl = user.AvatarUrl ?? "/Content/Images/noimage.png";
                vUsers.Add(vUser);
            }

            return vUsers;
        }
Esempio n. 2
0
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);

            if (externalLogin == null)
            {
                return InternalServerError();
            }

            var user = new ApplicationUser
            {
                UserName = model.Email,
                FirstName = model.FirstName,
                LastName = model.LastName
            };
            user.Logins.Add(new UserLoginInfo(externalLogin.LoginProvider, externalLogin.ProviderKey));
            var result = await UserManager.CreateAsync(user);
            var errorResult = GetErrorResult(result);

            return errorResult ?? Ok();
        }
Esempio n. 3
0
 public NewsFeedBuilder(ApplicationUser user, IPostRepository postRepository, IUserRepository userRepository)
 {
     _user = user;
     _postRepository = postRepository;
     _userRepository = userRepository;
 }
Esempio n. 4
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser
            {
                UserName = model.Email,
                FirstName = model.FirstName,
                LastName = model.LastName
            };

            var result = await UserManager.CreateAsync(user, model.Password);
            var errorResult = GetErrorResult(result);

            return errorResult ?? Ok();
        }