public async Task <Employee> Update(EmployeeEdit input) { if (!string.IsNullOrEmpty(input.FIDCard)) { Employee emp; if (!checkFIDCard(input, out emp)) { throw new UserFriendlyException($"【{input.FIDCard}】此ID卡已绑定到员工【{emp.FName}】,不能重复绑定,请换卡!"); } } var entity = input.MapTo <Employee>(); long userid; //修改员工对应用户信息 CreateOrUpdateUser(input, out userid); if (input.FDepartment > 0) //部门ID { var treelist = _Repository.GetAll().Where(p => p.IsDeleted == false).ToList(); //查找部门的那条数据 var eneiety = _Repository.GetAll().Include(p => p.Parent) .SingleOrDefault(p => p.Id == input.FDepartment && p.IsDeleted == false); if (eneiety != null) { var resultjt = GetCompany(eneiety, treelist); entity.FOrganizationUnitId = resultjt.Id; } } entity.FTenantId = this.AbpSession.TenantId.HasValue ? this.AbpSession.TenantId.Value : 0; entity.FERPUser = input.FERPUser; entity.FERPOfficeClerk = input.FERPOfficeClerk; entity.FUserId = (userid != 0 && input.FUserId == 0)?userid:input.FUserId; entity.IsDeleted = false; entity.FHiredate = (entity.FHiredate == null || entity.FHiredate == DateTime.MinValue)? DateTime.Now:entity.FHiredate; var count = await _ERepository.UpdateAsync(entity); return(count); }
public async Task <int> Create(EmployeeEdit input) { var entity = input.MapTo <Employee>(); long userid = 0; var companyId = 0; var isExist = await _ERepository.CountAsync(p => p.FMpno == input.FMpno && p.IsDeleted == false); if (isExist > 0) { throw new UserFriendlyException($"员工编号:{input.FMpno}已存在"); } //指定默认邮箱 //input.FEmailAddress = string.IsNullOrEmpty(input.FEmailAddress) ? $"test{count}@jit.com" : input.FEmailAddress; if (input.FSystemUser == 1) { var CreateUserDto = input.User; var UserDto = new CreateUserDto { UserName = string.IsNullOrEmpty(CreateUserDto.UserName)?input.FMpno: CreateUserDto.UserName, Name = input.FName, Surname = input.FName, EmailAddress = input.FEmailAddress, IsActive = true, RoleNames = null, //默认用户密码 Password = string.IsNullOrEmpty(CreateUserDto.Password)?User.DefaultPassword:CreateUserDto.Password }; #region 旧代码 //var Users =new User() // { // UserName = UserDto.UserName, // EmailAddress = input.FEmailAddress, // Name = input.FName, // Surname = input.FName, // Password = UserDto.Password, // IsActive = true, // IsDeleted = false, // NormalizedUserName = input.FName, // NormalizedEmailAddress = input.FEmailAddress, // IsTwoFactorEnabled = false, // IsPhoneNumberConfirmed = false, // IsEmailConfirmed = true, // AccessFailedCount = 0, // IsLockoutEnabled = false, // CreationTime = DateTime.Now, // }; // userid = _UserRepository.InsertAndGetId(Users); #endregion userid = UserAppService.Create(UserDto).Result.Id; //User u = UserDto.MapTo<User>(); //u.NormalizedUserName = u.UserName.ToUpper(); //u.Password = PasswordHasher.HashPassword(u, u.Password); //userid = await _UserRepository.InsertAndGetIdAsync(u); } if (input.FDepartment > 0) //部门ID { var treelist = _Repository.GetAll().Where(p => p.IsDeleted == false).ToList(); //查找部门的那条数据 var eneiety = _Repository.GetAll().Include(p => p.Parent) .SingleOrDefault(p => p.Id == input.FDepartment && p.IsDeleted == false); if (eneiety != null) { var resultjt = GetCompany(eneiety, treelist); companyId = resultjt.Id; } } entity.FOrganizationUnitId = companyId; entity.FTenantId = this.AbpSession.TenantId.HasValue ? this.AbpSession.TenantId.Value : 0; entity.FUserId = userid; entity.IsDeleted = false; // return 0; return(await _ERepository.InsertAndGetIdAsync(entity)); }