コード例 #1
0
        public async Task <Guid> CreateUserAsync(CreateUserDto createUserDto)
        {
            using (var scope = _dbContextScopeFactory.Create())
            {
                // create user
                var createUser = _userRepository.GetUserByEmail(createUserDto.Email.ToLower());
                if (createUser == null)
                {
                    createUser = User.CreateUser(createUserDto.UserName, createUserDto.FullName,
                                                 createUserDto.Gender, createUserDto.Email, createUserDto.Mobile,
                                                 createUserDto.Address, createUserDto.HomePhone, createUserDto.Ext,
                                                 createUserDto.BirthDate, createUserDto.UserCode, null,
                                                 createUserDto.Language, createUserDto.UserIndex);
                    _userRepository.Add(createUser);
                }
                else
                {
                    createUser.Update(createUserDto.FullName,
                                      createUserDto.Gender, createUserDto.Email, createUserDto.Mobile,
                                      createUserDto.Address, createUserDto.HomePhone, createUserDto.Ext,
                                      createUserDto.BirthDate, createUserDto.UserCode, null,
                                      createUserDto.Language, createUserDto.UserIndex);
                }

                // create user depart
                foreach (var deptId in createUserDto.Departments)
                {
                    var createUserDept = _userDepartmentRepository
                                         .Get(w => w.UserID == createUser.Id && w.DeptID == deptId)
                                         .FirstOrDefault();
                    if (createUserDept == null)
                    {
                        createUserDept = UserDepartment.CreateUserDepartment(
                            createUser.Id, deptId, createUserDto.JobDescription,
                            createUserDto.OrderNumber, createUserDto.JobTitleId,
                            createUserDto.IsManager);
                        _userDepartmentRepository.Add(createUserDept);
                    }
                    else
                    {
                        createUserDept.Update(createUserDto.JobDescription,
                                              createUserDto.OrderNumber, createUserDto.JobTitleId,
                                              createUserDto.IsManager);
                    }
                }

                // create signature
                if (createUserDto.UserSignatures != null && createUserDto.UserSignatures.Count > 0)
                {
                    foreach (var signature in createUserDto.UserSignatures)
                    {
                        var createSignature = UserSignature.CreateUserSignature(
                            signature.SignServerId, createUser.Id,
                            signature.Title, signature.CertificateBin,
                            signature.SignImage, signature.SignImageType,
                            signature.StampImage, signature.StampImageType,
                            signature.Account, signature.Password);
                        _signatureRepository.Add(createSignature);
                    }
                }

                // create notification setting
                if (createUserDto.NotificationSettings != null && createUserDto.NotificationSettings.Count > 0)
                {
                    foreach (var notifySetting in createUserDto.NotificationSettings)
                    {
                        var createMotifySetting = NotificationSetting.Create(createUser.Id,
                                                                             notifySetting.NotificationTypeId, notifySetting.IsUrgent);
                        _notificationSettingRepository.Add(createMotifySetting);
                    }
                }

                await scope.SaveChangesAsync();

                return(createUser.Id);
            }
        }
コード例 #2
0
 public UserDepartment GetUserPrimaryDepartmentById(string userId)
 {
     return(userdepartmentRepository.Get(x => x.UserID == userId && x.IsActive && x.IsPrimary));
 }