//to Do private async Task SetUserAdditionalInformation(AmigoTenantTUserDTO userDTO) { if (!string.IsNullOrEmpty(userDTO.Username)) { var httpClient = ISHttpClient.GetClient(IdentityServerClientSettings); var rspUsersDetails = await httpClient.GetAsync("api/Users/GetUsersDetails?Usernames=" + HttpUtility.UrlEncode(userDTO.Username)); if (rspUsersDetails.IsSuccessStatusCode) { var userDetailsJson = await rspUsersDetails.Content.ReadAsStringAsync().ConfigureAwait(false); var users = JsonConvert.DeserializeObject <ResponseDTO <List <UserResponse> > >(userDetailsJson); var user = users.Data.Where(q => q.UserName == userDTO.Username).FirstOrDefault(); if (user != null) { userDTO.FirstName = user.FirstName; userDTO.LastName = user.LastName; userDTO.Email = user.Email; } } else { throw new Exception("Amigo.Tenant.Application.Services.Security - AmigoTenantTUserApplicationService - SearchUsersByCriteriaAsync - call to IdentityServerHttpClient api/Users/GetUsersDetails was not successful"); } } }
public async Task <UserResponse> ValidateUserName(UserSearchRequest search) { var queryFilter = GetQueryFilter(search); var exist = await _userDataAccess.AnyAsync(queryFilter); UserResponse userAD = new UserResponse(); using (var httpClient = ISHttpClient.GetClient(IdentityServerClientSettings)) { var resetUserPasswordRequest = new AmigoTenantTUserDTO() { Username = search.UserName }; var resetUserPasswordResponse = await httpClient.PostAsJsonAsync("api/Users/search", resetUserPasswordRequest); if (resetUserPasswordResponse.IsSuccessStatusCode) { var userDetailsJson = await resetUserPasswordResponse.Content.ReadAsStringAsync().ConfigureAwait(false); var users = JsonConvert.DeserializeObject <ResponseDTO <PagedList <UserResponse> > >(userDetailsJson); userAD = users.Data.Items.FirstOrDefault(); var content = await resetUserPasswordResponse.Content.ReadAsAsync <ResponseDTO>(); if (!content.IsValid) { //return ResponseBuilder.InCorrect().WithMessages(content.Messages.ToArray()); } } else { //return ResponseBuilder.InCorrect().WithMessages(new ApplicationMessage() { Message = Constants.Entity.AmigoTenantTUser.ErrorMessage.PasswordNotUpdated }); } } return(userAD); }
private async Task <bool> SetUsersAdditionalInformation(List <AmigoTenantTUserDTO> userListDTO) { if (userListDTO.Any()) { var httpClient = ISHttpClient.GetClient(IdentityServerClientSettings); var rspUsersDetails = await httpClient.GetAsync("api/Users/GetUsersDetails" + GetUrlParameterValues(userListDTO.Select(q => q.Username).ToList())); if (rspUsersDetails.IsSuccessStatusCode) { var userDetailsJson = await rspUsersDetails.Content.ReadAsStringAsync().ConfigureAwait(false); var users = JsonConvert.DeserializeObject <ResponseDTO <List <UserResponse> > >(userDetailsJson); foreach (var item in userListDTO) { var user = users.Data.Where(q => q.UserName == item.Username).FirstOrDefault(); if (user != null) { item.FirstName = user.FirstName; item.LastName = user.LastName; item.Email = user.Email; item.CustomUsername = user.UserName + " - " + (user.FirstName == null ? string.Empty : user.FirstName) + " " + (user.LastName == null ? string.Empty : user.LastName); } else { item.CustomUsername = item.Username + " - " + (item.FirstName == null ? string.Empty : item.FirstName) + " " + (item.LastName == null ? string.Empty : item.LastName); } } } else { throw new Exception("Amigo.Tenant.Application.Services.Security - AmigoTenantTUserApplicationService - SearchUsersByCriteriaAsync - call to IdentityServerHttpClient api/Users/GetUsersDetails was not successful"); } } return(true); }
public async Task <ResponseDTO <List <Last24HoursDTO> > > SearchAsync(Last24HoursRequest search) { //--------------------------------------------------------------------------------------------- //---------------- Get driver's last 24 hours logs from AmigoTenant DB ------------------- //--------------------------------------------------------------------------------------------- var queryFilter = GetQueryFilter(search); IEnumerable <Last24HoursDTO> eventLogs; Expression <Func <Last24HoursDTO, object> > expressionReportedActivityDate = p => p.ReportedActivityDate; List <OrderExpression <Last24HoursDTO> > orderExpressions = new List <OrderExpression <Last24HoursDTO> >(); orderExpressions.Add(new OrderExpression <Last24HoursDTO>(OrderType.Desc, expressionReportedActivityDate)); var mostRecent = await _last24HoursDataAccess.FirstOrDefaultAsync(queryFilter, orderExpressions.ToArray()); if (mostRecent != null) { var before24Hours = mostRecent.ReportedActivityDate.Value.Subtract(new TimeSpan(24, 0, 0)); eventLogs = await _last24HoursDataAccess.ListAsync(queryFilter.And(w => w.ReportedActivityDate >= before24Hours)); //eventLogs = eventLogs.Select(s => s.); eventLogs.ToList().ForEach(x => x.Username = x.Username.ToUpper()); var myGroup = eventLogs.GroupBy( p => new { p.AmigoTenantTUserId, p.Username, p.Latitude, p.Longitude, p.ChargeNo, p.ChargeType, p.ActivityTypeName, p.ActivityTypeCode, p.TractorNumber, p.FirstName, p.LastName, p.ChassisNumber, p.EquipmentNumber } ); eventLogs = myGroup .Select(el => new Last24HoursDTO { AmigoTenantTUserId = el.Key.AmigoTenantTUserId, Username = el.Key.Username, Latitude = el.Key.Latitude, Longitude = el.Key.Longitude, ChargeNo = el.Key.ChargeNo, ChargeType = el.Key.ChargeType, ActivityTypeName = el.Key.ActivityTypeName, ActivityTypeCode = el.Key.ActivityTypeCode, TractorNumber = el.Key.TractorNumber, FirstName = el.Key.FirstName, LastName = el.Key.LastName, ChassisNumber = el.Key.ChassisNumber, EquipmentNumber = el.Key.EquipmentNumber, ReportedActivityTimeZone = el.Last().ReportedActivityTimeZone, ReportedActivityDate = el.Last().ReportedActivityDate, Product = el.Last().Product, Origin = el.Last().Origin, Destination = el.Last().Destination, ServiceName = el.Last().ServiceName, EquipmentTypeName = el.Last().EquipmentTypeName }).ToList().OrderByDescending(o => o.ReportedActivityDate); } else { List <Last24HoursDTO> res = new List <Last24HoursDTO>(); return(ResponseBuilder.Correct(res)); } //--------------------------------------------------------------------------------------------- //---------------- Get driver's firstName/lastName from Identity server ---------------------- //--------------------------------------------------------------------------------------------- string usernameParameter = "username="******"api/Users/GetUser?" + usernameParameter); if (rspUserDetails.IsSuccessStatusCode) { var userDetailsJson = await rspUserDetails.Content.ReadAsStringAsync().ConfigureAwait(false); var user = JsonConvert.DeserializeObject <ResponseDTO <UserResponse> >(userDetailsJson); //---------------------------------------------------------------------- //---------------------- merge with results list ------------------- //---------------------------------------------------------------------- int i = 0; foreach (var log in eventLogs) { i++; log.FirstName = user.Data.FirstName; log.LastName = user.Data.LastName; log.Index = i; } return(ResponseBuilder.Correct(eventLogs.ToList())); } else { throw new Exception("Amigo.Tenant.Application.Services.Tracking - Last24HoursService - SearchAsync - call to IdentityServerHttpClient api/Users/GetUsersDetails was not successful"); } }