public IActionResult createUser(UserDto userDto)
        {
            //string surname, string lastname, int age, string email
            var user = _dataService.CreateUser(userDto.Username, userDto.Password, userDto.Surname, userDto.LastName, userDto.Age, userDto.Email);

            return(Created(" ", user));
        }
Exemple #2
0
        /*Note: The name contains 'createUser' because the input type=
         * submit annotation in the corresponding @page, has the asp page
         * handler "CreateUser", therefore this onPost is only called
         * when the client presses the 'Create User' button.
         * The strings parameters 'user_realName, user_...' is similarly
         * named the same as the inputs in the @page, enabling the binding
         */
        public async Task OnPostCreateUserAsync(string user_realName, string user_email, string user_password, double user_wage, DateTime user_employmentDate, string authLvl)
        {
            UserCreationError    = true;
            UserCreationErrorMsg = "";
            if (string.IsNullOrEmpty(user_realName) || string.IsNullOrEmpty(user_email) || string.IsNullOrEmpty(user_password) || double.IsNaN(user_wage))
            {
                //Show error messages in view
                UserCreationError    = false;
                UserCreationErrorMsg = "Name, email, password, wage and employment start can not be empty... Please try again";
                return;
            }


            if (user_employmentDate.Equals(DateTime.MinValue))
            {
                user_employmentDate = DateTime.Today;
            }


            if (string.IsNullOrEmpty(authLvl))
            {
                UserCreationError    = false;
                UserCreationErrorMsg = "You must choose a role for user to be created";
                return;
            }

            var authNiveau = ResolveAuthNiveau(authLvl);

            if (authNiveau.Equals(UserRoles.Unknown))
            {
                UserCreationError    = false;
                UserCreationErrorMsg = "The chosen role is not valid --> Valid roles are Admin, Employee, Manager";
                return;
            }

            var response = await _userDataService.CreateUser(new User
            {
                Email          = user_email,
                Name           = user_realName,
                Password       = user_password,
                BaseWage       = user_wage,
                EmploymentDate = user_employmentDate,
                AccessLevel    = authNiveau
            });

            if (!response.IsSuccesfull)
            {
                UserCreationError    = false;
                UserCreationErrorMsg = response.Message;
                return;
            }

            //Show success messages in view
            UserCreationSuccesfull = false;
            UserCreationSuccesMSg  =
                "Succesfully created user with email: " + user_email + " and password " + user_password + " and wage " + user_wage + " and employment start at " + user_employmentDate + response;
        }
        /// <summary>
        /// Register User
        /// </summary>
        /// <param name="userInformation"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public User RegisterUser(UserInformation userInformation, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            User user = new User();

            try
            {
                user.EmailAddress = userInformation.EmailAddress;
                user.FirstName    = userInformation.FirstName;
                user.LastName     = userInformation.LastName;
                user.Password     = userInformation.Password;
                user.AddressLine1 = string.Empty;
                user.AddressLine2 = string.Empty;
                user.City         = string.Empty;
                user.State        = string.Empty;
                user.ZipCode      = string.Empty;

                UserBusinessRules userBusinessRules = new UserBusinessRules(_userDataService, user, userInformation.PasswordConfirmation);
                ValidationResult  results           = userBusinessRules.Validate(user);

                bool validationSucceeded           = results.IsValid;
                IList <ValidationFailure> failures = results.Errors;

                if (validationSucceeded == false)
                {
                    transaction = ValidationErrors.PopulateValidationErrors(failures);
                    return(user);
                }

                _userDataService.CreateSession();
                _userDataService.BeginTransaction();
                _userDataService.CreateUser(user);
                _userDataService.CommitTransaction(true);

                transaction.ReturnStatus = true;
                transaction.ReturnMessage.Add("user successfully created.");
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _userDataService.CloseSession();
            }

            return(user);
        }
Exemple #4
0
        public async Task <string> AddNewUser(UserViewModel userModel)
        {
            try
            {
                var userId = await _userDataService.CreateUser(CreateUserDataModel(userModel));

                if (userId > 0)
                {
                    var credId = await _userCredentialDataService.CreateUserCredential(CreateUserCredentialDataModel(userModel, userId));

                    return(credId > 0 ? userModel.UserName : "******");
                }
            }
            catch (Exception)
            {
                throw new Exception($"Failed to create user {userModel.UserName}");
            }
            return("failed");
        }
Exemple #5
0
        ISession ISecurityService.Register(IUserRegister details)
        {
            if (!_userDataService.UserExists(details.Email))
            {
                // validation
                RegistrationValidate(details);

                var user = _userDataService.CreateUser(
                    details.Name, details.Email,
                    _hashService.Hash64(details.Password));

                user.Active = true;

                _userDataService.InsertUser(user);

                return(CreateInsertSession(user));
            }

            return(null);
        }
Exemple #6
0
 private async void AddUser()
 {
     Users.Add(await Go(() => _userDataService.CreateUser(), "Сохранение..."));
 }
Exemple #7
0
        public async Task <IActionResult> Create([FromBody] BaseApplicationUserViewModel user)
        {
            await _userDataService.CreateUser(user, ConstantKey.GeneralRoleName);

            return(Ok());
        }
 private void OnSave() => DataService.CreateUser(new User()
 {
     Username = this.Username, Password = this.Password, Firstname = this.Firstname, Lastname = this.Lastname, Email = this.Email
 });