You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.8 KiB
52 lines
1.8 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Security;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using IoT.Shared.Application.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("Admin/[controller]/[action]")]
|
|
[Area("Admin")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class UserController : CrudController<User, EditUserModel>
|
|
{
|
|
private readonly IEncryptionService _encrypitonService;
|
|
|
|
public UserController(IEncryptionService encrypitonService, IRepository<User> userRepo) : base(userRepo)
|
|
{
|
|
this._encrypitonService = encrypitonService;
|
|
}
|
|
|
|
public override IQueryable<User> Query(PagedListModel<EditUserModel> model, IQueryable<User> query)
|
|
{
|
|
return base.Query(model, query)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.UserName), o => o.UserName.Contains(model.Query.UserName))
|
|
.OrderBy(o => o.UserName);
|
|
}
|
|
|
|
public override void ToEntity(EditUserModel model, User entity)
|
|
{
|
|
if (!string.IsNullOrEmpty(model.Password))
|
|
{
|
|
entity.PasswordHash = this._encrypitonService.CreatePasswordHash(model.Password, entity.SecurityStamp);
|
|
entity.PasswordConfirmed = true;
|
|
}
|
|
if (!string.IsNullOrEmpty(model.Email))
|
|
{
|
|
entity.EmailConfirmed = true;
|
|
}
|
|
if (!string.IsNullOrEmpty(model.PhoneNumber))
|
|
{
|
|
entity.PhoneNumberConfirmed = true;
|
|
}
|
|
}
|
|
}
|
|
} |