public void ChangeRoleName(string userId, string roleName)
        {
            var user = this.db
                       .Users.
                       SingleOrDefault(u => u.Id == userId);

            user.Role = roleName;

            db.SaveChanges();
        }
Beispiel #2
0
        public void Update(int id, string title, string description, string skills, List <int> categories, BudgetViewModel budget)
        {
            var project = this.db
                          .Projects
                          .Include(p => p.Categories)
                          .SingleOrDefault(p => p.Id == id);

            project.Title       = title;
            project.Description = description;
            project.Skills      = skills;
            project.BudgetId    = budget.Id;

            project.Categories = new List <ProjectsCategories>();

            db.SaveChanges();

            this.SetCategories(categories, project.Id);

            this.db.SaveChanges();
        }
Beispiel #3
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, lockoutOnFailure : false);

                var user = db.Users.SingleOrDefault(u => u.UserName == model.UserName);
                if (user != null)
                {
                    user.LastSeen = DateTime.Now;
                    db.SaveChanges();
                }

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");
                    return(RedirectToLocal(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToAction(nameof(Lockout)));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }