Beispiel #1
0
        public List <UserSearchResultModel> SearchUsers(string name, string userId)
        {
            string[] friendIds                = GetFriendUserIds(userId);
            var      objList                  = _context.UserProfiles.Where(m => m.FirstName.ToLower().Contains(name.ToLower()) && m.UserId != userId && !friendIds.Contains(m.UserId)).ToList();
            var      receivedRequests         = GetReceivedFriendRequests(userId);
            var      sentRequests             = GetSentFriendRequests(userId);
            List <UserSearchResultModel> list = new List <UserSearchResultModel>();

            foreach (var item in objList)
            {
                bool isReceived      = false;
                var  receivedRequest = receivedRequests.Where(x => x.UserInfo.UserId == item.UserId).FirstOrDefault();
                if (receivedRequest != null)
                {
                    isReceived = true;
                }
                var userInfo = new UserSearchResultModel();
                userInfo.IsRequestReceived = isReceived;
                userInfo.UserInfo          = item;
                var sentRequest = sentRequests.Where(m => m.UserInfo.UserId == item.UserId).FirstOrDefault();
                if (sentRequest != null)
                {
                    userInfo.FriendRequestStatus = sentRequest.RequestStatus;;
                }
                list.Add(userInfo);
            }
            return(list);
        }
Beispiel #2
0
        public ActionResult CreatePlaceholder(CreatePlaceholderUserModel model)
        {
            using (var db = ApplicationDbContext.Create())
            {
                if (!ModelState.IsValid)
                {
                    throw new HttpException(400, "Bad request");
                }

                var org = db.Organizations.Single(x => x.Name == model.OrganizationName);

                // TODO Ensure the authenticated user belongs to the organization and
                // has authorization to create new users.

                // Create the user.
                var user = new ApplicationUser();
                Mapper.Map(model, user);
                user.IsPlaceholder = true;
                user.Id            = Guid.NewGuid().ToString();
                user.Organizations.Add(org);

                // Make sure this email is not already used.
                var existingUser = db.Users.Where(x => x.Email == user.Email)
                                   .FirstOrDefault();
                if (existingUser != null)
                {
                    throw new HttpException(409, "Email address is already used");
                }

                //if (string.IsNullOrWhiteSpace(user.Email))
                //{
                //    user.Email = "placeholder-" + Guid.NewGuid().ToString() + "@example.com";
                //}
                if (string.IsNullOrWhiteSpace(user.UserName))
                {
                    user.UserName = "******" + Guid.NewGuid().ToString();
                }

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

                var resultModel = new UserSearchResultModel();
                Mapper.Map(user, resultModel);
                return(Json(resultModel));
            }
        }