Exemple #1
0
        /// <summary>
        /// This method is used to create a new user in the data base
        /// </summary>
        /// <param name="sMsjError"></param>
        /// <param name="usersModel"></param>
        public void CreateNewUser(ref string sMessage, ref UsersModel usersModel)
        {
            #region Local variables

            string sNombreSP, sEncryptedEmailPass = usersModel.PasswordEmail, sEncryptedUserPass = "", sResultado = string.Empty;

            DbModel             dbModel             = new DbModel();
            DbViewModel         dbViewModel         = new DbViewModel();
            EncryptionViewModel encryptionViewModel = new EncryptionViewModel();

            #endregion
            if (!IsEmailGood(usersModel.UserEmail))
            {
                sMessage = "Por favor verifique que el correo electrónico se haya ingresado en el formato correcto";
            }
            else if (usersModel.PasswordEmail == string.Empty || usersModel.PasswordEmail is null)
            {
                sMessage = "Por favor ingrese la contraseña del correo electrónico";
            }
            else if (usersModel.UserIdType == "Nacional" && !IsIdNumberGood(usersModel.UserIdNumber))
            {
                sMessage = "Por favor verifique que el número de identificación se haya ingresado en el formato correcto";
            }
            else if (usersModel.UserAddress == string.Empty || usersModel.UserAddress is null ||
                     usersModel.UserProvince == string.Empty || usersModel.UserProvince is null ||
                     usersModel.UserCanton == string.Empty || usersModel.UserCanton is null ||
                     usersModel.UserDistrict == string.Empty || usersModel.UserDistrict is null)
            {
                sMessage = "Por favor ingrese una dirección de residencia";
            }
        public void AuthenticateUser(ref AuthenticationModel authenticationModel, ref string sMsjError)
        {
            #region Local variables

            string sNombreTabla, sNombreSP, sEncryptedPass = authenticationModel.UserPassword;

            DbModel             dbModel             = new DbModel();
            DbViewModel         dbViewModel         = new DbViewModel();
            EncryptionViewModel encryptionViewModel = new EncryptionViewModel();

            #endregion

            encryptionViewModel.EncryptString(ref sEncryptedPass);

            dbViewModel.GenerarDataTableParametros(ref dbModel);

            DataRow dr1 = dbModel.dtParametros.NewRow();
            dr1["Nombre"]   = "@email";
            dr1["TipoDato"] = "4";
            dr1["Valor"]    = authenticationModel.UserName;

            DataRow dr2 = dbModel.dtParametros.NewRow();
            dr2["Nombre"]   = "@s_contrasena";
            dr2["TipoDato"] = "4";
            dr2["Valor"]    = sEncryptedPass;

            dbModel.dtParametros.Rows.Add(dr1);
            dbModel.dtParametros.Rows.Add(dr2);

            sNombreTabla = (App.Current as App).TblAuthentication.ToString();
            sNombreSP    = (App.Current as App).SpAuthentication.ToString();

            dbViewModel.ExecuteFill(sNombreTabla, sNombreSP, ref dbModel);

            if (dbModel.sMsjError != string.Empty)
            {
                sMsjError = dbModel.sMsjError;
                authenticationModel.UserProfile = String.Empty;
            }
            else
            {
                sMsjError = string.Empty;

                if (dbModel.DS.Tables[sNombreTabla].Rows.Count > 0)
                {
                    authenticationModel.UserProfile = dbModel.DS.Tables[sNombreTabla].Rows[0][0].ToString();

                    if (authenticationModel.UserProfile == "Invalid Credentials")
                    {
                        authenticationModel.IsErrorMessageVisible = true;
                        authenticationModel.UserProfile           = "";
                    }
                }
                else
                {
                    authenticationModel.UserProfile           = string.Empty;
                    authenticationModel.IsErrorMessageVisible = true;
                }
            }
        }