public async Task Run() { // Create sample application command var registerUser = new Application.Commands.RegisterUser(firstName: "Donald", lastName: "Duck"); // Invoke sample application service var userId = await UserApplicationService.RegisterUser(registerUser); // Wait one second for the Read model to be updated. // This is much, much more than usually needed. Thread.Sleep(1000); // Get the query model UserQueryModel queryModel = await UserProjection.QueryById(userId); Console.WriteLine($"Query models Display Name: {queryModel.DisplayName}"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public async Task <Pagination <User> > GetFilterAsync(UserQueryModel queryModel) { queryModel.PageSize = queryModel.PageSize.HasValue ? queryModel.PageSize.Value : 20; queryModel.CurrentPage = queryModel.CurrentPage.HasValue ? queryModel.CurrentPage.Value : 1; var query = _dataContext.AppUsers.AsNoTracking(); if (queryModel.ListTextSearch != null && queryModel.ListTextSearch.Count > 0) { foreach (var ts in queryModel.ListTextSearch) { query = query.Where(q => q.Username.Contains(ts) || q.Email.Contains(ts) ); } } return(await query.GetPagedAsync(queryModel.CurrentPage.Value, queryModel.PageSize.Value, queryModel.Sort)); }
public async Task <IList <UserEntity> > Query(UserQueryModel model) { var paging = model.Paging(); var query = Db.Find(); query.WhereIf(model.Name.NotNull(), m => m.Name.Contains(model.Name)); query.WhereIf(model.Number.NotNull(), m => m.Number == model.Number); if (!paging.OrderBy.Any()) { query.OrderByDescending(m => m.Id); } var result = await query.LeftJoin <AccountEntity>((x, y) => x.CreatedBy == y.Id) .Select((x, y) => new { x, Creator = y.Name }) .PaginationAsync(paging); model.TotalCount = paging.TotalCount; return(result); }
public async Task <IList <UserEntity> > Query(UserQueryModel model) { var conditions = await _filter.GetConditions <UserEntity, UserQueryModel>(model); var query = _dbContext.Db.Queryable <UserEntity>() .LeftJoin <OrganizeEntity>((x, y) => x.OrganizeId == y.Id && y.IsDel == false) .Select((x, y) => new UserEntity() { Id = x.Id.SelectAll(), OrganizeFullName = y.OrganizeFullName }) .MergeTable() .Where(conditions) .OrderBy(model.OrderFileds); RefAsync <int> totalCount = 0; var data = await query.ToPageListAsync(model.PageIndex, model.PageSize, totalCount); model.TotalCount = totalCount; return(data); }
public async Task <IList <UserEntity> > Query(UserQueryModel model) { var paging = model.Paging(); var query = Db.Find(); query.WhereIf(model.Name.NotNull(), m => m.Name.Contains(model.Name)); query.WhereIf(model.Number != null && model.Number > 0, m => m.JobNo == model.Number); if (!paging.OrderBy.Any()) { query.OrderByDescending(m => m.Id); } var result = await query.LeftJoin <AccountEntity>((x, y) => x.CreatedBy == y.Id) .LeftJoin <DepartmentEntity>((t1, t2, t3) => t1.DepartmentId == t3.Id) .LeftJoin <PositionEntity>((t1, t2, t3, t4) => t1.PositionId == t4.Id) .Select((t1, t2, t3, t4) => new { t1, Creator = t2.Name, DepartmentName = t3.Name, PositionName = t4.Name }) .PaginationAsync(paging); model.TotalCount = paging.TotalCount; return(result); }
public ActionResult AddUser(string keywords) { var query = new UserQueryModel(); var userId = 0L; if (ValidatorHelper.IsMobilePhoneNumber(keywords)) { query.Phone = keywords; } else if (long.TryParse(keywords, out userId)) { query.UserId = userId; } else { query.RealNameLike = keywords; } using (var db = new MbContext()) { var models = db.User.Where(query).Take(query.PageInfo.PageSize).ToList(); return(View(models)); } }
public IActionResult GetUserList([FromQuery] UserQueryModel userQuery) { return(Ok(_userService.GetUsers(userQuery))); }
public Task <IResultModel> QueryBySameOrg([FromQuery] UserQueryModel model) { return(_service.QueryBySameOrg(model)); }
public Task <IResultModel> QueryLatestSelect([FromQuery] UserQueryModel model) { return(_service.QueryLatestSelect(model)); }
public PagingResultModel <UserResultModel> GetUsers(UserQueryModel query) { var userQuery = _userRepository.Get() .AndIfHaveValue(query.UserName, u => u.UserName.Contains(query.UserName)) .AndIfHaveValue(query.Name, u => u.Name.Contains(query.Name)) .AndIfHaveValue(query.PhoneNumber, u => u.PhoneNumber.Contains(query.PhoneNumber)); if (!string.IsNullOrEmpty(query.RoleId)) { var roleid = int.Parse(query.RoleId); userQuery = from u in userQuery join ur in _userRoleRepository.Get() on u.Id equals ur.UserId where ur.RoleId == roleid select u; } if (query.Department != null) { userQuery = from u in userQuery join uc in _userClaimRepository.Get() on u.Id equals uc.UserId where uc.ClaimType == CustomClaimTypes.UserDepartment && uc.ClaimValue == query.Department.ToString() select u; } if (query.Position != null) { userQuery = from u in userQuery join uc in _userClaimRepository.Get() on u.Id equals uc.UserId where uc.ClaimType == CustomClaimTypes.UserPosition && uc.ClaimValue == query.Position.ToString() select u; } var resultQuery = from u in userQuery orderby u.Id descending select new UserResultModel { Avatar = u.Avatar, Name = u.Name, UserName = u.UserName, PhoneNumber = u.PhoneNumber, Id = u.Id, IsActive = u.IsActive, Sex = (int)u.Sex, CreatedTime = u.CreatedTime, RoleName = string.Join(',', from ur in _userRoleRepository.Get(false) join r in _roleRepository.Get(false) on ur.RoleId equals r.Id where ur.UserId == u.Id select r.Name), DepartmentName = (from uc in _userClaimRepository.Get(false) from dinfo in _departmentRepository.Get(false) where u.Id == uc.UserId && uc.ClaimType == CustomClaimTypes.UserDepartment && uc.ClaimValue == dinfo.Id.ToString() select dinfo.Name).FirstOrDefault(), PositionName = string.Join(',', from uc in _userClaimRepository.Get(false) from pinfo in _positionRepository.Get(false) where u.Id == uc.UserId && uc.ClaimType == CustomClaimTypes.UserPosition && uc.ClaimValue == pinfo.Id.ToString() select pinfo.Name), }; var skip = query.Size * (query.Page - 1); var users = resultQuery.Skip(skip).Take(query.Size).ToArray(); return(new PagingResultModel <UserResultModel> { Data = users, Count = resultQuery.Count() }); }
public IEnumerable <UserTableModel> SearchUsers(UserQueryModel query) { return(userRepository.SearchUsers(query)); }
public IEnumerable <Users> getUsers([FromBody] UserQueryModel Queryparam) { IInforWhatIFRequest Obj = new InforWhatIFRequest(); return(Obj.getUsers(Queryparam)); }
public Task <IResultModel> Query([FromQuery] UserQueryModel model) { return(_userService.Query(model)); }
public void when_listening_for_IUserEvent() { it["model is null"] = () => it["Model is not null in updater"] = () => _listener.TheModel.Should().BeNull(); context["when receiving a IUserCreated"] = () => { before = () => { _sessionMock.Setup(session => session.Save(It.IsAny <UserQueryModel>())).Callback <UserQueryModel>(saved => _queryModel = saved); _listener.Handle(new UserCreatedEvent(_userId)); }; it["BeforeHandlers1 should be called first"] = () => _listener.BeforeHandlers1CallOrder.Should().Be(1); it["BeforeHandlers2 should be called second"] = () => _listener.BeforeHandlers2CallOrder.Should().Be(2); it["usercreated is called third"] = () => _listener.UserCreatedCallOrder.Should().Be(3); it["AfterHandlers1 should be called fourth"] = () => _listener.AfterHandlers1CallOrder.Should().Be(4); it["AftereHandlers2 should be called fifth"] = () => _listener.AfterHandlers2CallOrder.Should().Be(5); it["5 calls should have been made"] = () => _listener.CallsMade.Should().Be(5); it["userregistered should not be called"] = () => _listener.UserRegisteredCallOrder.Should().Be(null); it["save is called on the session"] = () => _sessionMock.Verify(session => session.Save(It.IsAny <UserQueryModel>())); it["Model is not null in updater"] = () => _listener.TheModel.Should().NotBeNull(); }; context["when receiving a IUserRegisteredEvent"] = () => { before = () => { _sessionMock.Setup(session => session.Save(It.IsAny <UserQueryModel>())).Callback <UserQueryModel>(saved => _queryModel = saved); _listener.Handle(new UserRegistered(_userId)); }; it["BeforeHandlers1 should be called first"] = () => _listener.BeforeHandlers1CallOrder.Should().Be(1); it["BeforeHandlers2 should be called second"] = () => _listener.BeforeHandlers2CallOrder.Should().Be(2); it["usercreated should be called third"] = () => _listener.UserCreatedCallOrder.Should().Be(3); it["userregistered should be called fourth"] = () => _listener.UserRegisteredCallOrder.Should().Be(4); it["AfterHandlers1 should be called fifth"] = () => _listener.AfterHandlers1CallOrder.Should().Be(5); it["AftereHandlers2 should be called sixth"] = () => _listener.AfterHandlers2CallOrder.Should().Be(6); it["6 calls should have been made"] = () => _listener.CallsMade.Should().Be(6); it["save is called on the session"] = () => _sessionMock.Verify(session => session.Save(It.IsAny <UserQueryModel>())); it["Model is not null in updater"] = () => _listener.TheModel.Should().NotBeNull(); }; context["when receiving a UserEditedSkills event"] = () => { before = () => { _sessionMock.Setup(session => session.GetForUpdate <UserQueryModel>(_userId)).Returns(_queryModel); _sessionMock.Setup(session => session.SaveChanges()); _listener.Handle(new UserEditedSkill(_userId)); }; it["BeforeHandlers1 should be called first"] = () => _listener.BeforeHandlers1CallOrder.Should().Be(1); it["BeforeHandlers2 should be called second"] = () => _listener.BeforeHandlers2CallOrder.Should().Be(2); it["SkillsRemoved should be called third"] = () => _listener.SkillsRemovedCallOrder.Should().Be(3); it["SkillsAdded should be called fourth"] = () => _listener.SkillsAddedCallOrder.Should().Be(4); it["AfterHandlers1 should be called fifth"] = () => _listener.AfterHandlers1CallOrder.Should().Be(5); it["AftereHandlers2 should be called sixth"] = () => _listener.AfterHandlers2CallOrder.Should().Be(6); it["6 calls should have been made"] = () => _listener.CallsMade.Should().Be(6); it["GetForUpdate is called on the session"] = () => _sessionMock.Verify(session => session.GetForUpdate <UserQueryModel>(_userId)); it["Model is not null in updater"] = () => _listener.TheModel.Should().NotBeNull(); }; context["when receiving IUserDeletedEvent"] = () => { before = () => { _sessionMock.Setup(mock => mock.Delete <UserQueryModel>(_userId)); _sessionMock.Setup(mock => mock.SaveChanges()); _listener.Handle(new UserDeleted(_userId)); }; it["delete is called on the session"] = () => _sessionMock.Verify(session => session.Delete <UserQueryModel>(_userId)); it["delete is called on the session"] = () => _sessionMock.Verify(session => session.SaveChanges()); it["Model is null in updater"] = () => _listener.TheModel.Should().BeNull(); }; context["when receiving IIgnoredUserEvent"] = () => { before = () => _listener.Handle(new IgnoredUserEvent()); it["there are 0 calls"] = () => _listener.CallsMade.Should().Be(0); }; context["when receiving unhandled event"] = () => { it["unhandled event exception is thrown"] = () => expect <EventUnhandledException>(() => _listener.Handle(new UnHandledEvent())); }; }
public IActionResult SendFaqMessage(UserQueryModel userQueryModel) { Authorize(); if (userQueryModel.UserQuery.ToLower() == "noq0") { return(Ok("100")); } ChatViewModel chatViewModel = new ChatViewModel(); string message = Request.Headers["MessageToSend"]; var conversation = new List <ConversatioMessage>(); conversation.Add(new ConversatioMessage { Message = userQueryModel.UserQuery, SendBy = "user" }); #region Store Conversation if (HttpContext.Session.GetObject("conversationCurrent") != null) { string testHist = !string.IsNullOrEmpty(HttpContext.Session.GetObject("conversationCurrent").ToString()) ? HttpContext.Session.GetObject("conversationCurrent").ToString() : string.Empty; testHist = $"{testHist}-{userQueryModel.UserQuery}"; HttpContext.Session.SetObject("conversationCurrent", testHist.ToString()); if (userQueryModel.UserQuery.ToLower() == "noq10" || userQueryModel.UserQuery.ToLower() == "yesq10") { bool createStatus = _conversationHelper.CreateConversation(new ConversationViewModel { TYPE = "OST", CONVERSDATETIME = DateTime.Now.ToString("dd-mm-yyyy hh:MM:tt"), USERID = CurrentUserId, MESSAGE = testHist }); return(createStatus ? Ok("100") : Ok("999")); } } #endregion WatsonChatbotHelper watsonChatbotHelper = new WatsonChatbotHelper(); OutputData response = watsonChatbotHelper.MessageToCovid19Bot(userQueryModel.UserQuery); if (response.Generic.Count > 0) { foreach (var ob in response.Generic) { if (ob.ResponseType.ToLower() == "text") { conversation.Add(new ConversatioMessage { SendBy = "bot", Message = ob.Text, IsOption = 0 }); } if (ob.ResponseType.ToLower() == "option") { if (ob.Title == "Q0") { conversation.Add(new ConversatioMessage { SendBy = "bot", Message = "Are you ready to Take Test? Choose options carefully!!", IsOption = 1, QuestionNo = ob.Title }); } else { conversation.Add(new ConversatioMessage { SendBy = "bot", Message = ob.Text, IsOption = 1, QuestionNo = ob.Title }); } } } } else { conversation.Add(new ConversatioMessage { SendBy = "bot", Message = response.Text.Count > 0 ? response.Text[0] : "" }); } chatViewModel.ChatHistory = conversation; return(Ok(chatViewModel)); }
public IEnumerable <UserTableModel> SearchUsers(UserQueryModel query) { return(Context.Connection.Query <UserTableModel>("admdata.search_user", query)); }
public async Task <Pagination <UserViewModel> > GetAllAsync(UserQueryModel queryModel) { var query = from u in _dataContext.Users.AsNoTracking() .Include(x => x.Department) .Include(x => x.Organization) .Include(x => x.Title) .Include(x => x.Roles) select new UserViewModel { Id = u.Id, Username = u.Username, Firstname = u.Firstname, Lastname = u.Lastname, Fullname = u.Fullname, Code = u.Code, CertificateNumber = u.CertificateNumber, IssueDate = u.IssueDate, BirthDate = u.BirthDate, Email = u.Email, Gender = u.Gender, Address = u.Address, Type = u.Type, AvatarUrl = u.AvatarUrl, TitleId = u.TitleId, Title = u.Title, OrganizationId = u.OrganizationId, Organization = u.Organization, DepartmentId = u.DepartmentId, Department = u.Department, LastModifiedOnDate = u.LastModifiedOnDate }; if (queryModel.ListTextSearch != null && queryModel.ListTextSearch.Count > 0) { foreach (var ts in queryModel.ListTextSearch) { query = query.Where(q => q.Fullname.Contains(ts) || q.Code.Contains(ts) || q.CertificateNumber.Contains(ts) || q.Email.Contains(ts) ); } } if (queryModel.DepartmentId != null && queryModel.DepartmentId != Guid.Empty) { query = query.Where(x => x.DepartmentId == queryModel.DepartmentId); } if (queryModel.OrganizationId != null && queryModel.OrganizationId != Guid.Empty) { query = query.Where(x => x.OrganizationId == queryModel.OrganizationId); } if (queryModel.TitleId != null && queryModel.TitleId != Guid.Empty) { query = query.Where(x => x.TitleId == queryModel.TitleId); } var result = await query.GetPagedAsync(queryModel.CurrentPage.Value, queryModel.PageSize.Value, queryModel.Sort); if (queryModel.Year != null && queryModel.Year != 0) { //for (var i = 0; i < result.Content.Count(); i++) //{ // var newUser = new UserViewModel(); // newUser = AutoMapperUtils.AutoMap<UserViewModel, UserViewModel>(result.Content.ElementAt(i)); // newUser.AmoutInYear = 2000; // // var AmoutInYear = _dataContext.TrainingProgram_User.AsNoTracking() // // .Where(x => x.UserId == result.Content.ElementAt(i).Id && x.Year == queryModel.Year).Count(); // // result.Content.ElementAt(i).AmoutInYear = AmoutInYear; // var a = result.Content.ElementAt(i); // result.Content.ElementAt(i) = newUser; //} result.Content = result.Content.Select(x => { var trp_u = _dataContext.TrainingProgram_Users.AsNoTracking() .Where(t => t.UserId == x.Id && t.Year == queryModel.Year && t.Active == true).ToList(); x.AmoutInYear = (Int32)trp_u.Sum(x => x.Amount); return(x); }).ToList(); } return(result); }
public async Task <ActionResult <PagedResultModel <UserModel> > > GetAllUsers([FromQuery] UserQueryModel model, CancellationToken cancellationToken) { var query = Context.Users .AsNoTracking() .Include(x => x.OrganizationUnit) .AsQueryable(); if (!string.IsNullOrEmpty(model.OrgUnitPath)) { query = query.Where(x => x.OrganizationUnitPath.StartsWith(model.OrgUnitPath)); } var users = await query .OrderBy(x => x.FamilyName) .ThenBy(x => x.GivenName) .Select(MapToModel) .PagedAsync(model, cancellationToken); foreach (var user in users.Items) { user.PictureUrl = Url.ActionLink(nameof(GetUserPictureById), values: new { id = user.Id }); } return(Ok(users)); }