Beispiel #1
0
        public void AddUserDepartment(bool currentDep,
                                      int departmentId,
                                      bool isDeleted,
                                      bool isDepartmentManager,
                                      int userId,
                                      DateTime validFrom,
                                      DateTime validTo)
        {
            using (IUnitOfWork work = UnitOfWork.Begin())
            {
                UserDepartment ud = _userDepartmentRepository.FindByUserId(userId).Where(d => d.DepartmentId == departmentId).SingleOrDefault();

                if (ud == null)
                {
                    ud = DomainObjectFactory.CreateUserDepartment();
                    _userDepartmentRepository.Add(ud);
                }

                ud.CurrentDep          = currentDep;
                ud.DepartmentId        = departmentId;
                ud.IsDeleted           = isDeleted;
                ud.IsDepartmentManager = isDepartmentManager;
                ud.UserId    = userId;
                ud.ValidFrom = validFrom;
                ud.ValidTo   = validTo;

                work.Commit();

                var userDepLogEntity = new UserDepartmentEventEntity(_userDepartmentRepository.FindById(ud.Id));

                _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId,
                                      userDepLogEntity.GetCreateMessage());
            }
        }
Beispiel #2
0
        public HandleResponse <UserDepartmentKey> AddUserDepartment(UserDepartmentAddViewModel req)
        {
            HandleResponse <UserDepartmentKey> rm = new HandleResponse <UserDepartmentKey>();
            //bool b =await IsExist(a => a.UserId == req.UserId && a.DeparmentId == req.DepartmentId);
            //if (b)
            //{
            //    rm.Success = false;
            //    rm.Message = "该用户已分配在该部门,请勿重复操作";
            //    return rm;
            //}
            UserDepartmentModel ud = new UserDepartmentModel()
            {
                UserId = req.UserId, DeparmentId = req.DepartmentId
            };

            try
            {
                _UserDepartment.Add(ud);
                rm.Success = true;
                rm.Message = "添加数据成功";
                rm.Key     = new UserDepartmentKey {
                    UserId = ud.UserId, DepartmentId = ud.DeparmentId
                };
            }
            catch (Exception ex)
            {
                rm.Success = false;
                rm.Message = "添加数据失败" + ex.Message;
            }
            return(rm);
        }
        public async Task <IActionResult> Create([FromBody] SaveUserDepartmentResource userDepartmentResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userDepartment = mapper.Map <SaveUserDepartmentResource, UserDepartment>(userDepartmentResource);

            userDepartmentRepository.Add(userDepartment);
            if (await unitOfWork.CompleteAsync() == false)
            {
                throw new Exception(message: "Create new userDepartment failed on save");
            }

            userDepartment = await userDepartmentRepository.GetOne(userDepartment.Id);

            var result = mapper.Map <UserDepartment, ViewUserDepartmentResource>(userDepartment);

            return(Ok(result));
        }
        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);
            }
        }
 public bool Add(UserDepartment model)
 {
     return(userdepartmentRepository.Add(model));
 }