Beispiel #1
0
        public IHttpActionResult AddUser(EmployeeModel employee)
        {
            var findUser = DBContext.Employee.FirstOrDefault(x => x.UserName == employee.UserName);

            if (findUser != null)
            {
            }
            var newEmployee = new Employee();

            newEmployee.Admin     = employee.IsAdmin;
            newEmployee.UserName  = employee.UserName;
            newEmployee.FirstName = employee.FirstName;
            newEmployee.LastName  = employee.LastName;
            newEmployee.Salt      = PasswordHashHelper.CreateSalt(employee.UserName);
            newEmployee.Pword     = PasswordHashHelper.PasswordHasher(new HashModel()
            {
                Password = employee.Password, Salt = newEmployee.Salt
            });

            try
            {
                DBContext.Employee.Add(newEmployee);
                DBContext.SaveChanges();
                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());

                throw;
            }
        }
Beispiel #2
0
        public async Task Create(EnrollStudent model, SqlTransaction sqlTransaction, int idEnrollment)
        {
            await using var command = new SqlCommand(InsertStudentQuery, sqlTransaction.Connection)
                        {
                            CommandType = CommandType.Text,
                            Transaction = sqlTransaction
                        };

            var salt = PasswordHashHelper.CreateSalt();

            command.Parameters.AddWithValue("@IndexNumber", model.IndexNumber);
            command.Parameters.AddWithValue("@FirstName", model.FirstName);
            command.Parameters.AddWithValue("@Password", PasswordHashHelper.Create(model.Password, salt));
            command.Parameters.AddWithValue("@LastName", model.LastName);
            command.Parameters.AddWithValue("@BirthDate", model.BirthDate);
            command.Parameters.AddWithValue("@Salt", salt);
            command.Parameters.AddWithValue("@IdEnrollment", idEnrollment);

            await command.ExecuteNonQueryAsync();
        }