Пример #1
0
        public IEnumerable <UserReplyViewModel> GetUserReplies(string id)
        {
            User   currentUser;
            string imageUrl;

            Reply[] replies;
            using (var context = this.GetDbContext)
            {
                currentUser = context.Users.Find(id);
                imageUrl    = new AccountProfileService().GetUserProfileImage(currentUser);
                replies     = context
                              .Replies
                              .Include(r => r.Topic)
                              .Where(r => r.UserId == id)
                              .ToArray();
            }

            return(replies.Select(
                       r => new UserReplyViewModel
            {
                ReplyId = r.Id,
                ReplyText = r.ReplayText,
                ReplayDate = r.ReplayDate,
                TopicId = r.TopicId,
                TopicTitle = r.Topic.Title,
                UserId = currentUser.Id,
                Username = currentUser.UserName,
                UserProfileImage = imageUrl
            }));
        }
Пример #2
0
        public TopicViewModel2 GetById(int id)
        {
            var profileService = new AccountProfileService();

            //Reply[] replies;
            using (var context = this.GetDbContext)
            {
                var currentTopic = context
                                   .Topics
                                   .Include(t => t.User)
                                   .Include(t => t.Replies)
                                   .FirstOrDefault(t => t.Id == id);
                //replies = await context
                //    .Replies
                //    .Include(r => r.User)
                //    .Include(r => r.Topic)
                //    .Where(r => r.TopicId == currentTopic.Id)
                //    .ToArrayAsync();
                return(new TopicViewModel2
                {
                    TopicId = currentTopic.Id,
                    TopicTitle = currentTopic.Title,
                    TopicDate = currentTopic.TopicDate,
                    TopicCategory = currentTopic.Category,
                    TopicText = currentTopic.Text,
                    AuthorUserName = currentTopic.User.UserName,
                    AuthorProfilePicture = profileService.GetUserProfileImage(currentTopic.User)
                                           //ReplyViewModels = currentTopic.Replies.AsParallel().Select(r =>
                                           //    new ReplyViewModel
                                           //    {
                                           //        Id = r.Id,
                                           //        ReplyText = r.ReplayText,
                                           //        ReplierId = replies.FirstOrDefault(rep => rep.Id == r.Id).UserId,
                                           //        ReplierProfilePicture =
                                           //            profileService.GetUserProfileImage(replies.FirstOrDefault(rep => rep.Id == r.Id)?.User),
                                           //        ReplierUserName = replies.FirstOrDefault(rep => rep.Id == r.Id).User.UserName,
                                           //        ReplyDate = r.ReplayDate
                                           //    }
                                           //).OrderBy(r => r.Id)
                });
            }
        }
Пример #3
0
        public async Task EditProfile(
            EditProfileBindingModel epbm,
            IPrincipal user,
            IAuthenticationManager authenticationManager,
            UserManager userManager)
        {
            var isImageUpdate = epbm.PostedFileBase != null;

            using (var context = this.GetDbContext)
            {
                var currentUser         = context.Users.Find(user.Identity.GetUserId());
                var isUserInfoIsUpdated = epbm.Email != currentUser.Email ||
                                          epbm.FirstName != currentUser.FirstName ||
                                          epbm.LastName != currentUser.LastName;
                if (isImageUpdate)
                {
                    var accountUserProfile = new AccountProfileService();
                    await accountUserProfile.UploadUserProfilePicture(
                        currentUser.UserName,
                        currentUser.HasOwnProfilePicture,
                        epbm);

                    if (!currentUser.HasOwnProfilePicture)
                    {
                        currentUser.HasOwnProfilePicture = true;
                        context.Users.AddOrUpdate(currentUser);
                        await context.SaveChangesAsync();
                    }
                }

                if (isUserInfoIsUpdated)
                {
                    currentUser.FirstName = epbm.FirstName;
                    currentUser.LastName  = epbm.LastName;
                    currentUser.Email     = epbm.Email;
                    var newUsername = $"{epbm.FirstName} {epbm.LastName}";
                    if (currentUser.HasOwnProfilePicture)
                    {
                        InternalService.DropboxService
                        .RenameFolder("/Users/",
                                      currentUser.UserName.Replace(" ", "-").ToLower(),
                                      newUsername.Replace(" ", "-").ToLower());
                    }

                    currentUser.UserName = newUsername;
                    context.Users.AddOrUpdate(currentUser);
                    await context.SaveChangesAsync();

                    authenticationManager.SignOut(
                        DefaultAuthenticationTypes.ExternalCookie);
                    var identity = userManager.CreateIdentity(
                        currentUser,
                        DefaultAuthenticationTypes.ApplicationCookie);
                    authenticationManager.SignIn(
                        new AuthenticationProperties
                    {
                        IsPersistent = true
                    },
                        identity);
                }
            }
        }
Пример #4
0
 public WebContentController()
 {
     this.profileService = new AccountProfileService();
 }
Пример #5
0
 public AccountController()
 {
     AccountDataService    = new AccountDataService();
     AccountProfileService = new AccountProfileService();
 }