Пример #1
0
 public void Insert(Trinity.BE.IssueCard model)
 {
     BE.IssueCard issueCard = GetIssueCardBySmartCardId(model.SmartCardId);
     if (issueCard != null)
     {
         throw new Trinity.Common.ExceptionArgs(EnumMessage.SmartCardIsAlreadyInUse);
     }
     else
     {
         UpdateStatusByUserId(model.UserId, EnumIssuedCards.Inactive);
         _localUnitOfWork.GetRepository <DBContext.IssuedCard>().Add(model.Map <DBContext.IssuedCard>());
         _localUnitOfWork.Save();
     }
 }
Пример #2
0
        private async void CreateUserAsync()
        {
            //if (string.IsNullOrEmpty(_currentUser.SmartCardId) || _currentUser.Fingerprint == null)
            //{
            //    MessageBox.Show("You have to scan your smart card and fingerprint");
            //    return;
            //}
            //
            // Prepare user information
            //

            _currentUser.Name = txtName.Text;
            _currentUser.NRIC = txtNRIC.Text;
            _currentUser.Role = String.IsNullOrEmpty(cboRoles.Text) ? EnumUserRoles.Supervisee : cboRoles.Text;

            ApplicationUser user = new ApplicationUser();

            user.UserName = _currentUser.NRIC;
            user.Name     = _currentUser.Name;
            user.Email    = txtPrimaryEmail.Text;
            user.RightThumbFingerprint = _currentUser.RightThumbFingerprint;
            user.LeftThumbFingerprint  = _currentUser.LeftThumbFingerprint;
            user.IsFirstAttempt        = _currentUser.IsFirstAttempt;
            user.NRIC        = _currentUser.NRIC;
            user.PhoneNumber = txtPrimaryPhone.Text;
            user.SmartCardId = _currentUser.SmartCardId;
            user.Status      = EnumUserStatuses.Enrolled;

            UserManager <ApplicationUser> userManager = ApplicationIdentityManager.GetUserManager();

            Trinity.DAL.DAL_User dalUser = new Trinity.DAL.DAL_User();
            IdentityResult       result  = await userManager.CreateAsync(user, txtPassword.Text.Trim());

            if (result.Succeeded)
            {
                RoleManager <IdentityRole> roleManager = ApplicationIdentityManager.GetRoleManager();
                userManager.AddToRole(user.Id, _currentUser.Role);
                // Save to the Centralized DB also
                //dalUser.CreateUser(_currentUser, false);

                Trinity.DAL.DAL_UserProfile dalUserProfile = new Trinity.DAL.DAL_UserProfile();
                Trinity.BE.UserProfile      userProfile    = new Trinity.BE.UserProfile();
                userProfile.UserId        = _currentUser.UserId;
                userProfile.Primary_Phone = txtPrimaryPhone.Text;
                userProfile.Primary_Email = txtPrimaryEmail.Text;
                userProfile.Nationality   = txtNationality.Text;
                userProfile.DOB           = dpDOB.Value;



                var updateUProfileResult = CallCentralized.Post <bool>("User", "UpdateUserProfile", userProfile);

                //dalUserProfile.UpdateUserProfile(userProfile, _currentUser.UserId, true);

                //// Save to the Centralized DB also
                //dalUserProfile.UpdateUserProfile(userProfile, _currentUser.UserId, false);

                Trinity.BE.IssueCard issuedCard = new Trinity.BE.IssueCard()
                {
                    CreatedDate   = DateTime.Now,
                    Date_Of_Issue = DateTime.Now,
                    Expired_Date  = DateTime.Now.AddYears(2),
                    Name          = _currentUser.Name,
                    NRIC          = _currentUser.NRIC,
                    Serial_Number = "123434",
                    SmartCardId   = _currentUser.SmartCardId,
                    Status        = "Active",
                    UserId        = user.Id
                };
                DAL_IssueCard dalIssuedCard = new DAL_IssueCard();
                dalIssuedCard.Insert(issuedCard);

                btnSave.Enabled = false;
                MessageBox.Show("Create user successfully!", "Create user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Form frmMain = (Form)this.MainForm;
                frmMain.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Could not create user.", "Create user", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }