Esempio n. 1
0
        public bool AddUser(string firstName, string lastName, string idCardNumber)
        {
            bool isSuccess;

            try
            {
                isSuccess = _userFunction.AddUser(firstName, lastName, idCardNumber);
            }
            catch (Exception ex)
            {
                //TODO: normal exception handling
                throw ex;
            }
            return(isSuccess);
        }
Esempio n. 2
0
        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            var model = Form.DataContext as UserViewModel;

            if (model != null)
            {
                ProgressUpload.IsIndeterminate = true;
                try
                {
                    UserFunctions.AddUser(this.TextPassword.Password, model.Login, model.Name, model.Surname,
                                          (byte)UserPrivlidgesExtensions.GetValueFromDescription(model.Permission));
                }
                catch (Exception)
                {
                    MessageBox.Show("An error occured, please check your inputs.");
                }
                finally
                {
                    ProgressUpload.IsIndeterminate = false;
                }
            }
        }
        /// <summary>
        /// This is a helper method to the User controllers Register Endpoint
        /// </summary>
        /// <param name="data">The Request Model coming in</param>
        /// <param name="Db">The Database context from the Dependency Injector</param>
        /// <returns>
        /// 0. Ok
        /// 1. Error
        /// </returns>
        internal static int RegisterUser(RegisterUserRequestModel data, DBContext Db)
        {
            try
            {
                IUserFunctions userFunctions = new UserFunctions(Db);

                //Hashing password before storing
                string PasswordHashed = Helpers.Crypto.GetHashStringsFromStrings(data.Password);

                ///Creating user entity from input data
                Users NewUser = new Users()
                {
                    Id             = new Random().Next(0, 9999999),
                    CreatedOn      = DateTime.Now,
                    Email          = data.Email,
                    Name           = data.Name,
                    Password       = PasswordHashed,
                    Phone          = data.Phone,
                    Username       = data.Username,
                    LastModifiedOn = DateTime.Now
                };

                //Adding user to database
                int Result = userFunctions.AddUser(NewUser);

                if (Result == 2)
                {
                    //Handling the Exception
                    ExceptionHandler.Handle(userFunctions.LastException);
                }
                return(Result);
            }
            catch (Exception e)
            {
                ExceptionHandler.Handle(e);
                throw;
            }
        }