コード例 #1
0
ファイル: UserAction.cs プロジェクト: chenchunwei/NPC
 public void UpdateUser(EditUserModel viewModel)
 {
     var userInContext = NpcContext.CurrentUser;
     if (viewModel.Id == null)
         throw new ArgumentException("id不能为空");
     var user = _userRepository.Find(viewModel.Id.Value);
     FillUser(user, viewModel);
     if (user.PhoneBookRecord == null)
     {
         var phoneBookService = new PhoneBookService();
         var phoneBook = phoneBookService.CreateOrGetDefaultPhoneBook(userInContext.Unit);
         var phoneBookRecord = new PhoneBookRecord();
         phoneBookRecord.Mobile = viewModel.FormData.Mobile;
         phoneBookRecord.Name = viewModel.FormData.Name;
         phoneBookRecord.User = user;
         phoneBookRecord.PhoneBook = phoneBook;
         phoneBookRecord.RecordDescription.CreateBy(userInContext);
         _phoneBookRecordRepository.Save(phoneBookRecord);
         user.PhoneBookRecord = phoneBookRecord;
     }
     else
     {
         user.PhoneBookRecord.Name = viewModel.FormData.Name;
         user.PhoneBookRecord.RecordDescription.UpdateBy(userInContext);
         _phoneBookRecordRepository.Save(user.PhoneBookRecord);
     }
     _userRepository.Save(user);
     if (!string.IsNullOrEmpty(viewModel.FormData.RoleNames))
         SaveOrUpdateRoleUser(user.Id, viewModel.FormData.RoleNames.Split(new[] { ',' }));
 }
コード例 #2
0
ファイル: UserAction.cs プロジェクト: chenchunwei/NPC
 public void NewUser(EditUserModel viewModel)
 {
     var userInContext = NpcContext.CurrentUser;
     if (_userRepository.IsRepeatAccount(viewModel.FormData.Mobile.Trim(), userInContext.Unit.Id))
     {
         throw new ArgumentException(string.Format("手机{0}已被使用,请选择其它的手机号码", viewModel.FormData.Mobile));
     }
     var user = new User();
     user.Account = viewModel.FormData.Mobile;
     FillUser(user, viewModel);
     user.Unit = userInContext.Unit;
     user.RecordDescription.CreateBy(userInContext);
     _userRepository.Save(user);
     var phoneBookService = new PhoneBookService();
     var phoneBook = phoneBookService.CreateOrGetDefaultPhoneBook(userInContext.Unit);
     var phoneBookRecord = new PhoneBookRecord();
     phoneBookRecord.Mobile = viewModel.FormData.Mobile;
     phoneBookRecord.Name = viewModel.FormData.Name;
     phoneBookRecord.User = user;
     phoneBookRecord.PhoneBook = phoneBook;
     phoneBookRecord.RecordDescription.CreateBy(userInContext);
     _phoneBookRecordRepository.Save(phoneBookRecord);
     user.PhoneBookRecord = phoneBookRecord;
     _userRepository.Save(user);
     if (!string.IsNullOrEmpty(viewModel.FormData.RoleNames))
         SaveOrUpdateRoleUser(user.Id, viewModel.FormData.RoleNames.Split(new[] { ',' }));
 }