public override async Task <GetSessionsResponse> GetSessions(GetSessionsRequest request, ServerCallContext context) { var result = new GetSessionsResponse { }; result.Sessions.Add(string.IsNullOrEmpty(request.TitleStartsWith) ? GetSessions() : GetSessions().Where(s => s.Title.StartsWith(request.TitleStartsWith, StringComparison.OrdinalIgnoreCase))); return(await Task.FromResult(result)); }
public async Task <IActionResult> GetSessionAll(int pages) { try { var request = new GetSessionsRequest(pages); var response = await _sessionUseCase.GetList(request); return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Sessions(GetSessionsRequest request) { var viewModel = new SessionsViewModel(request); if (ModelState.IsValid) { var response = await _adminService.GetSessions(request); if (response.IsSuccessful) { viewModel.Sessions = response.Sessions; viewModel.SelectedFilter = response.SelectedFilter; return(View(viewModel)); } } AddNotifications(request); return(View(viewModel)); }
public async Task <GetSessionsResponse> GetSessions(GetSessionsRequest request) { var response = new GetSessionsResponse(); var sessions = new List <Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsResponse>(); if (request.Last24Hours.HasValue && request.Last24Hours.Value) { using (var uow = _uowFactory.GetUnitOfWork()) { sessions = await uow.SessionRepo.GetAdminSessionsByStartDate(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsByStartDateRequest() { Start_Date = DateTime.Now.AddDays(-1) }); uow.Commit(); } response.SelectedFilter = "Last 24 Hours"; } if (request.LastXDays.HasValue) { using (var uow = _uowFactory.GetUnitOfWork()) { sessions = await uow.SessionRepo.GetAdminSessionsByStartDate(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsByStartDateRequest() { Start_Date = DateTime.Today.AddDays(request.LastXDays.Value * -1) }); uow.Commit(); } response.SelectedFilter = $"Last {request.LastXDays} days"; } if (request.Day.HasValue) { using (var uow = _uowFactory.GetUnitOfWork()) { sessions = await uow.SessionRepo.GetAdminSessionsByDate(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsByDateRequest() { Date = request.Day.Value }); uow.Commit(); } response.SelectedFilter = request.Day.Value.ToLongDateString(); } if (request.UserId.HasValue) { using (var uow = _uowFactory.GetUnitOfWork()) { sessions = await uow.SessionRepo.GetAdminSessionsByUserId(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsByUserIdRequest() { User_Id = request.UserId.Value }); uow.Commit(); } response.SelectedFilter = $"User ID: {request.UserId}"; } if (!string.IsNullOrEmpty(request.Username)) { using (var uow = _uowFactory.GetUnitOfWork()) { var user = await uow.UserRepo.GetUserByUsername(new Repositories.DatabaseRepos.UserRepo.Models.GetUserByUsernameRequest() { Username = request.Username }); if (user == null) { response.Notifications.AddError($"Could not find user with username {request.Username}"); return(response); } sessions = await uow.SessionRepo.GetAdminSessionsByUserId(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsByUserIdRequest() { User_Id = user.Id }); uow.Commit(); } response.SelectedFilter = $"Username: {request.Username}"; } if (!string.IsNullOrEmpty(request.MobileNumber)) { using (var uow = _uowFactory.GetUnitOfWork()) { var user = await uow.UserRepo.GetUserByMobileNumber(new Repositories.DatabaseRepos.UserRepo.Models.GetUserByMobileNumberRequest() { Mobile_Number = request.MobileNumber }); if (user == null) { response.Notifications.AddError($"Could not find user with mobile number {request.MobileNumber}"); return(response); } sessions = await uow.SessionRepo.GetAdminSessionsByUserId(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsByUserIdRequest() { User_Id = user.Id }); uow.Commit(); } response.SelectedFilter = $"Mobile Number: {request.MobileNumber}"; } if (!string.IsNullOrEmpty(request.EmailAddress)) { using (var uow = _uowFactory.GetUnitOfWork()) { var user = await uow.UserRepo.GetUserByEmail(new Repositories.DatabaseRepos.UserRepo.Models.GetUserByEmailRequest() { Email_Address = request.EmailAddress }); if (user == null) { response.Notifications.AddError($"Could not find user with email address {request.EmailAddress}"); return(response); } sessions = await uow.SessionRepo.GetAdminSessionsByUserId(new Repositories.DatabaseRepos.SessionRepo.Models.GetSessionsByUserIdRequest() { User_Id = user.Id }); uow.Commit(); } response.SelectedFilter = $"Email Address: {request.EmailAddress}"; } response.Sessions = sessions.Select(s => new Session() { Entity = s, Username = s.Username, Last_Session_Event_Date = s.Last_Session_Event_Date, Last_Session_Log_Date = s.Last_Session_Log_Date }).OrderByDescending(s => s.Entity.Created_Date).ToList(); return(response); }
public async Task <GetSessionsResponse> GetList(GetSessionsRequest getSessionsRequest) { var responseMovie = await _mediator.Send(getSessionsRequest, CancellationToken.None); return(responseMovie); }