public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); #region Tenant var _context = new ProjectCore.DAL.Models.ProjectCoreContext(); _context.Tenants.Add(new ProjectCore.DAL.Models.Tenants { Name = Input.Organization, CreatedAt = DateTime.Now, Plan = Input.Plan }); _context.SaveChanges(); var aspNetUser = _context.AspNetUsers.Where(x => x.UserName.Equals(Input.Email)).FirstOrDefault(); aspNetUser.TenantId = _context.Tenants.Max(x => x.Id); _context.SaveChanges(); await _userManager.AddToRoleAsync(user, "Admin"); #endregion //await _signInManager.SignInAsync(user, isPersistent: false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public void CreateTasks ( string title, string details, DateTime?expirationDate, bool?isCompleted, int?effort, int?remainingWork, int?stateId, int?activityId, int?priorityId, int?projectId ) { ProjectCore.DAL.Models.ProjectCoreContext _context = new ProjectCore.DAL.Models.ProjectCoreContext(); _context.Tasks.Add(new ProjectCore.DAL.Models.Tasks { Title = title, Details = details, ExpirationDate = expirationDate, IsCompleted = isCompleted, Effort = effort, RemainingWork = remainingWork, StateId = stateId, ActivityId = activityId, PriorityId = priorityId, ProjectId = projectId }); _context.SaveChanges(); }