Skip to content

Commit

Permalink
#274 #277 #278 finished
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBlaa committed Jul 17, 2019
1 parent f29ca9a commit cd1f2e5
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 76 deletions.
56 changes: 56 additions & 0 deletions Components/AAA/BExIS.Security.Services/Subjects/GroupManager.cs
@@ -1,6 +1,10 @@
using BExIS.Security.Entities.Subjects;
using BExIS.Utils.NH.Querying;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Threading.Tasks;
using Vaiona.Persistence.Api;

Expand All @@ -26,6 +30,58 @@ public GroupManager()
public IQueryable<Group> Roles => GroupRepository.Query();
private IReadOnlyRepository<Group> GroupRepository { get; }

/// <summary>
/// returns subset of groups based on the parameters
/// and also count of filtered list
/// </summary>
/// <param name="filter"></param>
/// <param name="orderBy"></param>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <returns></returns>
public List<Group> GetGroups(FilterExpression filter, OrderByExpression orderBy, int pageNumber, int pageSize, out int count)
{
var orderbyClause = orderBy?.ToLINQ();
var whereClause = filter?.ToLINQ();
count = 0;
try
{
using (IUnitOfWork uow = this.GetUnitOfWork())
{
if (whereClause != null && orderBy != null)
{
var l = Groups.Where(whereClause);
var x = l.OrderBy(orderbyClause);
var y = x.Skip((pageNumber - 1) * pageSize);
var z = y.Take(pageSize);

count = l.Count();

return z.ToList();
}
else if (whereClause != null)
{
var filtered = Groups.Where(whereClause);
count = filtered.Count();

return filtered.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
}
if (orderBy != null)
{
count = Groups.Count();
return Groups.OrderBy(orderbyClause).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
throw new Exception(string.Format("Could not retrieve filtered groups."), ex);
}

return null;
}

public Task CreateAsync(Group role)
{
if (string.IsNullOrEmpty(role.Name))
Expand Down
30 changes: 26 additions & 4 deletions Components/AAA/BExIS.Security.Services/Subjects/SubjectManager.cs
Expand Up @@ -30,11 +30,21 @@ public SubjectManager()
public IReadOnlyRepository<Subject> SubjectRepository { get; }
public IQueryable<Subject> Subjects => SubjectRepository.Query();

public List<Subject> GetSubjects(FilterExpression filter, OrderByExpression orderBy, int pageNumber, int pageSize)
/// <summary>
/// returns subset of subjects based on the parameters
/// and also count of filtered list
/// </summary>
/// <param name="filter"></param>
/// <param name="orderBy"></param>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <returns></returns>
public List<Subject> GetSubjects(FilterExpression filter, OrderByExpression orderBy, int pageNumber, int pageSize, out int count)
{
var orderbyClause = orderBy?.ToLINQ();
var whereClause = filter?.ToLINQ();

count = 0;
try
{
using (IUnitOfWork uow = this.GetUnitOfWork())
Expand All @@ -46,10 +56,22 @@ public List<Subject> GetSubjects(FilterExpression filter, OrderByExpression orde
var y = x.Skip((pageNumber - 1) * pageSize);
var z = y.Take(pageSize);

count = l.Count();

return z.ToList();
}
else if (whereClause != null) return Subjects.Where(whereClause).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
if (orderBy != null) return Subjects.OrderBy(orderbyClause).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
else if (whereClause != null)
{
var filtered = Subjects.Where(whereClause);
count = filtered.Count();

return filtered.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
}
if (orderBy != null)
{
count = Subjects.Count();
return Subjects.OrderBy(orderbyClause).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
Expand Down
56 changes: 56 additions & 0 deletions Components/AAA/BExIS.Security.Services/Subjects/UserManager.cs
@@ -1,9 +1,11 @@
using BExIS.Security.Entities.Authentication;
using BExIS.Security.Entities.Subjects;
using BExIS.Utils.NH.Querying;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -31,6 +33,60 @@ public UserManager()

private IReadOnlyRepository<User> UserRepository { get; }

/// <summary>
/// returns subset of users based on the parameters
/// and also count of filtered list
/// </summary>
/// <param name="filter"></param>
/// <param name="orderBy"></param>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <returns></returns>
public List<User> GetUsers(FilterExpression filter, OrderByExpression orderBy, int pageNumber, int pageSize, out int count)
{
var orderbyClause = orderBy?.ToLINQ();
var whereClause = filter?.ToLINQ();

count = 0;

try
{
using (IUnitOfWork uow = this.GetUnitOfWork())
{
if (whereClause != null && orderBy != null)
{
var l = Users.Where(whereClause);
var x = l.OrderBy(orderbyClause);
var y = x.Skip((pageNumber - 1) * pageSize);
var z = y.Take(pageSize);

count = l.Count();

return z.ToList();
}
else if (whereClause != null)
{
var filtered = Users.Where(whereClause);
count = filtered.Count();

return filtered.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
}
if (orderBy != null)
{
count = Users.Count();
return Users.OrderBy(orderbyClause).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
throw new Exception(string.Format("Could not retrieve filtered users."), ex);
}

return null;
}

#region IUserEmailStore

/// <summary>
Expand Down
Expand Up @@ -175,7 +175,7 @@ public ActionResult Subjects_Select(GridCommand command, long featureId)
FilterExpression filter = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

subjects = subjectManager.GetSubjects(filter, orderBy, command.Page, command.PageSize);
subjects = subjectManager.GetSubjects(filter, orderBy, command.Page, command.PageSize, out count);
}
else
{
Expand Down
22 changes: 18 additions & 4 deletions Console/BExIS.Web.Shell/Areas/SAM/Controllers/GroupsController.cs
@@ -1,6 +1,8 @@
using BExIS.Modules.Sam.UI.Models;
using BExIS.Security.Entities.Subjects;
using BExIS.Security.Services.Subjects;
using BExIS.UI.Helpers;
using BExIS.Utils.NH.Querying;
using Microsoft.AspNet.Identity;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -105,16 +107,28 @@ public async Task<bool> Delete(long groupId)
}
}

[GridAction]
public ActionResult Groups_Select()
[GridAction(EnableCustomBinding = true)]
public ActionResult Groups_Select(GridCommand command)
{
var groupManager = new GroupManager();

try
{
var groups = groupManager.Groups.Select(GroupGridRowModel.Convert).ToList();
var groups = new List<GroupGridRowModel>();
int count = groupManager.Groups.Count();
if (command != null)// filter subjects based on grid filter settings
{
FilterExpression filter = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

groups = groupManager.GetGroups(filter, orderBy, command.Page, command.PageSize, out count).Select(GroupGridRowModel.Convert).ToList();
}
else
{
groups = groupManager.Groups.Select(GroupGridRowModel.Convert).ToList();
}

return View(new GridModel<GroupGridRowModel> { Data = groups });
return View(new GridModel<GroupGridRowModel> { Data = groups, Total = count });
}
finally
{
Expand Down
22 changes: 18 additions & 4 deletions Console/BExIS.Web.Shell/Areas/SAM/Controllers/UsersController.cs
@@ -1,6 +1,8 @@
using BExIS.Modules.Sam.UI.Models;
using BExIS.Security.Entities.Subjects;
using BExIS.Security.Services.Subjects;
using BExIS.UI.Helpers;
using BExIS.Utils.NH.Querying;
using Microsoft.AspNet.Identity;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -187,16 +189,28 @@ public ActionResult Update(UpdateUserModel model)
}
}

[GridAction]
public ActionResult Users_Select()
[GridAction(EnableCustomBinding = true)]
public ActionResult Users_Select(GridCommand command)
{
var userManager = new UserManager();

try
{
var users = userManager.Users.Select(UserGridRowModel.Convert).ToList();
var users = new List<UserGridRowModel>();
int count = userManager.Users.Count();
if (command != null)// filter subjects based on grid filter settings
{
FilterExpression filter = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

users = userManager.GetUsers(filter, orderBy, command.Page, command.PageSize, out count).Select(UserGridRowModel.Convert).ToList();
}
else
{
users = userManager.Users.Select(UserGridRowModel.Convert).ToList();
}

return View(new GridModel<UserGridRowModel> { Data = users });
return View(new GridModel<UserGridRowModel> { Data = users, Total = count });
}
finally
{
Expand Down
8 changes: 4 additions & 4 deletions Console/BExIS.Web.Shell/Areas/SAM/Models/GroupModels.cs
Expand Up @@ -23,7 +23,7 @@ public class DeleteGroupModel
public class GroupFeaturePermissionGridRowModel
{
public string Description { get; set; }
public string GroupName { get; set; }
public string Name { get; set; }
public bool HasFeaturePermission { get; set; }
public long Id { get; set; }

Expand All @@ -32,7 +32,7 @@ public static GroupFeaturePermissionGridRowModel Convert(Group group)
return new GroupFeaturePermissionGridRowModel()
{
Description = group.Description,
GroupName = group.Name,
Name = group.Name,
Id = group.Id,
};
}
Expand All @@ -41,15 +41,15 @@ public static GroupFeaturePermissionGridRowModel Convert(Group group)
public class GroupGridRowModel
{
public string Description { get; set; }
public string GroupName { get; set; }
public string Name { get; set; }
public long Id { get; set; }

public static GroupGridRowModel Convert(Group group)
{
return new GroupGridRowModel()
{
Description = group.Description,
GroupName = group.Name,
Name = group.Name,
Id = group.Id
};
}
Expand Down
4 changes: 2 additions & 2 deletions Console/BExIS.Web.Shell/Areas/SAM/Models/UserModels.cs
Expand Up @@ -48,15 +48,15 @@ public class UserGridRowModel
{
public string Email { get; set; }
public long Id { get; set; }
public string UserName { get; set; }
public string Name { get; set; }

public static UserGridRowModel Convert(User user)
{
return new UserGridRowModel()
{
Email = user.Email,
Id = user.Id,
UserName = user.Name
Name = user.Name
};
}
}
Expand Down

0 comments on commit cd1f2e5

Please sign in to comment.