Exemple #1
0
        public IActionResult Edit(int?id, UserEditViewModel data)
        {
            var userId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid)?.Value);

            var user = _userLogic.GetBy(AuthController.GetAuthUserId(User), userId);

            if (User.IsInRole("Admin") && id != null)
            {
                user = _userLogic.GetBy(AuthController.GetAuthUserId(User), (int)id);
            }

            var userNew = new User
            {
                Id        = user.Id,
                FirstName = data.FirstName,
                LastName  = data.LastName,
                BirthDate = data.BirthDate,
                Length    = data.Length,
                Email     = data.Email,
                Blocked   = user.Blocked,
                Right     = user.Right
            };

            bool success;

            if (User.IsInRole("Admin"))
            {
                userNew.Right   = _rightLogic.GetBy(data.RightId);
                userNew.Blocked = data.Blocked;
                success         = _userLogic.Edit(userId, userNew);
            }
            else
            {
                success = _userLogic.ChangeUser(userNew);
            }

            return(success ? RedirectToAction("List", "User") : RedirectToAction("Edit", new { id = data.Id }));
        }
Exemple #2
0
        public IActionResult Register(RegisterViewModel data)
        {
            if (data.Password != data.PasswordH)
            {
                return(View("Register", data));
            }
            var user = new User
            {
                FirstName = data.FirstName,
                LastName  = data.LastName,
                Length    = data.Length,
                BirthDate = data.BirthDate,
                Blocked   = false,
                Email     = data.Email,
                Right     = _rightLogic.GetBy("Fitnesser")
            };
            var success = _userLogic.Register(user, data.Password);

            if (success)
            {
                return(RedirectToAction("Login", "Auth"));
            }
            return(View("Register", data));
        }