コード例 #1
0
        public bool CreateKhachHangAccount(TaiKhoanKhachHangDTO registerUserDto)
        {
            try
            {
                //var item = IsExistedUserByMaNhanVien(registerUserDto.MaNhanVien.ToString());
                //if (item)
                //{
                //    return false;
                //}
                var khachhang = new KhachHang
                {
                    MaKhachHang  = Guid.NewGuid(),
                    HoLot        = registerUserDto.HoLot.ToLower(),
                    TenKhachhang = registerUserDto.TenKhachhang.ToLower(),
                    DiaChi       = registerUserDto.DiaChi.ToLower(),
                    TinhTP       = registerUserDto.TinhTP.ToLower(),
                    Sdt          = registerUserDto.Sdt.ToLower(),
                    Email        = registerUserDto.Email.ToLower(),
                    GhiChu       = registerUserDto.GhiChu.ToLower(),
                };
                _khachhangRepository.Insert(khachhang);
                _unitOfWork.Commit();

                var user = new User
                {
                    Id           = Guid.NewGuid(),
                    UserName     = registerUserDto.UserName.ToLower(),
                    PasswordHash = _userManager.PasswordHasher.HashPassword(registerUserDto.PasswordHash),
                    //PasswordHash = _userManager.PasswordHasher.HashPassword(AppSettings.DefaultPassword),
                    //   MaNhanVien = new Guid(registerUserDto.MaNhanVien.ToString().ToLower()),
                    MaKhachHang = new Guid(khachhang.MaKhachHang.ToString().ToLower()),
                    CreatedBy   = registerUserDto.TenKhachhang.ToLower(),
                    CreatedDate = DateTime.Now,
                    UpdatedBy   = registerUserDto.UpdatedBy,
                    UpdatedDate = registerUserDto.UpdatedDate,
                    Status      = registerUserDto.Status
                };
                _userRepository.Insert(user);
                _unitOfWork.Commit();
                if (registerUserDto.RoleIds != null)
                {
                    foreach (var roleId in registerUserDto.RoleIds)
                    {
                        var userRole = new UserRole {
                            UserId = user.Id, RoleId = new Guid(roleId)
                        };
                        _userRoleRepository.Insert(userRole);
                    }
                    _unitOfWork.Commit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #2
0
 public async Task <BaseResponse> CreateKhachHangAccount(TaiKhoanKhachHangDTO userDTO)
 {
     try
     {
         var result = _userService.CreateKhachHangAccount(userDTO);
         if (result)
         {
             return(await Task.FromResult(new BaseResponse(result)));
         }
         return(await Task.FromResult(new BaseResponse(Message.CreateNotSuccess, false)).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         return(await Task.FromResult(new BaseResponse(Message.CreateNotSuccess, false)).ConfigureAwait(false));
     }
 }