using Hncore.Infrastructure.Common;
using Hncore.Infrastructure.Data;
using Hncore.Infrastructure.DDD;
using Hncore.Infrastructure.EntitiesExtension;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Manage.Request;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace Hncore.Pass.Manage.Domain
{
///
/// 物业管理员表
///
public partial class Manager : EntityWithTime, ITenant
{
///
/// 所属物业ID
///
public int TenantId { get; set; }
///
/// 更新人ID
///
public int UpdatorId { get; set; }
///
/// 创建人ID
///
public int CreatorId { get; set; }
///
/// 管理员登录名[16
///
public string LoginCode { get; set; }
///
/// 登录密码[20]
///
public string Password { get; set; }
///
/// 管理员角色
///
public int RoleId { get; set; }
///
/// 状态
///
public int State { get; set; }
///
/// 头像地址[30
///
public string PhotoUrl { get; set; }
///
/// 微信openid[50]
///
public string WxOpenid { get; set; }
///
/// 微信昵称
///
public string WxNickName { get; set; }
///
/// 微信头像
///
public string WxImage { get; set; }
///
/// 注册来源
///
public int Source { get; set; }
///
/// 管理员手机号
///
public string Phone { get; set; }
///
/// 账号code
///
public string ManagerCode { get; set; }
///
/// 管理员姓名
///
public string RealName { get; set; }
///
/// 电子邮箱
///
public string Email { get; set; }
///
/// 是否主管理员权限
///
public bool IsRoot { get; set; }
public int SystemId { get; set; }
private static async Task EditCheckAsync(IQueryable queryable, EditManagerRequest request, int id = 0)
{
Expression> condition = t => t.LoginCode == request.LoginCode || t.Phone== request.Phone;
if (id > 0)
{
condition = condition.And(t => t.Id != id);
}
if (await queryable.AnyAsync(condition))
{
BusinessException.Throw("管理员手机号或登陆名重复");
}
}
///
/// 创建管理员
///
///
///
public static async Task Create(EditManagerRequest request,
IQueryable queryable)
{
await EditCheckAsync(queryable, request, 0);
var Manager = new Manager()
{
TenantId = request.TenantId,
CreatorId = request.OperaterId,
UpdatorId = request.OperaterId,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
LoginCode = request.LoginCode,
Password = SecurityHelper.HashPassword(request.Password),
PhotoUrl = request.photourl,
RealName = request.RealName,
State = 1,
Phone = request.Phone,
RoleId = -100, ///新规则的权限用-100标识
SystemId = 100,
};
return Manager;
}
///
/// 编辑管理员
///
///
///
public async Task Edit(EditManagerRequest request, IQueryable queryable)
{
await EditCheckAsync(queryable, request, request.Id);
TenantId = request.TenantId;
UpdatorId = request.OperaterId;
UpdateTime = DateTime.Now;
LoginCode = request.LoginCode;
if (!string.IsNullOrEmpty(request.Password))
{ Password = SecurityHelper.HashPassword(request.Password); }
PhotoUrl = request.photourl;
RealName = request.RealName;
Phone = request.Phone;
RoleId = request.roleid;
return this;
}
///
/// 删除管理员
///
///
///
public Manager Delete(int updatorId)
{
DeleteTag = 1;
UpdatorId = updatorId;
return this;
}
}
}