public async Task <IActionResult> EditUserInfo(EditUserInfoViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                if (user == null)
                {
                    return(View("Error"));
                }

                user.UserName  = model.UserName;
                user.Email     = model.Email;
                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;

                var result = await _userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    //update user information with new information
                    ProjectManagement.Models.User currentUser = ProjectManagement.Models.User.Find(user.UserName);
                    ProjectManagement.Models.User newUser     = new ProjectManagement.Models.User(user.FirstName + " " + user.LastName, user.UserName, user.Email);
                    currentUser.Update(newUser);

                    _logger.LogInformation(3, "User updated information.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult CreateProject(string Name, string Content, DateTime DueDate, string Tags, string UserName, string returnUrl = null)
        {
            Project newProject = new Project(Name, Content, DueDate, "In Progress");

            newProject.Save();
            ProjectManagement.Models.User currentUser = ProjectManagement.Models.User.Find(UserName);
            newProject.AddUser(currentUser);
            newProject.AssignOwner(currentUser);

            if (Tags != "emptyTag")
            {
                Tags = Tags.Trim();
                string [] tags = Tags.Split(' ');
                foreach (string tag in tags)
                {
                    Tag foundTag;
                    if (!Tag.Exist(tag))
                    {
                        foundTag = new Tag(tag);
                        foundTag.Save();
                    }
                    else
                    {
                        foundTag = Tag.Find(tag);
                    }
                    newProject.AddTag(foundTag);
                }
            }

            return(RedirectToAction(nameof(ProjectController.Index), "Project"));
        }
        public ActionResult JoinProject(int projectId, int userId, string returnUrl = null)
        {
            Project foundProject = Project.Find(projectId);

            ProjectManagement.Models.User foundUser = ProjectManagement.Models.User.Find(userId);
            foundProject.AddUser(foundUser);
            return(RedirectToAction(nameof(ExploreController.Index)));
        }
        public ActionResult LeaveProject(int projectId, int userId)
        {
            Project foundProject = Project.Find(projectId);

            ProjectManagement.Models.User foundUser = ProjectManagement.Models.User.Find(userId);
            foundUser.DeleteProject(foundProject);
            ProjectManagement.Models.User nextOwnerUser = foundProject.GetUsers()[0];
            foundProject.AssignOwner(nextOwnerUser);
            return(RedirectToAction(nameof(ProjectController.Index)));
        }
Exemple #5
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    // If there isn't user record in MySql DB
                    if (!ProjectManagement.Models.User.Exist(user.UserName))
                    {
                        ProjectManagement.Models.User newUser = new ProjectManagement.Models.User(user.FirstName + " " + user.LastName, user.UserName, user.Email);
                        newUser.Save();
                    }
                    // If there is a user record, update information.
                    else
                    {
                        ProjectManagement.Models.User foundUser = ProjectManagement.Models.User.Find(user.UserName);
                        foundUser.Update(new ProjectManagement.Models.User(user.FirstName + " " + user.LastName, user.UserName, user.Email));
                    }

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #6
0
        public async Task <IActionResult> CreateProject(string Name, string Content, DateTime DueDate, string Tags = "", string returnUrl = null)
        {
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            Project newProject = new Project(Name, Content, DueDate, "In Progress");

            newProject.Save();
            ProjectManagement.Models.User currentUser = ProjectManagement.Models.User.Find(user.UserName);
            newProject.AddUser(currentUser);
            newProject.AssignOwner(currentUser);

            if (Tags != "")
            {
                Tags = Tags.Trim();
                string [] tags = Tags.Split(' ');
                foreach (string tag in tags)
                {
                    Tag foundTag;
                    if (!Tag.Exist(tag))
                    {
                        foundTag = new Tag(tag);
                        foundTag.Save();
                    }
                    else
                    {
                        foundTag = Tag.Find(tag);
                    }
                    newProject.AddTag(foundTag);
                }
            }

            return(RedirectToAction(nameof(ProjectController.Index), "Project"));
        }