Exemplo n.º 1
0
        public async Task <ActionResult <GetUserFollowerModel> > PostUserFollower(PostUserFollowerModel postUserFollowerModel)
        {
            try
            {
                GetUserFollowerModel userFollowerModel = await _userFollowerRepository.PostUserFollower(postUserFollowerModel);

                return(CreatedAtAction(nameof(GetUserFollower), new { id = userFollowerModel.Id }, userFollowerModel));
            }
            catch (DatabaseException e)
            {
                return(BadRequest(e.MovieMindError));
            }
        }
        public async Task <IActionResult> AddFollower(string followingId)
        {
            try
            {
                var userId = HttpContext.Session.GetString("_Id");
                var user   = await _moviemindAPIService.GetModel <GetUserModel>(userId, "users");

                PostUserFollowerModel postUserFollowerModel = new PostUserFollowerModel
                {
                    FollowingId = Guid.Parse(followingId),
                    FollowerId  = user.Id
                };

                GetUserFollowerModel getUserFollowerModel = await _moviemindAPIService.PostModel <PostUserFollowerModel, GetUserFollowerModel>(postUserFollowerModel, "Userfollowers");

                return(Redirect("/Users/Details/" + followingId));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }
        public async Task <GetUserFollowerModel> GetUserFollower(string id)
        {
            GetUserFollowerModel userFollower = await _context.UserFollowers
                                                .Where(x => x.Id == Guid.Parse(id))
                                                .Select(x => new GetUserFollowerModel
            {
                Id          = x.Id,
                FollowingId = x.FollowingId,
                Following   = new GetUserModel
                {
                    Id          = x.FollowingId,
                    FirstName   = x.Following.FirstName,
                    LastName    = x.Following.LastName,
                    Email       = x.Following.Email,
                    Description = x.Following.Description
                },
                FollowerId = x.FollowerId,
                Follower   = new GetUserModel
                {
                    Id          = x.FollowerId,
                    FirstName   = x.Follower.FirstName,
                    LastName    = x.Follower.LastName,
                    Email       = x.Follower.Email,
                    Description = x.Follower.Description
                }
            })
                                                .AsNoTracking()
                                                .FirstOrDefaultAsync();

            if (userFollower == null)
            {
                throw new EntityException("UserFollower not found", this.GetType().Name, "GetUserFollower", "404");
            }

            return(userFollower);
        }