Example #1
0
        public async Task <IActionResult> Register(TaiKhoanForCreateDto taiKhoan)
        {
            try
            {
                taiKhoan.TenDangNhap = taiKhoan.TenDangNhap.ToLower();
                var exists = await _repo.TaiKhoanTonTai(taiKhoan.TenDangNhap);

                if (exists == true)
                {
                    return(BadRequest());
                }

                var taiKhoanMoi = new TaiKhoan
                {
                    TenDangNhap = taiKhoan.TenDangNhap,
                    HoVaTen     = taiKhoan.HoVaTen,
                    GioiTinh    = taiKhoan.GioiTinh,
                    ThoiGianTao = DateTime.Now,
                    DiaChi      = taiKhoan.DiaChi,
                    NgaySinh    = taiKhoan.NgaySinh,
                    Email       = taiKhoan.Email,
                    SoDienThoai = taiKhoan.SoDienThoai,
                    PhanQuyen   = taiKhoan.PhanQuyen
                };

                var taiKhoanDuocTao = await _repo.TaoTaiKhoan(taiKhoanMoi, taiKhoan.MatKhau);

                return(StatusCode(200, new SuccessResponseDto
                {
                    Message = "Tạo tài khoản mới thành công!",
                    Result = new SuccessResponseResultWithSingleDataDto
                    {
                        Data = taiKhoanMoi
                    }
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new FailedResponseDto
                {
                    Message = "Tạo tài khoản mới thất bại!",
                    Result = new FailedResponseResultDto
                    {
                        Errors = e
                    }
                }));
            }
        }
        public async Task <IActionResult> Register([FromBody] TaiKhoanForCreateDto taiKhoan)
        {
            try
            {
                taiKhoan.TenDangNhap = taiKhoan.TenDangNhap.ToLower();

                if (await _repo.TaiKhoanTonTai(taiKhoan.TenDangNhap))
                {
                    return(BadRequest());
                }

                var taiKhoanMoi = new TaiKhoan
                {
                    TenDangNhap = taiKhoan.TenDangNhap,
                    ThoiGianTao = DateTime.Now,
                    PhanQuyen   = taiKhoan.PhanQuyen
                };

                var taiKhoanDuocTao = await _repo.TaoTaiKhoan(taiKhoanMoi, taiKhoan.MatKhau);

                return(StatusCode(200, new SuccessResponseDto
                {
                    Message = "Tạo tài khoản mới thành công!",
                    Result = new SuccessResponseResultWithSingleDataDto
                    {
                        Data = taiKhoanDuocTao
                    }
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new FailedResponseDto
                {
                    Message = "Tạo tài khoản mới thất bại!",
                    Result = new FailedResponseResultDto
                    {
                        Errors = e
                    }
                }));
            }
        }