Ejemplo n.º 1
0
        public BusinessResult CreateUser(BOUser objUser)
        {
            BusinessResult result = new BusinessResult();

            if (!_userService.IsValid(objUser))
            {
                result.Success    = false;
                result.ErrorsList = _userService.Errors;
                return(result);
            }

            using (var conexion = Util.GetConnection())
            {
                conexion.Open();
                using (var objPE = new UserPE())
                {
                    try
                    {
                        objUser.Id = objPE.CreateUser(conexion, objUser);

                        result.Success = true;
                        result.Other   = objUser;
                    }
                    catch (Exception error)
                    {
                        result.ErrorsList.Add(error.Message);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public BusinessResult UpdateUser(BOUser objUser)
        {
            BusinessResult result = new BusinessResult();

            using (var conexion = Util.GetConnection())
            {
                conexion.Open();
                using (var objPE = new UserPE())
                {
                    try
                    {
                        objPE.UpdateUser(conexion, objUser);

                        result.Success = true;
                        result.Other   = objUser;
                    }
                    catch (Exception error)
                    {
                        result.ErrorsList.Add(error.Message);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public BusinessResult GetUserById(int id)
        {
            BusinessResult result = new BusinessResult();

            using (var conexion = Util.GetConnection())
            {
                conexion.Open();
                using (var objPE = new UserPE())
                {
                    try
                    {
                        BOUser objUser = objPE.GetUserById(conexion, id);

                        if (objUser == null)
                        {
                            result.ErrorsList.Add("Record not found.");
                        }
                        else
                        {
                            result.Success = true;
                            result.Other   = objUser;
                        }
                    }
                    catch (Exception error)
                    {
                        throw new Exception(error.Message);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        public int CreateUser(IDbConnection conexion, BOUser obj)
        {
            string sql = "INSERT INTO USER " +
                         "(" +
                         "NAME," +
                         "LASTNAME," +
                         "ADDRESS," +
                         "CREATEDATE" +
                         ")" +
                         " VALUES " +
                         "(" +
                         "'" + obj.Name + "'," +
                         "'" + obj.LastName + "'," +
                         "'" + obj.Address + "'," +
                         "'" + Util.FormatDateYYYYMMDD(DateTime.Now) + "'" +
                         ")";
            int resp = 0;

            switch (Util._GestorBaseDatos)
            {
            case Util.GestorBaseDatos.MySQL:
                DataBase.ExecuteNonQuery(sql, conexion);
                sql  = "SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'USER'";
                resp = Convert.ToInt32(DataBase.ExecuteScalar(sql, conexion)) - 1;
                break;

            default:
                break;
            }
            return(resp);
        }
Ejemplo n.º 5
0
        public void UpdateUser(IDbConnection conexion, BOUser obj)
        {
            string sql = "UPDATE USER SET" +
                         " NAME='" + Util.FormatString(obj.Name) + "'," +
                         " LASTNAME='" + Util.FormatString(obj.LastName) + "'," +
                         " ADDRESS='" + obj.Address + "'," +
                         " UPDATEDATE='" + Util.FormatDateYYYYMMDD(DateTime.Now) + "'" +
                         " WHERE ID='" + obj.Id + "'";

            DataBase.ExecuteNonQuery(sql, conexion);
        }
Ejemplo n.º 6
0
        private BOUser Load(IDataReader reader)
        {
            BOUser obj = new BOUser();

            obj.Id         = NotNullDataReader.GetInt32(reader, "ID");
            obj.Name       = NotNullDataReader.GetString(reader, "NAME");
            obj.LastName   = NotNullDataReader.GetString(reader, "LASTNAME");
            obj.Address    = NotNullDataReader.GetString(reader, "ADDRESS");
            obj.CreateDate = NotNullDataReader.GetDateTime(reader, "CREATEDATE");
            obj.UpdateDate = NotNullDataReader.GetDateTime(reader, "UPDATEDATE");

            return(obj);
        }
Ejemplo n.º 7
0
        public BOUser GetUserById(IDbConnection conexion, int idUser)
        {
            BOUser resp = null;
            string sql  = "SELECT * FROM USER" +
                          " WHERE ID=" + idUser;

            using (var dr = DataBase.ExecuteReader(sql, conexion))
            {
                while (dr.Read())
                {
                    resp = Load(dr);
                }
            }
            return(resp);
        }
Ejemplo n.º 8
0
 public BusinessResult UpdateUser(BOUser objUser)
 {
     return(this.getUserCO().UpdateUser(objUser));
 }