Beispiel #1
0
        public IActionResult Create([FromBody] UserDtos UserDtos)
        {
            // map dto to entity
            // var userdto = _mapper.Map<User>(UserDtos);

            var user = new User
            {
                FirstName = UserDtos.FirstName,
                LastName  = UserDtos.LastName,
                Email     = UserDtos.Email,
                Username  = UserDtos.Username,
                PhoneNo   = UserDtos.PhoneNo
            };

            try
            {
                // save
                var userCreated = _userService.Create(user, UserDtos.Password);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                // return error message if there was an exception
                return(View());
            }
        }
        public async Task <IActionResult> Post([FromBody] UserDtos registerUser)
        {
            ApplicationUser user = new ApplicationUser();

            user.FirstName = registerUser.FirstName;
            user.LastName  = registerUser.LastName;
            user.UserName  = registerUser.Username;
            user.Email     = registerUser.Email;


            var newUser = await _account.CreateUser(user, registerUser.Password);

            if (newUser)
            {
                return(Ok(new { message = "User Created" }));
            }

            return(BadRequest(new { message = "User not created" }));
        }
Beispiel #3
0
 public bool UpDate(UserDtos userDtos)
 {
     try
     {
         var user = _context.Users.Where(x => x.UserName == userDtos.UserName).SingleOrDefault();
         user.Password     = userDtos.Password;
         user.Name         = userDtos.Name;
         user.Address      = userDtos.Address;
         user.Phone        = userDtos.Phone;
         user.Email        = userDtos.Email;
         user.ModifiedDate = DateTime.Now;
         user.Status       = userDtos.Status;
         _context.SaveChanges();
         return(true);
     }catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #4
0
        public async Task <IActionResult> Register([FromBody] UserDtos registerUser)
        {
            ApplicationUser user = new ApplicationUser();

            user.FirstName = registerUser.FirstName;
            user.LastName  = registerUser.LastName;
            user.UserName  = registerUser.Username;
            user.Email     = registerUser.Email;


            var newUser = await _account.CreateUser(user, registerUser.Password);

            if (newUser)
            {
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Beispiel #5
0
        public async Task <IActionResult> Register(UserDtos userDtos)
        {
            try
            {
                var user = _mapper.Map <User>(userDtos);

                var result = await _userManager.CreateAsync(user, userDtos.Password);

                var userToReturn = _mapper.Map <UserDtos>(user);

                if (result.Succeeded)
                {
                    return(Created("GetUser", userToReturn));
                }

                return(BadRequest(result.Errors));
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco Dados Falhou {ex.Message}"));
            }
        }
Beispiel #6
0
 // Add List "THeDocGia" and "User"
 public void AddTheDocGiaAndUser(TheDocGiaDtos DocGia, UserDtos user)
 {
     _TheDocGiaBUS.AddTheDocGiaAndUser(DocGia, user);
 }
Beispiel #7
0
 private void bt_CNDL_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(tb_HoTenDG.Text))
     {
         MessageBox.Show("Không được để trống họ tên độc giả.", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); tb_HoTenDG.Focus();
     }
     else if (string.IsNullOrEmpty(tb_User.Text))
     {
         MessageBox.Show("Không được để trống Tài khoản.", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); tb_User.Focus();
     }
     else if (string.IsNullOrEmpty(tb_Passwork.Text))
     {
         MessageBox.Show("Không được để trống Passwork.", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); tb_Passwork.Focus();
     }
     else if (string.IsNullOrEmpty(tb_Diachi.Text))
     {
         MessageBox.Show("Không được để trống địa chỉ.", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); tb_Diachi.Focus();
     }
     else if (string.IsNullOrEmpty(tb_Email.Text))
     {
         MessageBox.Show("Không được để trống Email.", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); tb_Email.Focus();
     }
     else if (HelperGUI.Instance.checkIsMail(tb_Email) == false)
     {
         MessageBox.Show("Email không hợp lệ", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); tb_Email.Focus();
     }
     else if (string.IsNullOrEmpty(cb_LoaiDocGia.Text))
     {
         MessageBox.Show("Không được để trống loại độc giả.", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); cb_LoaiDocGia.Focus();
     }
     else
     {
         try
         {
             TheDocGiaService sv   = new TheDocGiaService();
             TheDocGiaDtos    tdg  = new TheDocGiaDtos();
             UserDtos         user = new UserDtos();
             HoTenDG          = HelperGUI.Instance.KiemTraHoTen(tb_HoTenDG.Text);
             UserName         = tb_User.Text;
             Pwd              = tb_Passwork.Text;
             DiaChiDG         = tb_Diachi.Text;
             EmailDG          = tb_Email.Text;
             NgayLapThe       = dt_NgayLT.Value;
             tdg.HoTenDG      = HoTenDG;
             tdg.IDLoaiDocGia = IDLoaiDG;
             tdg.NgayLapThe   = NgayLapThe;
             tdg.NgaySinhDG   = NgaySinhDG;
             tdg.DiaChiDG     = DiaChiDG;
             tdg.EmailDG      = EmailDG;
             user.Password    = Pwd;
             user.UserName    = UserName;
             sv.AddTheDocGiaAndUser(tdg, user);
             MessageBox.Show("Thêm thành công!");
             fillAllDataFromTableTheDocGia();
             HelperGUI.ResetAllControls(groupControl_TTDG);
         }
         catch
         {
         }
     }
 }