// POST api/<controller> public IHttpActionResult Register(CustomerRegisterDTO customerRegisterDTO) { if (!ModelState.IsValid) { return(BadRequest("請檢查欄位是否有遺漏")); } if (customerService.AccountIsduplicate(customerRegisterDTO.C_Account)) { return(BadRequest("帳號已被註冊!")); } if (customerService.PhoneNumIsDuplicate(customerRegisterDTO.C_PhoneNum)) { return(BadRequest("手機號碼已經使用過囉")); } var customer = Mapper.Map <CustomerRegisterDTO, Customer>(customerRegisterDTO); var result = customerService.Register(ref customer); if (result.Success == false) { return(BadRequest("Error 資料有誤")); } return(Created(new Uri(Request.RequestUri + "/" + customer.C_Id), customer)); }
public async Task <IActionResult> Register(CustomerRegisterDTO model) { Customer customer = new Customer(); customer.Email = model.Email; customer.FirstName = model.FirstName; customer.LastName = model.LastName; customer.PasswordHash = model.Password; customer.UserName = model.UserName; var result = await userManager.CreateAsync(customer, model.Password); if (result.Succeeded) { await userManager.AddToRoleAsync(customer, "Registred"); await signInManager.SignInAsync(customer, isPersistent : false); return(LocalRedirect("~/")); } foreach (var item in result.Errors) { ModelState.AddModelError(string.Empty, item.Description); } return(View(model)); }
public async Task <IActionResult> Register(CustomerRegisterDTO customerRegisterDTO) { customerRegisterDTO.Email.ToLower(); if (await _repo.CustomerExists(customerRegisterDTO.Email)) { return(BadRequest("UserExisting ")); } var customersToCreate = new Customer { Email = customerRegisterDTO.Email }; var createUser = await _repo.CustomerRegister(customersToCreate, customerRegisterDTO.Password); return(StatusCode(202)); }
public async Task CreateAsync(CustomerRegisterDTO customerDto) { var account = new Account(); var role = await _unitOfWork.RoleRepository.GetByIdAsync((long)RoleType.Customer); var socialAccounts = new List <SocialAccount>(); var socialAccount = new SocialAccount(); var customer = new Customer(); var person = new Person(); account.Role = role; account.DateCreated = DateTime.Now; account.Email = customerDto.Email; account.Avatar = customerDto.Image; account.DateCreated = DateTime.Now; socialAccount.Provider = customerDto.Provider; socialAccount.Uid = customerDto.Uid; socialAccount.Account = account; socialAccounts.Add(socialAccount); account.SocialAccounts = socialAccounts; account.Location = new Location() { Adress = customerDto.Location.Adress, City = customerDto.Location.City, IsDeleted = false, Latitude = customerDto.Location.Latitude, Longitude = customerDto.Location.Longitude, PostIndex = customerDto.Location.PostIndex }; person.Birthday = customerDto.Birthday; person.Phone = customerDto.Phone; person.Name = customerDto.FirstName; person.MiddleName = customerDto.MiddleName; person.Surname = customerDto.LastName; person.Account = account; customer.Person = person; customer.Books = new List <Book>(); customer.History = new List <History>(); _unitOfWork.CustomerRepository.Create(customer); await _unitOfWork.SaveAsync(); }
public async Task <HttpResponseMessage> ConfirmCustomer(CustomerRegisterDTO customer) { string token = null; try { await customerService.CreateAsync(customer); token = await authService.GenerateJwtTokenAsync(customer.Provider, customer.Uid); } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); response.Headers.Add("Access-Control-Expose-Headers", "Token"); response.Headers.Add("Token", token); return(response); }
public async Task <IActionResult> CreateCustomer([FromForm] CustomerRegisterDTO customerRegisterDTO) { var u = await _userManager.FindByEmailAsync(customerRegisterDTO.Email); if (u != null) { return(BadRequest(new { Email = "This Email already exist" })); } var user = new IdentityUser { UserName = customerRegisterDTO.Email, Email = customerRegisterDTO.Email, PhoneNumber = customerRegisterDTO.PhoneNumber }; var claims = new List <Claim> { new Claim(ClaimTypes.Name, customerRegisterDTO.Name), }; // Add no required claim if exist if (!string.IsNullOrEmpty(customerRegisterDTO.Address)) { claims.Add(new Claim(ClaimTypes.StreetAddress, customerRegisterDTO.Address)); } if (!string.IsNullOrEmpty(customerRegisterDTO.Gender)) { claims.Add(new Claim(ClaimTypes.Gender, customerRegisterDTO.Gender)); } await _userManager.CreateAsync(user, customerRegisterDTO.Password); await _userManager.AddToRoleAsync(user, Roles.Customer); await _userManager.AddClaimsAsync(user, claims); return(CreatedAtAction(nameof(GetCustomerById), new { id = user.Id }, null)); }
public IActionResult Register() { CustomerRegisterDTO dto = new CustomerRegisterDTO(); return(View(dto)); }