コード例 #1
0
        public async Task <IActionResult> UpdateUsersAsync([FromRoute] int id, [FromBody] UserUpdateDTO UserModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var users = await uow.User.GetUserByIdT(id);

                if (users != null)
                {
                    users.firstname  = UserModel.Firstname;
                    users.surname    = UserModel.Surname;
                    users.state      = UserModel.State;
                    users.gender     = UserModel.Gender;
                    users.age        = UserModel.Age;
                    users.updated_at = DateTime.Now;
                    users.email      = UserModel.Email;
                    users.username   = UserModel.Username;
                    users.country    = UserModel.Country;

                    uow.User.Update(users);
                    await uow.save();

                    return(Ok(new { success = true, message = "Profile Data Updated Successfully" }));
                }

                return(Ok(new { success = false, Message = "Failed to update" }));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }
コード例 #2
0
        public async Task <IActionResult> updatePostAsync([FromBody] PostWriteUpdateDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var postInfo = await uow.Post.GetPostById(model.post_Id);

                if (postInfo == null)
                {
                    return(Ok(new { success = true, message = "Failed to update post" }));
                }

                postInfo.message    = model.message;
                postInfo.updated_at = DateTime.Now;
                uow.Post.Update(postInfo);
                await uow.save();

                var newPostInfo = await uow.Post.GetPostsByIdSingle(model.post_Id);

                return(Ok(new { success = true, message = "Post Updated successfully", userInfo = newPostInfo }));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }
コード例 #3
0
        public async Task <IActionResult> FollowUserAsync([FromRoute] int userToFollowOrUnfollowId, [FromRoute] int userThatWantToFollowORUnfollowId)
        {
            try
            {
                var CheckIfFollowingIsTrue = await _uow.Followers.CheckIfFollowerExistAsync(userToFollowOrUnfollowId, userThatWantToFollowORUnfollowId);

                if (CheckIfFollowingIsTrue == null)
                {
                    var Follower = new Followers
                    {
                        user_Id     = userToFollowOrUnfollowId,
                        follower_Id = userThatWantToFollowORUnfollowId,
                        isFollowing = true
                    };

                    _uow.Followers.Create(Follower);
                    await _uow.save();

                    return(Ok(new { following = true }));
                }
                else
                {
                    if (CheckIfFollowingIsTrue.isFollowing == true)
                    {
                        CheckIfFollowingIsTrue.isFollowing = false;
                        _uow.Followers.Update(CheckIfFollowingIsTrue);
                        await _uow.save();

                        return(Ok(new { following = false }));
                    }
                    else
                    {
                        CheckIfFollowingIsTrue.isFollowing = true;
                        _uow.Followers.Update(CheckIfFollowingIsTrue);
                        await _uow.save();

                        return(Ok(new { following = true }));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }
コード例 #4
0
        public async Task <IActionResult> ChangeUserPasswordAsync([FromRoute] int UserId, [FromBody] ChangePassword passwordInfo)
        {
            try
            {
                var user = await uow.User.GetUserByIdT(UserId);

                if (user.password != passwordInfo.OldPassword)
                {
                    return(Ok(new { success = false }));
                }

                user.password = passwordInfo.NewPassword;
                uow.User.Update(user);
                await uow.save();

                return(Ok(new { success = true }));
            }
            catch (Exception ex)
            {
                return(Ok(ex.Message));
            }
        }