public async Task <IActionResult> CreateProfessional(ProfessionalCreateUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } D.User user = new D.User() { firstName = model.firstName, lastName = model.lastName, Email = model.email, UserName = model.email, PhoneNumber = model.phoneNumber }; var result = await _userManager.CreateAsync(user, model.password); if (result.Succeeded) { var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.Action(nameof(ConfirmEmail), "Management", new { token, email = user.Email }, Request.Scheme); var message = new Message(new string[] { user.Email }, "Confirmation email link", confirmationLink, null); await _emailSender.SendEmailAsync(message); await _userManager.AddToRoleAsync(user, "professionals"); var professional = _mapper.Map <D.Professional>(model); professional.user = _mapper.Map <D.User>(user); professional.active = true; var prof = _repository.professional.Create(professional); ; if (prof == null) { await _userManager.DeleteAsync(user); return(BadRequest()); } return(Ok()); } else { return(new ObjectResult(result.Errors)); } }
public async Task <IActionResult> CreateCustomer(CustomerCreateUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else { D.User user = new D.User() { firstName = model.firstName, lastName = model.lastName, Email = model.email, UserName = model.email, PhoneNumber = model.phoneNumber, }; var result = await _userManager.CreateAsync(user, model.password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "customers"); var customer = _mapper.Map <D.Customer>(model); customer.user = user; customer.active = true; var cus = _repository.Customers.Create(customer); if (cus == null) { await _userManager.DeleteAsync(user); return(BadRequest()); } return(Ok()); } else { return(new ObjectResult(result.Errors)); } } }
public async Task <IActionResult> CreateProfessional(ProfessionalCreateUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } D.User user = new D.User() { firstName = model.firstName, lastName = model.lastName, Email = model.email, UserName = model.email, PhoneNumber = model.phoneNumber }; var result = await _userManager.CreateAsync(user, model.password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "professionals"); var professional = _mapper.Map <D.Professional>(model); professional.user = _mapper.Map <D.User>(user); var cus = _repository.professional.Create(professional); ; if (cus == null) { await _userManager.DeleteAsync(user); return(BadRequest()); } return(Ok()); } else { return(new ObjectResult(result.Errors)); } }