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 { private readonly IEncryptionService _encrypitonService; public UserController(IEncryptionService encrypitonService, IRepository userRepo) : base(userRepo) { this._encrypitonService = encrypitonService; } public override IQueryable Query(PagedListModel model, IQueryable 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; } } } }