public async Task <IActionResult> GetUserInfo(Guid id) { List <User> users = await _userRepo.GetAsync(d => d.AccountId == id); var user = users.FirstOrDefault(); return(Ok(user)); }
public async Task <IActionResult> GetUserList() { var results = await _userRepo.GetAllAsync(); var userList = new List <UserVM>(); foreach (var user in results) { var deptResults = await _departmentRepo.GetAsync(d => d.DepartmentId == user.DepartmentId); var posResults = await _positionRepo.GetAsync(p => p.PositionId == user.PositionId); var accountResults = await _accountRepo.GetAsync(a => a.AccountId == user.AccountId); var userShiftResults = await _userShiftRepo.GetAsync(u => u.UserId == user.UserId); var userShifts = new List <UserShiftVM>(); foreach (var userShift in userShiftResults) { var shiftResults = await _shiftRepo.GetAsync(s => s.ShiftId == userShift.ShiftId); var shiftResult = shiftResults.FirstOrDefault(); var shift = new ShiftVM { ShiftId = shiftResult.ShiftId, TimeSlot = shiftResult.TimeSlot }; userShifts.Add(new UserShiftVM { UserShiftId = userShift.UserShiftId, UserId = userShift.UserId, Day = userShift.Day, ShiftId = userShift.ShiftId, Shift = shift }); } userList.Add(new UserVM { Id = user.UserId, AccountId = user.AccountId, Email = accountResults.FirstOrDefault().Email, FirstName = user.FirstName, LastName = user.LastName, Gender = user.Gender, DepartmentId = user.DepartmentId, Department = deptResults.FirstOrDefault().Name, PositionId = user.PositionId, Position = posResults.FirstOrDefault().Name, UserShifts = userShifts }); } return(Ok(userList)); }
public async Task <TokenResponseDto> LoginAsync(LoginDto credential) { try { var accounts = await _accountRepo.GetAsync(a => a.Email == credential.Email); var account = accounts.FirstOrDefault(); if (account == null) { return(new TokenResponseDto { Code = System.Net.HttpStatusCode.Unauthorized }); } if (!VerifyPasswordHash(account.PasswordHash, account.PasswordSalt, credential.Password)) { return(new TokenResponseDto { Code = System.Net.HttpStatusCode.Unauthorized }); } return(new TokenResponseDto { Token = _jwtHelper.GenerateToken(credential.Email), Code = System.Net.HttpStatusCode.OK, RoleId = account.RoleId, AccountId = account.AccountId }); } catch (System.Exception e) { return(new TokenResponseDto { Error = e.Message, Code = System.Net.HttpStatusCode.BadRequest }); } }