public async Task <RegisterCustomerResultModel> RegisterAsync(RegisterCustomerInputModel registerCustomerInputModel) { var user = new User { Email = registerCustomerInputModel.Email, UserName = registerCustomerInputModel.Email }; var identityResult = await this.userManager.CreateAsync(user, registerCustomerInputModel.Password); var registerCustomerResultOutputModel = new RegisterCustomerResultModel(); if (identityResult.Succeeded) { registerCustomerResultOutputModel.Succeeded = true; registerCustomerResultOutputModel.Email = registerCustomerInputModel.Email; registerCustomerResultOutputModel.Password = registerCustomerInputModel.Password; return(registerCustomerResultOutputModel); } var errors = identityResult.Errors.Select(e => e.Description); registerCustomerResultOutputModel.Succeeded = false; registerCustomerResultOutputModel.Errors = errors.ToList(); return(registerCustomerResultOutputModel); }
public async Task <ActionResult <string> > Register(RegisterCustomerInputModel registerCustomerInputModel) { var result = await this.identityService.RegisterAsync(registerCustomerInputModel); if (!result.Succeeded) { return(this.BadRequest(result.Errors)); } var loginCustomerInputModel = new LoginCustomerInputModel { Email = result.Email, Password = result.Password }; return(await this.Login(loginCustomerInputModel)); }
public async Task <IActionResult> RegisterCustomer(RegisterCustomerInputModel model) { var customerId = Guid.NewGuid(); var customer = new Customer { Id = customerId, Email = model.Email, DateOfBirth = model.DateOfBirth }; try { await _customerService.RegisterCustomer(customer); } catch (EmailAlreadyExists) { return(BadRequest("Email already registered")); } return(Ok(customerId)); }
public JsonResultModel Register(RegisterCustomerInputModel input) { try { if (cnn.Customers.Any(x => (x.Phone == input.phone || x.Email == input.email) && x.IsActive)) { return(rp.response(0, 0, "Email hoặc số điện thoại đã tồn tại", null)); } else { Customer cus = new Customer(); cus.Address = input.address; cus.CreatedDate = DateTime.Now; cus.Email = input.email; cus.DistrictID = input.district_id; cus.ProvinceID = input.province_id; cus.Phone = input.phone; cus.Password = Util.GenPass(input.password); cus.VillageID = input.village_id; cus.Name = input.name; cus.Token = Util.CreateMD5(DateTime.Now.ToString()); cus.IsActive = true; cus.Status = SystemParam.ACTIVE; cnn.Customers.Add(cus); cnn.SaveChanges(); LoginOutputModel data = new LoginOutputModel(); data.Id = cus.ID; data.Name = cus.Name; data.Token = cus.Token; HttpContext.Current.Session["Client"] = data; return(rp.response(1, 1, "Đăng ký thành công", data)); } } catch (Exception ex) { return(rp.serverError()); } }
public JsonResult Register(RegisterCustomerInputModel input) { var data = customerBusiness.Register(input); return(Json(data, JsonRequestBehavior.AllowGet)); }