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 ProyectCore.DAL.Models.ProyectCoreContext();
                    _context.Tenants.Add(new ProyectCore.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());
        }
示例#2
0
        public void CreateTasks(string title,
                                string details,
                                DateTime?expirationDate,
                                bool?isCompleted,
                                int?effort,
                                int?remainingWork,
                                int?stateId,
                                int?activityId,
                                int?priorityId,
                                int?projectId)
        {
            ProyectCore.DAL.Models.ProyectCoreContext _context = new ProyectCore.DAL.Models.ProyectCoreContext();

            _context.Tasks.Add(new ProyectCore.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();
        }
示例#3
0
        public void UpdateProjects(int id,
                                   string title,
                                   string details,
                                   DateTime?expectedCompletionDate)
        {
            ProyectCore.DAL.Models.ProyectCoreContext _context = new ProyectCore.DAL.Models.ProyectCoreContext();

            var projectEF = _context.Projects.Where(x => x.Id == id).FirstOrDefault();

            projectEF.Title   = title;
            projectEF.Details = details;
            projectEF.ExpectedCompletionDate = expectedCompletionDate;
            projectEF.UpdatedAt = DateTime.Now;

            _context.SaveChanges();
        }
示例#4
0
        public void DeleteProjects(int?id)

        {
            ProyectCore.DAL.Models.ProyectCoreContext _context = new ProyectCore.DAL.Models.ProyectCoreContext();

            if (_context.Artifacts.Any(x => x.ProjectId == id) ||
                _context.UserProjects.Any(x => x.ProjectId == id))
            {
                return;
            }

            var projectEF = _context.Projects.Where(x => x.Id == id).FirstOrDefault();

            _context.Projects.Remove(projectEF);

            _context.SaveChanges();
        }
示例#5
0
        public void CreateProjects(string title,
                                   string details,
                                   DateTime?expectedCompletionDate,
                                   int?tenantId)
        {
            ProyectCore.DAL.Models.ProyectCoreContext _context = new ProyectCore.DAL.Models.ProyectCoreContext();

            _context.Projects.Add(new ProyectCore.DAL.Models.Projects
            {
                Title   = title,
                Details = details,
                ExpectedCompletionDate = expectedCompletionDate,
                TenantId  = tenantId,
                CreatedAt = DateTime.Now
            });

            _context.SaveChanges();
        }