public void Follow(string username, CredentialsDto credentials) { var followee = _context.Users .SingleOrDefault(u => u.Credentials.Username == username && !u.Deleted); var follower = _context.Users .SingleOrDefault(u => u.Credentials.Username == credentials.Username && !u.Deleted); if (followee == null || follower == null) { throw new UserNotFoundException(); } if (follower.Credentials.Password != credentials.Password) { throw new InvalidCredentialsException(); } bool exists = _context.UserFollowJoin.Where(u => u.FolloweeId == followee.Id && u.FollowerId == follower.Id).Any(); if (!exists) { var userUser = new UserUser { Followee = followee, FolloweeId = followee.Id, Follower = follower, FollowerId = follower.Id }; _context.UserFollowJoin.Add(userUser); _context.SaveChanges(); } }
/// <summary> /// 显示详细信息 /// </summary> /// <param name="key"></param> public override void ShowInfo(string key) { txtUserCode.Text = key; txtUserCode.Enabled = false; if (_userList.Any(u => u.UserID == key)) { _user = _userList.First(u => u.UserID == key); txtUserName.Text = _user.UserName; txtPwd.Text = _user.PassWord; if (_roleList.Count == 0) { return; } if (_roleList.Any(r => r.RoleID == _user.UserRole)) { var role = _roleList.First(r => r.RoleID == _user.UserRole); if (!string.IsNullOrEmpty(role.RoleName)) { cbRole.Text = role.RoleName; } } } }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="user"></param> /// <returns></returns> public bool ModifyUser(UserUser user) { var sql = "Update UserUser set UserName='******', PassWord='******', UserRole='" + user.UserRole + "' where UserID='" + user.UserID + "'"; return(CrudBll.Update(user, sql)); }
public async Task <IActionResult> userLogin([FromBody] UserUser data) { var role = "User"; HttpResponse successResponse = new HttpResponse { ok = true, statusCode = 200, msg = "you has been loged succesfully as " + role }; HttpResponse invalidLoginResponse = new HttpResponse { statusCode = 401, ok = false, msg = "invalid user or password for " + role, }; HttpResponse invalidBodyResponse = new HttpResponse { ok = false, statusCode = 400, msg = "invalid body for " + role + " role" }; if (data is UserUser == false) { return(StatusCode(400, invalidBodyResponse)); } if (AuthTools.user(data)) { await this.loginAs(userRole); return(Ok(successResponse)); } else { return(StatusCode(401, invalidLoginResponse)); } }
public async Task <IActionResult> FollowUser(int followedUserId) { User user = await HttpContext.GetContextUser(userService) .ConfigureAwait(false); if (await userService.FindAsync(user.Id) == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the user account.", Detail = "The database does not contain a user with this user id.", Instance = "B778C55A-D41E-4101-A7A0-F02F76E5A6AE" }; return(NotFound(problem)); } if (userUserService.CheckIfUserFollows(user.Id, followedUserId)) { ProblemDetails problem = new ProblemDetails { Title = "You are already following this user", Detail = "You are already following this user.", Instance = "6B4D9745-4A18-4516-86A3-466678A3F891" }; return(Conflict(problem)); } User followedUser = await userService.FindAsync(followedUserId); if (await userService.FindAsync(followedUserId) == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the user", Detail = "Unable to find user to follow", Instance = "57C13F73-6D22-41F3-AB05-0CCC1B3C8328" }; return(NotFound(problem)); } if (user.Id == followedUserId) { ProblemDetails problem = new ProblemDetails { Title = "You can not follow yourself", Detail = "You can not follow yourself", Instance = "57C13F73-6D22-41F3-AB05-0CCC1B3C8328" }; return(NotFound(problem)); } UserUser userUser = new UserUser(user, followedUser); userUserService.Add(userUser); userUserService.Save(); return(Ok(mapper.Map <UserUser, UserUserResourceResult>(userUser))); }
public bool DeleteContact(int lowerUserId, int upperUserId) { try { UserUser delCont = GetContact(lowerUserId, upperUserId); _DbConnection.Delete <UserUser>(delCont.ID); return(true); } catch (System.InvalidOperationException ioe) { System.Console.WriteLine(ioe.StackTrace); return(false); } }
/// <summary> /// 创建新用户 /// </summary> private void Create() { if (!ValidateInput()) { return; } _user = new UserUser() { UserID = txtUserCode.Text.Trim(), UserName = txtUserName.Text.Trim(), PassWord = txtPwd.Text.Trim(), UserRole = _usersBll.GetRoleIdByRoleName(cbRole.Text) }; }
public async Task <IActionResult> UnfollowUser(int followedUserId) { User user = await HttpContext.GetContextUser(userService) .ConfigureAwait(false); if (await userService.FindAsync(user.Id) == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the user account.", Detail = "The database does not contain a user with this user id.", Instance = "B778C55A-D41E-4101-A7A0-F02F76E5A6AE" }; return(NotFound(problem)); } if (userUserService.CheckIfUserFollows(user.Id, followedUserId) == false) { ProblemDetails problem = new ProblemDetails { Title = "User is not following this user", Detail = "You are not following this user.", Instance = "103E6317-4546-4985-8E39-7D9FD3E14E35" }; return(Conflict(problem)); } User followedUser = await userService.FindAsync(followedUserId); if (await userService.FindAsync(followedUserId) == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the project.", Detail = "The database does not contain a project with this project id.", Instance = "ED4E8B26-7D7B-4F5E-BA04-983B5F114FB5" }; return(NotFound(problem)); } UserUser userToUnfollow = new UserUser(user, followedUser); userUserService.Remove(userToUnfollow); userUserService.Save(); return(Ok()); }
public bool CreateContact(int user1Id, int user2Id) { if (GetContact(user1Id, user2Id) == null) { int size = _DbConnection.Table <UserUser>().Count() + 1; UserUser newCont = new UserUser(user1Id, user2Id, size); try { _DbConnection.Insert(newCont, typeof(UserUser)); return(true); } catch (System.InvalidOperationException ioe) { System.Console.WriteLine(ioe.StackTrace); return(false); } } return(false); }
public async Task <IActionResult> Follow([FromForm] AccountFollowVM formdata) { // Find User var user = await _dbContext.Users.FindAsync(formdata.UserID); if (user == null) { return(NotFound(new { message = "User Not Found " + formdata.UserID })); } // Find Follower var follower = await _dbContext.Users.FindAsync(formdata.FollowerID); if (follower == null) { return(NotFound(new { message = "User Not Found " + formdata.UserID })); } // Create Many To Many Connection var userFollower = new UserUser { UserID = formdata.UserID, FollowerID = formdata.FollowerID }; // Add To Database await _dbContext.UserUsers.AddAsync(userFollower); // Save Change await _dbContext.SaveChangesAsync(); return(Ok(new { result = userFollower, message = follower.UserName + " is now following " + user.UserName })); }
public static void AddParentUser(this List <AspNetUser> users, string childId, UserUser parent) { var user = users.FirstOrDefault(u => u.Id == childId); var userUsers = new List <UserUser>(); userUsers.Add(parent); user.UserUsers = userUsers; }
public static bool user(UserUser creds) { return(true); }
/// <summary> /// Updates a user. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='userId'> /// identifier of the user /// </param> /// <param name='body'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <UserUser> UpdateAsync(this IAuthService operations, string userId, UserUser body, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(userId, body, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Updates a user. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='userId'> /// identifier of the user /// </param> /// <param name='body'> /// </param> public static UserUser Update(this IAuthService operations, string userId, UserUser body) { return(operations.UpdateAsync(userId, body).GetAwaiter().GetResult()); }
public bool ModifyUser(UserUser user) => _dal.ModifyUser(user);