///<sumary>Creación de un modelo</sumary>
        ///<param name="model">Instancia de Model</param>
        ///<returns>Id del modelo</returns>
        ///<exception cref="UniqueAttributeException">
        /// Es excepción es lanzada cuando el nombre del modelo ya existe
        ///</exception>
        public int AddModel(Model model)
        {
            int id = 0;

            try {
                PostgresBrandDAO brandDAO = new PostgresBrandDAO();
                brandDAO.GetBrandById(model.ModelBrandId);//Throw BrandNotFoundException
                PgConnection pgConnection = PgConnection.Instance;
                DataTable    dataTable    = pgConnection.ExecuteFunction(
                    "ModelUniqueness(@modelName)", model.ModelName);
                if (Convert.ToBoolean(dataTable.Rows[0][0]))
                {
                    throw new UniqueAttributeException("El modelo " + model.ModelName + " ya existe");
                }
                else
                {
                    dataTable = pgConnection.ExecuteFunction(
                        "AddModel(@brandId, @modelName, @capacity, @picture)",
                        model.ModelBrandId, model.ModelName, model.Capacity, model.Picture);
                    id = Convert.ToInt32(dataTable.Rows[0][0]);
                }
            } catch (DatabaseException ex) {
                throw new InternalServerErrorException("Error en el servidor : Conexion a base de datos", ex);
            } catch (InvalidStoredProcedureSignatureException ex) {
                throw new InternalServerErrorException("Error en el servidor", ex);
            }
            return(id);
        }
        ///<sumary>Obtener modelos por marca</sumary>
        ///<param name="brandId">Id de la marca</param>
        ///<returns>Lista de modelos por marca</returns>
        ///<exception cref="Throw BrandNotFoundException"> Si la marca no existe </exception>
        ///<exception cref=" WithoutExistenceOfModelsException">
        /// Si no existen modelos para dicha marca
        ///</exception>
        public List <Model> GetModelsByBrand(int brandId)
        {
            List <Model> models = new List <Model>();

            try{
                PostgresBrandDAO brandDAO = new PostgresBrandDAO();
                brandDAO.GetBrandById(brandId);//Throw BrandNotFoundException
                PgConnection pgConnection = PgConnection.Instance;
                DataTable    dataTable    = pgConnection.ExecuteFunction("GetModelsByBrand(@brandId)", brandId);
                if (dataTable.Rows.Count > 0)
                {
                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        Model model = new Model(
                            Convert.ToInt32(dataRow[0]),
                            Convert.ToInt32(dataRow[1]),
                            dataRow[2].ToString(),
                            Convert.ToInt32(dataRow[3]),
                            dataRow[4].ToString()
                            );
                        models.Add(model);
                    }
                }
                else
                {
                    throw new WithoutExistenceOfModelsException("No se encontraron Modelos para dicha Marca");
                }
            }catch (DatabaseException ex) {
                throw new InternalServerErrorException("Error en el servidor : Conexion a base de datos", ex);
            }catch (InvalidStoredProcedureSignatureException ex) {
                throw new InternalServerErrorException("Error en el servidor", ex);
            }
            return(models);
        }
        ///<sumary>Modificar un modelo</sumary>
        ///<param name="modelo">Instancia de Modelo</param>
        ///<returns>True si actualizo correctamente</returns>
        ///<exception cref="ModelNotFoundException"> Si el modelo en sí no existe </exception>
        ///<exception cref="BrandNotFoundException"> Si la marca no existe </exception>
        public bool UpdateModel(Model model)
        {
            bool updated = false;

            try{
                GetModelById(model.Id);                    //Throw ModelNotFoundException
                PostgresBrandDAO brandDAO = new PostgresBrandDAO();
                brandDAO.GetBrandById(model.ModelBrandId); //Throw BrandNotFoundException
                PgConnection pgConnection = PgConnection.Instance;
                DataTable    dataTable    = pgConnection.ExecuteFunction(
                    "UpdateModel(@vmid, @vmbrand, @vmname, @vmcapacity, @vmpicture)",
                    model.Id, model.ModelBrandId, model.ModelName, model.Capacity, model.Picture);
                if (Convert.ToBoolean(dataTable.Rows[0][0]))
                {
                    updated = true;
                }
            }catch (DatabaseException ex) {
                throw new InternalServerErrorException("Error en el servidor : Conexion a base de datos", ex);
            }catch (InvalidStoredProcedureSignatureException ex) {
                throw new InternalServerErrorException("Error en el servidor", ex);
            }
            return(updated);
        }