Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LML.NPOManagement.Bll/Interfaces/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public interface IUserService
Task<int> UserInformationRegistration(UserInformationModel userInformationModel, IConfiguration configuration);
Task<UserTypeModel> AddUserType(UserInformationModel userInformationModel);
Task<UserModel> ActivationUser(string token, IConfiguration configuration);
Task<List<SearchModel>> GetSearchResult(string firstChars, bool includeGroups);
}
}
11 changes: 11 additions & 0 deletions LML.NPOManagement.Bll/Model/SearchModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
namespace LML.NPOManagement.Bll.Model
{
public class SearchModel
{
public int Id { get; set; }
public SearchType Type { get; set; }
public String Name { get; set; }
}
}

10 changes: 10 additions & 0 deletions LML.NPOManagement.Bll/Model/SearchType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace LML.NPOManagement.Bll.Model
{
public enum SearchType
{
User,
Group
}
}

46 changes: 45 additions & 1 deletion LML.NPOManagement.Bll/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,49 @@ public async Task<bool> ModifyUserInfo(UserInformationModel userInformationModel
await _dbContext.SaveChangesAsync();
return true;
}

public async Task<List<SearchModel>> GetSearchResult(string firstChars, bool includeGroups)
{
var users = await _dbContext.UserInformations
.Where(u => u.FirstName.Contains(firstChars) || u.LastName.Contains(firstChars))
.ToListAsync();

var groups = new List<UsersGroup>();

if (includeGroups)
{
groups = await _dbContext.UsersGroups
.Where(g => g.GroupName.Contains(firstChars))
.ToListAsync();
}

List<SearchModel> result = new();

foreach (var user in users)
{
var searchModel = new SearchModel()
{
Id = user.Id,
Name = user.FirstName + " " + user.LastName,
Type = SearchType.User
};

result.Add(searchModel);
}

foreach (var group in groups)
{
var searchModel = new SearchModel()
{
Id = group.Id,
Name = group.GroupName,
Type = SearchType.Group
};

result.Add(searchModel);
}

return result;
}
}
}
}
3 changes: 2 additions & 1 deletion LML.NPOManagement.Dal/INPOManagementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public interface INPOManagementContext
DbSet<UserIdea> UserIdeas { get; set; }
DbSet<UserInformation> UserInformations { get; set; }
DbSet<UserInventory> UserInventories { get; set; }
DbSet<UserType> UserTypes { get; set; }
DbSet<UserType> UserTypes { get; set; }
DbSet<UsersGroup> UsersGroups { get; set; }
Task<int> SaveChangesAsync();
void SaveChanges();
}
Expand Down
5 changes: 5 additions & 0 deletions LML.NPOManagement.Dal/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public User()
UserIdeas = new HashSet<UserIdea>();
UserInformations = new HashSet<UserInformation>();
UserInventories = new HashSet<UserInventory>();
UsersGroups = new HashSet<UsersGroup>();
Accounts = new HashSet<Account>();
Groups = new HashSet<UsersGroup>();
Notifications = new HashSet<Notification>();
Roles = new HashSet<Role>();
UserTypes = new HashSet<UserType>();
Expand All @@ -21,13 +23,16 @@ public User()
public string Email { get; set; } = null!;
public string Password { get; set; } = null!;
public string? Status { get; set; }
public int? StatusId { get; set; }

public virtual ICollection<InvestorInformation> InvestorInformations { get; set; }
public virtual ICollection<UserIdea> UserIdeas { get; set; }
public virtual ICollection<UserInformation> UserInformations { get; set; }
public virtual ICollection<UserInventory> UserInventories { get; set; }
public virtual ICollection<UsersGroup> UsersGroups { get; set; }

public virtual ICollection<Account> Accounts { get; set; }
public virtual ICollection<UsersGroup> Groups { get; set; }
public virtual ICollection<Notification> Notifications { get; set; }
public virtual ICollection<Role> Roles { get; set; }
public virtual ICollection<UserType> UserTypes { get; set; }
Expand Down
23 changes: 23 additions & 0 deletions LML.NPOManagement.Dal/Models/UsersGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;

namespace LML.NPOManagement.Dal.Models
{
public partial class UsersGroup
{
public UsersGroup()
{
Users = new HashSet<User>();
}

public int Id { get; set; }
public int CreatedByUserId { get; set; }
public string GroupName { get; set; } = null!;
public DateTime CreatedAt { get; set; }
public string? Description { get; set; }

public virtual User CreatedByUser { get; set; } = null!;

public virtual ICollection<User> Users { get; set; }
}
}
Loading