Exemplo n.º 1
0
        public UserFollowerVM GetUserFollower(string followByUserId, string followedUserId)
        {
            UserFollower userFollower = new UserFollowerRepository(dbContext).GetFollower(followByUserId, followedUserId);

            if (userFollower != null)
            {
                UserFollowerVM userFollowerVM = new UserFollowerVM();
                Mapper.Map(userFollower, userFollowerVM);
                return(userFollowerVM);
            }
            return(null);
        }
Exemplo n.º 2
0
        public ResponseResult <UserFollowerVM> FollowUser(UserFollowerVM userFollowerVM, bool follow)
        {
            ResponseResult <UserFollowerVM> responseResult = new ResponseResult <UserFollowerVM>
            {
                Success = true,
                Data    = userFollowerVM
            };

            try
            {
                UserFollowerRepository userFollowerRepository = new UserFollowerRepository(dbContext);
                UserFollower           userFollower           = userFollowerRepository.GetFollower(userFollowerVM.FollowByUserId, userFollowerVM.FollowedUserId);
                if (follow)
                {
                    if (userFollower == null)
                    {
                        userFollower = new UserFollower();
                        Mapper.Map(userFollowerVM, userFollower);
                        userFollowerRepository.Insert(userFollower);
                        userFollowerRepository.SaveChanges();

                        //Add User Action Log
                        new LogsSerivce().RunAddLogTask(_LogActionType.Follow, userFollowerVM.FollowByUserId, userFollowerVM.FollowedUserId);
                    }
                }
                else
                {
                    if (userFollower != null)
                    {
                        userFollowerRepository.Delete(userFollower);
                        userFollowerRepository.SaveChanges();

                        //Add User Action Log
                        new LogsSerivce().RunAddLogTask(_LogActionType.UnFollow, userFollowerVM.FollowByUserId, userFollowerVM.FollowedUserId);
                    }
                }

                userFollowerVM.Id = userFollower.Id;
            }
            catch
            {
                responseResult.Success = false;
                responseResult.Message = "Oops! You are unable to follow this user.";
            }

            return(responseResult);
        }
Exemplo n.º 3
0
        public ResponseResult <UserFollowerVM> AnonymizeProfile(string currentUserId)
        {
            ResponseResult <UserFollowerVM> responseResult = new ResponseResult <UserFollowerVM>
            {
                Success = true,
            };

            try
            {
                ApplicationUser        applicationUser        = applicationUserRepository.GetUserWithProfilePicture(currentUserId);
                UserFollowerRepository userFollowerRepository = new UserFollowerRepository(dbContext);
                if (applicationUser != null)
                {
                    string ProfileImageOriginal = applicationUser.ProfileImageOriginal;
                    string ProfileImageSelected = applicationUser.ProfileImageSelected;

                    //Anonymize User
                    applicationUser.UrlUsername          = "******";
                    applicationUser.UserName             = Guid.NewGuid().ToString() + "_N/A";
                    applicationUser.Email                = "N/A";
                    applicationUser.FullName             = "N/A";
                    applicationUser.LockoutEnabled       = true;
                    applicationUser.LockoutEndDateUtc    = DateTime.UtcNow;
                    applicationUser.ProfileImageOriginal = null;
                    applicationUser.ProfileImageSelected = null;
                    applicationUser.ProfileImageData     = null;
                    applicationUser.UpdatedOn            = DateTime.UtcNow;

                    if (userFollowerRepository.SaveChanges() > 0)
                    {
                        //Remove the ProfilePictures
                        try
                        {
                            if (!string.IsNullOrEmpty(ProfileImageOriginal))
                            {
                                System.IO.File.Delete(HttpContext.Current.Server.MapPath("~" + _FileSavingPaths.ProfileImage + "/" + ProfileImageOriginal));
                            }
                        }catch { }

                        try
                        {
                            if (!string.IsNullOrEmpty(ProfileImageSelected))
                            {
                                System.IO.File.Delete(HttpContext.Current.Server.MapPath("~" + _FileSavingPaths.ProfileImage + "/" + ProfileImageSelected));
                            }
                        }
                        catch { }

                        //Remove all Profile Data
                        applicationUserRepository.SP_DeleteUserProfileData(currentUserId);
                    }

                    //Add User Action Log
                    new LogsSerivce().RunAddLogTask(_LogActionType.AccountDeleted, currentUserId);
                }
                else
                {
                    responseResult.Success = false;
                    responseResult.Message = "Oops! Account profile does not exist.";
                }
            }
            catch (Exception err)
            {
                responseResult.Success = false;
                responseResult.Message = "Oops! An error occured while removing your profile.";
            }
            return(responseResult);
        }